Skip to content

Commit 24ff652

Browse files
author
Peter Zijlstra
committed
objtool: Teach get_alt_entry() about more relocation types
Occasionally objtool encounters symbol (as opposed to section) relocations in .altinstructions. Typically they are the alternatives written by elf_add_alternative() as encountered on a noinstr validation run on vmlinux after having already ran objtool on the individual .o files. Basically this is the counterpart of commit 44f6a7c ("objtool: Fix seg fault with Clang non-section symbols"), because when these new assemblers (binutils now also does this) strip the section symbols, elf_add_reloc_to_insn() is forced to emit symbol based relocations. As such, teach get_alt_entry() about different relocation types. Fixes: 9bc0bb5 ("objtool/x86: Rewrite retpoline thunk calls") Reported-by: Stephen Rothwell <[email protected]> Reported-by: Borislav Petkov <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Tested-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e4e737b commit 24ff652

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

tools/objtool/special.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ void __weak arch_handle_alternative(unsigned short feature, struct special_alt *
5858
{
5959
}
6060

61+
static bool reloc2sec_off(struct reloc *reloc, struct section **sec, unsigned long *off)
62+
{
63+
switch (reloc->sym->type) {
64+
case STT_FUNC:
65+
*sec = reloc->sym->sec;
66+
*off = reloc->sym->offset + reloc->addend;
67+
return true;
68+
69+
case STT_SECTION:
70+
*sec = reloc->sym->sec;
71+
*off = reloc->addend;
72+
return true;
73+
74+
default:
75+
return false;
76+
}
77+
}
78+
6179
static int get_alt_entry(struct elf *elf, struct special_entry *entry,
6280
struct section *sec, int idx,
6381
struct special_alt *alt)
@@ -91,15 +109,12 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry,
91109
WARN_FUNC("can't find orig reloc", sec, offset + entry->orig);
92110
return -1;
93111
}
94-
if (orig_reloc->sym->type != STT_SECTION) {
95-
WARN_FUNC("don't know how to handle non-section reloc symbol %s",
112+
if (!reloc2sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off)) {
113+
WARN_FUNC("don't know how to handle reloc symbol type: %s",
96114
sec, offset + entry->orig, orig_reloc->sym->name);
97115
return -1;
98116
}
99117

100-
alt->orig_sec = orig_reloc->sym->sec;
101-
alt->orig_off = orig_reloc->addend;
102-
103118
if (!entry->group || alt->new_len) {
104119
new_reloc = find_reloc_by_dest(elf, sec, offset + entry->new);
105120
if (!new_reloc) {
@@ -116,8 +131,11 @@ static int get_alt_entry(struct elf *elf, struct special_entry *entry,
116131
if (arch_is_retpoline(new_reloc->sym))
117132
return 1;
118133

119-
alt->new_sec = new_reloc->sym->sec;
120-
alt->new_off = (unsigned int)new_reloc->addend;
134+
if (!reloc2sec_off(new_reloc, &alt->new_sec, &alt->new_off)) {
135+
WARN_FUNC("don't know how to handle reloc symbol type: %s",
136+
sec, offset + entry->new, new_reloc->sym->name);
137+
return -1;
138+
}
121139

122140
/* _ASM_EXTABLE_EX hack */
123141
if (alt->new_off >= 0x7ffffff0)

0 commit comments

Comments
 (0)