diff options
Diffstat (limited to 'tools/objtool/elf.c')
-rw-r--r-- | tools/objtool/elf.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4e1d7460574b..be89c741ba9a 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -262,6 +262,32 @@ struct reloc *find_reloc_by_dest(const struct elf *elf, struct section *sec, uns return find_reloc_by_dest_range(elf, sec, offset, 1); } +void insn_to_reloc_sym_addend(struct section *sec, unsigned long offset, + struct reloc *reloc) +{ + if (sec->sym) { + reloc->sym = sec->sym; + reloc->addend = offset; + return; + } + + /* + * The Clang assembler strips section symbols, so we have to reference + * the function symbol instead: + */ + reloc->sym = find_symbol_containing(sec, offset); + 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(sec, offset - 1); + } + + if (reloc->sym) + reloc->addend = offset - reloc->sym->offset; +} + static int read_sections(struct elf *elf) { Elf_Scn *s = NULL; |