]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
objtool: Create disassembly context
authorAlexandre Chartre <alexandre.chartre@oracle.com>
Fri, 21 Nov 2025 09:53:12 +0000 (10:53 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 21 Nov 2025 14:30:06 +0000 (15:30 +0100)
Create a structure to store information for disassembling functions.
For now, it is just a wrapper around an objtool file.

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-3-alexandre.chartre@oracle.com
tools/objtool/check.c
tools/objtool/disas.c
tools/objtool/include/objtool/disas.h [new file with mode: 0644]
tools/objtool/include/objtool/objtool.h

index 1c7186f7af2ff87b479909d3a5696683250698d8..8b1a6a5185d3f4322594f8911885fe426beabe99 100644 (file)
@@ -12,6 +12,7 @@
 #include <objtool/builtin.h>
 #include <objtool/cfi.h>
 #include <objtool/arch.h>
+#include <objtool/disas.h>
 #include <objtool/check.h>
 #include <objtool/special.h>
 #include <objtool/warn.h>
@@ -4802,6 +4803,7 @@ static void free_insns(struct objtool_file *file)
 
 int check(struct objtool_file *file)
 {
+       struct disas_context *disas_ctx;
        int ret = 0, warnings = 0;
 
        arch_initial_func_cfi_state(&initial_func_cfi);
@@ -4943,7 +4945,9 @@ out:
        if (opts.verbose) {
                if (opts.werror && warnings)
                        WARN("%d warning(s) upgraded to errors", warnings);
-               disas_warned_funcs(file);
+               disas_ctx = disas_context_create(file);
+               disas_warned_funcs(disas_ctx);
+               disas_context_destroy(disas_ctx);
        }
 
        if (opts.backup && make_backup())
index 3a7cb1b8002ecc7f2ad0f6d30f71109db867bdc1..7a18e51d43e62ba01c0140beab936c8d547c8306 100644 (file)
@@ -4,10 +4,35 @@
  */
 
 #include <objtool/arch.h>
+#include <objtool/disas.h>
 #include <objtool/warn.h>
 
 #include <linux/string.h>
 
+struct disas_context {
+       struct objtool_file *file;
+};
+
+struct disas_context *disas_context_create(struct objtool_file *file)
+{
+       struct disas_context *dctx;
+
+       dctx = malloc(sizeof(*dctx));
+       if (!dctx) {
+               WARN("failed to allocate disassembly context");
+               return NULL;
+       }
+
+       dctx->file = file;
+
+       return dctx;
+}
+
+void disas_context_destroy(struct disas_context *dctx)
+{
+       free(dctx);
+}
+
 /* 'funcs' is a space-separated list of function names */
 static void disas_funcs(const char *funcs)
 {
@@ -58,12 +83,15 @@ static void disas_funcs(const char *funcs)
        }
 }
 
-void disas_warned_funcs(struct objtool_file *file)
+void disas_warned_funcs(struct disas_context *dctx)
 {
        struct symbol *sym;
        char *funcs = NULL, *tmp;
 
-       for_each_sym(file->elf, sym) {
+       if (!dctx)
+               return;
+
+       for_each_sym(dctx->file->elf, sym) {
                if (sym->warned) {
                        if (!funcs) {
                                funcs = malloc(strlen(sym->name) + 1);
diff --git a/tools/objtool/include/objtool/disas.h b/tools/objtool/include/objtool/disas.h
new file mode 100644 (file)
index 0000000..5c543b6
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+
+#ifndef _DISAS_H
+#define _DISAS_H
+
+struct disas_context;
+struct disas_context *disas_context_create(struct objtool_file *file);
+void disas_context_destroy(struct disas_context *dctx);
+void disas_warned_funcs(struct disas_context *dctx);
+
+#endif /* _DISAS_H */
index 35f926cf9c2542cf5846ac634fa14569eb309865..f7051bbe0bcb265471a30a967ed6e1d88970c702 100644 (file)
@@ -49,6 +49,4 @@ 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 */