Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

objtool: Move disassembly functions to a separated file

objtool disassembles functions which have warnings. Move the code
to do that to a dedicated file. The code is just moved, it is not
changed.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://patch.msgid.link/20251121095340.464045-2-alexandre.chartre@oracle.com

authored by

Alexandre Chartre and committed by
Peter Zijlstra
55d2a473 11991999

+93 -81
+1
tools/objtool/Build
··· 7 7 objtool-y += builtin-check.o 8 8 objtool-y += elf.o 9 9 objtool-y += objtool.o 10 + objtool-y += disas.o 10 11 11 12 objtool-$(BUILD_ORC) += orc_gen.o orc_dump.o 12 13 objtool-$(BUILD_KLP) += builtin-klp.o klp-diff.o klp-post-link.o
-81
tools/objtool/check.c
··· 4731 4731 return warnings; 4732 4732 } 4733 4733 4734 - /* 'funcs' is a space-separated list of function names */ 4735 - static void disas_funcs(const char *funcs) 4736 - { 4737 - const char *objdump_str, *cross_compile; 4738 - int size, ret; 4739 - char *cmd; 4740 - 4741 - cross_compile = getenv("CROSS_COMPILE"); 4742 - if (!cross_compile) 4743 - cross_compile = ""; 4744 - 4745 - objdump_str = "%sobjdump -wdr %s | gawk -M -v _funcs='%s' '" 4746 - "BEGIN { split(_funcs, funcs); }" 4747 - "/^$/ { func_match = 0; }" 4748 - "/<.*>:/ { " 4749 - "f = gensub(/.*<(.*)>:/, \"\\\\1\", 1);" 4750 - "for (i in funcs) {" 4751 - "if (funcs[i] == f) {" 4752 - "func_match = 1;" 4753 - "base = strtonum(\"0x\" $1);" 4754 - "break;" 4755 - "}" 4756 - "}" 4757 - "}" 4758 - "{" 4759 - "if (func_match) {" 4760 - "addr = strtonum(\"0x\" $1);" 4761 - "printf(\"%%04x \", addr - base);" 4762 - "print;" 4763 - "}" 4764 - "}' 1>&2"; 4765 - 4766 - /* fake snprintf() to calculate the size */ 4767 - size = snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + 1; 4768 - if (size <= 0) { 4769 - WARN("objdump string size calculation failed"); 4770 - return; 4771 - } 4772 - 4773 - cmd = malloc(size); 4774 - 4775 - /* real snprintf() */ 4776 - snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); 4777 - ret = system(cmd); 4778 - if (ret) { 4779 - WARN("disassembly failed: %d", ret); 4780 - return; 4781 - } 4782 - } 4783 - 4784 - static void disas_warned_funcs(struct objtool_file *file) 4785 - { 4786 - struct symbol *sym; 4787 - char *funcs = NULL, *tmp; 4788 - 4789 - for_each_sym(file->elf, sym) { 4790 - if (sym->warned) { 4791 - if (!funcs) { 4792 - funcs = malloc(strlen(sym->name) + 1); 4793 - if (!funcs) { 4794 - ERROR_GLIBC("malloc"); 4795 - return; 4796 - } 4797 - strcpy(funcs, sym->name); 4798 - } else { 4799 - tmp = malloc(strlen(funcs) + strlen(sym->name) + 2); 4800 - if (!tmp) { 4801 - ERROR_GLIBC("malloc"); 4802 - return; 4803 - } 4804 - sprintf(tmp, "%s %s", funcs, sym->name); 4805 - free(funcs); 4806 - funcs = tmp; 4807 - } 4808 - } 4809 - } 4810 - 4811 - if (funcs) 4812 - disas_funcs(funcs); 4813 - } 4814 - 4815 4734 __weak bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc) 4816 4735 { 4817 4736 unsigned int type = reloc_type(reloc);
+90
tools/objtool/disas.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com> 4 + */ 5 + 6 + #include <objtool/arch.h> 7 + #include <objtool/warn.h> 8 + 9 + #include <linux/string.h> 10 + 11 + /* 'funcs' is a space-separated list of function names */ 12 + static void disas_funcs(const char *funcs) 13 + { 14 + const char *objdump_str, *cross_compile; 15 + int size, ret; 16 + char *cmd; 17 + 18 + cross_compile = getenv("CROSS_COMPILE"); 19 + if (!cross_compile) 20 + cross_compile = ""; 21 + 22 + objdump_str = "%sobjdump -wdr %s | gawk -M -v _funcs='%s' '" 23 + "BEGIN { split(_funcs, funcs); }" 24 + "/^$/ { func_match = 0; }" 25 + "/<.*>:/ { " 26 + "f = gensub(/.*<(.*)>:/, \"\\\\1\", 1);" 27 + "for (i in funcs) {" 28 + "if (funcs[i] == f) {" 29 + "func_match = 1;" 30 + "base = strtonum(\"0x\" $1);" 31 + "break;" 32 + "}" 33 + "}" 34 + "}" 35 + "{" 36 + "if (func_match) {" 37 + "addr = strtonum(\"0x\" $1);" 38 + "printf(\"%%04x \", addr - base);" 39 + "print;" 40 + "}" 41 + "}' 1>&2"; 42 + 43 + /* fake snprintf() to calculate the size */ 44 + size = snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + 1; 45 + if (size <= 0) { 46 + WARN("objdump string size calculation failed"); 47 + return; 48 + } 49 + 50 + cmd = malloc(size); 51 + 52 + /* real snprintf() */ 53 + snprintf(cmd, size, objdump_str, cross_compile, objname, funcs); 54 + ret = system(cmd); 55 + if (ret) { 56 + WARN("disassembly failed: %d", ret); 57 + return; 58 + } 59 + } 60 + 61 + void disas_warned_funcs(struct objtool_file *file) 62 + { 63 + struct symbol *sym; 64 + char *funcs = NULL, *tmp; 65 + 66 + for_each_sym(file->elf, sym) { 67 + if (sym->warned) { 68 + if (!funcs) { 69 + funcs = malloc(strlen(sym->name) + 1); 70 + if (!funcs) { 71 + ERROR_GLIBC("malloc"); 72 + return; 73 + } 74 + strcpy(funcs, sym->name); 75 + } else { 76 + tmp = malloc(strlen(funcs) + strlen(sym->name) + 2); 77 + if (!tmp) { 78 + ERROR_GLIBC("malloc"); 79 + return; 80 + } 81 + sprintf(tmp, "%s %s", funcs, sym->name); 82 + free(funcs); 83 + funcs = tmp; 84 + } 85 + } 86 + } 87 + 88 + if (funcs) 89 + disas_funcs(funcs); 90 + }
+2
tools/objtool/include/objtool/objtool.h
··· 49 49 int orc_dump(const char *objname); 50 50 int orc_create(struct objtool_file *file); 51 51 52 + void disas_warned_funcs(struct objtool_file *file); 53 + 52 54 #endif /* _OBJTOOL_H */