]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Move disassembly functions to a separated file
authorAlexandre Chartre <alexandre.chartre@oracle.com>
Fri, 21 Nov 2025 09:53:11 +0000 (10:53 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 21 Nov 2025 14:30:06 +0000 (15:30 +0100)
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
tools/objtool/Build
tools/objtool/check.c
tools/objtool/disas.c [new file with mode: 0644]
tools/objtool/include/objtool/objtool.h

index 8cd71b9a5eef154051e73e8d46c3e18f846d7c10..17e50a1766d0e42e40769b9ea28ee5bf18849830 100644 (file)
@@ -7,6 +7,7 @@ objtool-y += special.o
 objtool-y += builtin-check.o
 objtool-y += elf.o
 objtool-y += objtool.o
+objtool-y += disas.o
 
 objtool-$(BUILD_ORC) += orc_gen.o orc_dump.o
 objtool-$(BUILD_KLP) += builtin-klp.o klp-diff.o klp-post-link.o
index 490cf78029b5929d1a69c762ae9df29c55b8c052..1c7186f7af2ff87b479909d3a5696683250698d8 100644 (file)
@@ -4731,87 +4731,6 @@ static int validate_reachable_instructions(struct objtool_file *file)
        return warnings;
 }
 
-/* 'funcs' is a space-separated list of function names */
-static void disas_funcs(const char *funcs)
-{
-       const char *objdump_str, *cross_compile;
-       int size, ret;
-       char *cmd;
-
-       cross_compile = getenv("CROSS_COMPILE");
-       if (!cross_compile)
-               cross_compile = "";
-
-       objdump_str = "%sobjdump -wdr %s | gawk -M -v _funcs='%s' '"
-                       "BEGIN { split(_funcs, funcs); }"
-                       "/^$/ { func_match = 0; }"
-                       "/<.*>:/ { "
-                               "f = gensub(/.*<(.*)>:/, \"\\\\1\", 1);"
-                               "for (i in funcs) {"
-                                       "if (funcs[i] == f) {"
-                                               "func_match = 1;"
-                                               "base = strtonum(\"0x\" $1);"
-                                               "break;"
-                                       "}"
-                               "}"
-                       "}"
-                       "{"
-                               "if (func_match) {"
-                                       "addr = strtonum(\"0x\" $1);"
-                                       "printf(\"%%04x \", addr - base);"
-                                       "print;"
-                               "}"
-                       "}' 1>&2";
-
-       /* fake snprintf() to calculate the size */
-       size = snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + 1;
-       if (size <= 0) {
-               WARN("objdump string size calculation failed");
-               return;
-       }
-
-       cmd = malloc(size);
-
-       /* real snprintf() */
-       snprintf(cmd, size, objdump_str, cross_compile, objname, funcs);
-       ret = system(cmd);
-       if (ret) {
-               WARN("disassembly failed: %d", ret);
-               return;
-       }
-}
-
-static void disas_warned_funcs(struct objtool_file *file)
-{
-       struct symbol *sym;
-       char *funcs = NULL, *tmp;
-
-       for_each_sym(file->elf, sym) {
-               if (sym->warned) {
-                       if (!funcs) {
-                               funcs = malloc(strlen(sym->name) + 1);
-                               if (!funcs) {
-                                       ERROR_GLIBC("malloc");
-                                       return;
-                               }
-                               strcpy(funcs, sym->name);
-                       } else {
-                               tmp = malloc(strlen(funcs) + strlen(sym->name) + 2);
-                               if (!tmp) {
-                                       ERROR_GLIBC("malloc");
-                                       return;
-                               }
-                               sprintf(tmp, "%s %s", funcs, sym->name);
-                               free(funcs);
-                               funcs = tmp;
-                       }
-               }
-       }
-
-       if (funcs)
-               disas_funcs(funcs);
-}
-
 __weak bool arch_absolute_reloc(struct elf *elf, struct reloc *reloc)
 {
        unsigned int type = reloc_type(reloc);
diff --git a/tools/objtool/disas.c b/tools/objtool/disas.c
new file mode 100644 (file)
index 0000000..3a7cb1b
--- /dev/null
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2015-2017 Josh Poimboeuf <jpoimboe@redhat.com>
+ */
+
+#include <objtool/arch.h>
+#include <objtool/warn.h>
+
+#include <linux/string.h>
+
+/* 'funcs' is a space-separated list of function names */
+static void disas_funcs(const char *funcs)
+{
+       const char *objdump_str, *cross_compile;
+       int size, ret;
+       char *cmd;
+
+       cross_compile = getenv("CROSS_COMPILE");
+       if (!cross_compile)
+               cross_compile = "";
+
+       objdump_str = "%sobjdump -wdr %s | gawk -M -v _funcs='%s' '"
+                       "BEGIN { split(_funcs, funcs); }"
+                       "/^$/ { func_match = 0; }"
+                       "/<.*>:/ { "
+                               "f = gensub(/.*<(.*)>:/, \"\\\\1\", 1);"
+                               "for (i in funcs) {"
+                                       "if (funcs[i] == f) {"
+                                               "func_match = 1;"
+                                               "base = strtonum(\"0x\" $1);"
+                                               "break;"
+                                       "}"
+                               "}"
+                       "}"
+                       "{"
+                               "if (func_match) {"
+                                       "addr = strtonum(\"0x\" $1);"
+                                       "printf(\"%%04x \", addr - base);"
+                                       "print;"
+                               "}"
+                       "}' 1>&2";
+
+       /* fake snprintf() to calculate the size */
+       size = snprintf(NULL, 0, objdump_str, cross_compile, objname, funcs) + 1;
+       if (size <= 0) {
+               WARN("objdump string size calculation failed");
+               return;
+       }
+
+       cmd = malloc(size);
+
+       /* real snprintf() */
+       snprintf(cmd, size, objdump_str, cross_compile, objname, funcs);
+       ret = system(cmd);
+       if (ret) {
+               WARN("disassembly failed: %d", ret);
+               return;
+       }
+}
+
+void disas_warned_funcs(struct objtool_file *file)
+{
+       struct symbol *sym;
+       char *funcs = NULL, *tmp;
+
+       for_each_sym(file->elf, sym) {
+               if (sym->warned) {
+                       if (!funcs) {
+                               funcs = malloc(strlen(sym->name) + 1);
+                               if (!funcs) {
+                                       ERROR_GLIBC("malloc");
+                                       return;
+                               }
+                               strcpy(funcs, sym->name);
+                       } else {
+                               tmp = malloc(strlen(funcs) + strlen(sym->name) + 2);
+                               if (!tmp) {
+                                       ERROR_GLIBC("malloc");
+                                       return;
+                               }
+                               sprintf(tmp, "%s %s", funcs, sym->name);
+                               free(funcs);
+                               funcs = tmp;
+                       }
+               }
+       }
+
+       if (funcs)
+               disas_funcs(funcs);
+}
index f7051bbe0bcb265471a30a967ed6e1d88970c702..35f926cf9c2542cf5846ac634fa14569eb309865 100644 (file)
@@ -49,4 +49,6 @@ int check(struct objtool_file *file);
 int orc_dump(const char *objname);
 int orc_create(struct objtool_file *file);
 
+void disas_warned_funcs(struct objtool_file *file);
+
 #endif /* _OBJTOOL_H */