summaryrefslogtreecommitdiff
path: root/tools/objtool/orc_gen.c
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2020-12-14 16:04:20 -0600
committerPeter Zijlstra <peterz@infradead.org>2020-12-16 14:35:46 +0100
commit44f6a7c0755d8dd453c70557e11687bb080a6f21 (patch)
treecd4c8503c23c827428d30337e9427cdb64d36b26 /tools/objtool/orc_gen.c
parent2c85ebc57b3e1817b6ce1a6b703928e113a90442 (diff)
objtool: Fix seg fault with Clang non-section symbols
The Clang assembler likes to strip section symbols, which means objtool can't reference some text code by its section. This confuses objtool greatly, causing it to seg fault. The fix is similar to what was done before, for ORC reloc generation: e81e07244325 ("objtool: Support Clang non-section symbols in ORC generation") Factor out that code into a common helper and use it for static call reloc generation as well. Reported-by: Arnd Bergmann <arnd@kernel.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Miroslav Benes <mbenes@suse.cz> Link: https://github.com/ClangBuiltLinux/linux/issues/1207 Link: https://lkml.kernel.org/r/ba6b6c0f0dd5acbba66e403955a967d9fdd1726a.1607983452.git.jpoimboe@redhat.com
Diffstat (limited to 'tools/objtool/orc_gen.c')
-rw-r--r--tools/objtool/orc_gen.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index 235663b96adc..9ce68b385a1b 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -105,30 +105,11 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti
}
memset(reloc, 0, sizeof(*reloc));
- if (insn_sec->sym) {
- reloc->sym = insn_sec->sym;
- reloc->addend = insn_off;
- } else {
- /*
- * The Clang assembler doesn't produce section symbols, so we
- * have to reference the function symbol instead:
- */
- reloc->sym = find_symbol_containing(insn_sec, insn_off);
- if (!reloc->sym) {
- /*
- * Hack alert. This happens when we need to reference
- * the NOP pad insn immediately after the function.
- */
- reloc->sym = find_symbol_containing(insn_sec,
- insn_off - 1);
- }
- if (!reloc->sym) {
- WARN("missing symbol for insn at offset 0x%lx\n",
- insn_off);
- return -1;
- }
-
- reloc->addend = insn_off - reloc->sym->offset;
+ insn_to_reloc_sym_addend(insn_sec, insn_off, reloc);
+ if (!reloc->sym) {
+ WARN("missing symbol for insn at offset 0x%lx",
+ insn_off);
+ return -1;
}
reloc->type = R_X86_64_PC32;