[PATCH v2] objtool: Report section name in elf_init_reloc_text_sym() warning

From: Kees Cook
Date: Mon May 06 2024 - 11:56:03 EST


While tracking down issues with LKDTM's .rodata "function", I found
the warning from elf_init_reloc_text_sym() to be unhelpful because it
wasn't clear which calling path it was coming from. Report the sec->name
and rephrase the warning a bit. Additionally check for NULL sym->name,
which may happen.

Before:

vmlinux.o: warning: objtool: bad call to elf_init_reloc_text_sym() for data symbol .rodata

After:

vmlinux.o: warning: objtool: .cfi_sites: unexpected reference to non-executable symbol '.rodata'

Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
---
Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
v1: https://lore.kernel.org/lkml/20240430235106.work.680-kees@xxxxxxxxxx/
---
tools/objtool/elf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 3d27983dc908..b38cedd4fd55 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -891,8 +891,8 @@ struct reloc *elf_init_reloc_text_sym(struct elf *elf, struct section *sec,
int addend = insn_off;

if (!(insn_sec->sh.sh_flags & SHF_EXECINSTR)) {
- WARN("bad call to %s() for data symbol %s",
- __func__, sym->name);
+ WARN("%s: unexpected reference to non-executable symbol '%s'",
+ sec->name, sym->name ?: "<unknown>");
return NULL;
}

--
2.34.1