Skip to content

Commit 99c0beb

Browse files
jpoimboePeter Zijlstra
authored andcommitted
objtool: Add option to print section addresses
To help prevent objtool users from having to do math to convert function addresses to section addresses, and to help out with finding data addresses reported by IBT validation, add an option to print the section address in addition to the function address. Normal: vmlinux.o: warning: objtool: fixup_exception()+0x2d1: unreachable instruction With '--sec-address': vmlinux.o: warning: objtool: fixup_exception()+0x2d1 (.text+0x76c51): unreachable instruction Suggested-by: Nick Desaulniers <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Link: https://lkml.kernel.org/r/2cea4d5299d53d1a4c09212a6ad7820aa46fda7a.1650300597.git.jpoimboe@redhat.com
1 parent 2bc3dec commit 99c0beb

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

tools/objtool/builtin-check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const struct option check_options[] = {
5050
OPT_BOOLEAN(0, "module", &opts.module, "object is part of a kernel module"),
5151
OPT_BOOLEAN(0, "no-fp", &opts.no_fp, "skip frame pointer validation"),
5252
OPT_BOOLEAN(0, "no-unreachable", &opts.no_unreachable, "skip 'unreachable instruction' warnings"),
53+
OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses in warnings"),
5354
OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"),
5455
OPT_BOOLEAN(0, "vmlinux", &opts.vmlinux, "vmlinux.o validation"),
5556

tools/objtool/include/objtool/builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct opts {
2828
bool module;
2929
bool no_fp;
3030
bool no_unreachable;
31+
bool sec_address;
3132
bool stats;
3233
bool vmlinux;
3334
};

tools/objtool/include/objtool/warn.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,33 @@
1111
#include <sys/types.h>
1212
#include <sys/stat.h>
1313
#include <fcntl.h>
14+
#include <objtool/builtin.h>
1415
#include <objtool/elf.h>
1516

1617
extern const char *objname;
1718

1819
static inline char *offstr(struct section *sec, unsigned long offset)
1920
{
20-
struct symbol *func;
21-
char *name, *str;
22-
unsigned long name_off;
21+
bool is_text = (sec->sh.sh_flags & SHF_EXECINSTR);
22+
struct symbol *sym = NULL;
23+
char *str;
24+
int len;
2325

24-
func = find_func_containing(sec, offset);
25-
if (!func)
26-
func = find_symbol_containing(sec, offset);
27-
if (func) {
28-
name = func->name;
29-
name_off = offset - func->offset;
26+
if (is_text)
27+
sym = find_func_containing(sec, offset);
28+
if (!sym)
29+
sym = find_symbol_containing(sec, offset);
30+
31+
if (sym) {
32+
str = malloc(strlen(sym->name) + strlen(sec->name) + 40);
33+
len = sprintf(str, "%s+0x%lx", sym->name, offset - sym->offset);
34+
if (opts.sec_address)
35+
sprintf(str+len, " (%s+0x%lx)", sec->name, offset);
3036
} else {
31-
name = sec->name;
32-
name_off = offset;
37+
str = malloc(strlen(sec->name) + 20);
38+
sprintf(str, "%s+0x%lx", sec->name, offset);
3339
}
3440

35-
str = malloc(strlen(name) + 20);
36-
sprintf(str, "%s+0x%lx", name, name_off);
37-
3841
return str;
3942
}
4043

0 commit comments

Comments
 (0)