From: Josh Poimboeuf <jpoimboe@kernel.org>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH 1/5] objtool: Add '--verbose' option for disassembling affected functions
Date: Mon, 27 Mar 2023 09:00:44 -0700 [thread overview]
Message-ID: <217a005fe22f9d33f99fed499d6508af9f5cabd0.1679932620.git.jpoimboe@kernel.org> (raw)
In-Reply-To: <cover.1679932620.git.jpoimboe@kernel.org>
When a warning is associated with a function, add an option to
disassemble that function.
This makes it easier for reporters to submit the information needed to
diagnose objtool warnings.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/Documentation/objtool.txt | 5 ++++
tools/objtool/builtin-check.c | 1 +
tools/objtool/include/objtool/builtin.h | 1 +
tools/objtool/include/objtool/warn.h | 38 +++++++++++++++++++++++++
4 files changed, 45 insertions(+)
diff --git a/tools/objtool/Documentation/objtool.txt b/tools/objtool/Documentation/objtool.txt
index 8e53fc6735ef..7c1a46af322f 100644
--- a/tools/objtool/Documentation/objtool.txt
+++ b/tools/objtool/Documentation/objtool.txt
@@ -244,6 +244,11 @@ To achieve the validation, objtool enforces the following rules:
Objtool warnings
----------------
+NOTE: When requesting help with an objtool warning, please re-run the
+kernel build with `OBJTOOL_ARGS="--verbose" make <whatever>` and send
+the full warning output (including any function disassembly below the
+warning) to the objtool maintainers.
+
For asm files, if you're getting an error which doesn't make sense,
first make sure that the affected code follows the above rules.
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index 7c175198d09f..b8de42f6778e 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -93,6 +93,7 @@ static const struct option check_options[] = {
OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"),
OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
+ OPT_BOOLEAN('v', "verbose", &opts.verbose, "verbose warnings"),
OPT_END(),
};
diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/include/objtool/builtin.h
index 2a108e648b7a..fcca6662c8b4 100644
--- a/tools/objtool/include/objtool/builtin.h
+++ b/tools/objtool/include/objtool/builtin.h
@@ -37,6 +37,7 @@ struct opts {
bool no_unreachable;
bool sec_address;
bool stats;
+ bool verbose;
};
extern struct opts opts;
diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h
index a3e79ae75f2e..b85aa440ee1f 100644
--- a/tools/objtool/include/objtool/warn.h
+++ b/tools/objtool/include/objtool/warn.h
@@ -11,6 +11,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <unistd.h>
#include <objtool/builtin.h>
#include <objtool/elf.h>
@@ -41,6 +42,41 @@ static inline char *offstr(struct section *sec, unsigned long offset)
return str;
}
+static inline void objdump_func(struct section *sec, unsigned long offset)
+{
+ struct symbol *sym = find_func_containing(sec, offset);
+ const char *script_relative = "scripts/objdump-func";
+ bool is_text = (sec->sh.sh_flags & SHF_EXECINSTR);
+ char *cmd, *srctree, *script;
+
+ if (is_text)
+ sym = find_func_containing(sec, offset);
+ if (!sym)
+ sym = find_symbol_containing(sec, offset);
+ if (!sym)
+ return;
+
+ srctree = getenv("abs_srctree");
+ if (!srctree)
+ return;
+
+ script = malloc(strlen(srctree) + strlen(script_relative) + 2);
+ if (!script)
+ return;
+
+ sprintf(script, "%s/%s", srctree, script_relative);
+
+ if (access(script, X_OK))
+ return;
+
+ cmd = malloc(strlen(script) + strlen(objname) + strlen(sym->name) + 10);
+ if (!cmd)
+ return;
+
+ sprintf(cmd, "%s %s %s 1>&2", script, objname, sym->name);
+ system(cmd);
+}
+
#define WARN(format, ...) \
fprintf(stderr, \
"%s: warning: objtool: " format "\n", \
@@ -51,6 +87,8 @@ static inline char *offstr(struct section *sec, unsigned long offset)
char *_str = offstr(sec, offset); \
WARN("%s: " format, _str, ##__VA_ARGS__); \
free(_str); \
+ if (opts.verbose) \
+ objdump_func(sec, offset); \
})
#define BT_FUNC(format, insn, ...) \
--
2.39.2
next prev parent reply other threads:[~2023-03-27 16:01 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 16:00 [PATCH 0/5] objtool: warning improvements Josh Poimboeuf
2023-03-27 16:00 ` Josh Poimboeuf [this message]
2023-03-28 8:47 ` [PATCH 1/5] objtool: Add '--verbose' option for disassembling affected functions Miroslav Benes
2023-03-27 16:00 ` [PATCH 2/5] objtool: Combine '--backtrace' with '--verbose' Josh Poimboeuf
2023-03-28 8:07 ` Peter Zijlstra
2023-03-28 20:19 ` Josh Poimboeuf
2023-03-29 7:25 ` Peter Zijlstra
2023-03-27 16:00 ` [PATCH 3/5] objtool: Remove superfluous dead_end_function() check Josh Poimboeuf
2023-03-27 16:00 ` [PATCH 4/5] objtool: Add per-function rate limiting for unreachable warnings Josh Poimboeuf
2023-03-28 8:11 ` Peter Zijlstra
2023-03-28 20:22 ` Josh Poimboeuf
2023-03-29 7:26 ` Peter Zijlstra
2023-03-28 9:07 ` Miroslav Benes
2023-03-27 16:00 ` [PATCH 5/5] objtool: Add "missing __noreturn" warning Josh Poimboeuf
2023-03-28 9:10 ` Miroslav Benes
2023-03-29 16:24 ` Josh Poimboeuf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=217a005fe22f9d33f99fed499d6508af9f5cabd0.1679932620.git.jpoimboe@kernel.org \
--to=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®