Skip to content

Commit 258c760

Browse files
jpoimboeKAGA-KOKO
authored andcommitted
objtool: Allow alternatives to be ignored
Getting objtool to understand retpolines is going to be a bit of a challenge. For now, take advantage of the fact that retpolines are patched in with alternatives. Just read the original (sane) non-alternative instruction, and ignore the patched-in retpoline. This allows objtool to understand the control flow *around* the retpoline, even if it can't yet follow what's inside. This means the ORC unwinder will fail to unwind from inside a retpoline, but will work fine otherwise. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: Rik van Riel <[email protected]> Cc: Andi Kleen <[email protected]> Cc: [email protected] Cc: Peter Zijlstra <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Jiri Kosina <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Kees Cook <[email protected]> Cc: Tim Chen <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Paul Turner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 39b7353 commit 258c760

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

tools/objtool/check.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,40 @@ static void add_ignores(struct objtool_file *file)
427427
}
428428
}
429429

430+
/*
431+
* FIXME: For now, just ignore any alternatives which add retpolines. This is
432+
* a temporary hack, as it doesn't allow ORC to unwind from inside a retpoline.
433+
* But it at least allows objtool to understand the control flow *around* the
434+
* retpoline.
435+
*/
436+
static int add_nospec_ignores(struct objtool_file *file)
437+
{
438+
struct section *sec;
439+
struct rela *rela;
440+
struct instruction *insn;
441+
442+
sec = find_section_by_name(file->elf, ".rela.discard.nospec");
443+
if (!sec)
444+
return 0;
445+
446+
list_for_each_entry(rela, &sec->rela_list, list) {
447+
if (rela->sym->type != STT_SECTION) {
448+
WARN("unexpected relocation symbol type in %s", sec->name);
449+
return -1;
450+
}
451+
452+
insn = find_insn(file, rela->sym->sec, rela->addend);
453+
if (!insn) {
454+
WARN("bad .discard.nospec entry");
455+
return -1;
456+
}
457+
458+
insn->ignore_alts = true;
459+
}
460+
461+
return 0;
462+
}
463+
430464
/*
431465
* Find the destination instructions for all jumps.
432466
*/
@@ -509,11 +543,18 @@ static int add_call_destinations(struct objtool_file *file)
509543
dest_off = insn->offset + insn->len + insn->immediate;
510544
insn->call_dest = find_symbol_by_offset(insn->sec,
511545
dest_off);
546+
/*
547+
* FIXME: Thanks to retpolines, it's now considered
548+
* normal for a function to call within itself. So
549+
* disable this warning for now.
550+
*/
551+
#if 0
512552
if (!insn->call_dest) {
513553
WARN_FUNC("can't find call dest symbol at offset 0x%lx",
514554
insn->sec, insn->offset, dest_off);
515555
return -1;
516556
}
557+
#endif
517558
} else if (rela->sym->type == STT_SECTION) {
518559
insn->call_dest = find_symbol_by_offset(rela->sym->sec,
519560
rela->addend+4);
@@ -678,12 +719,6 @@ static int add_special_section_alts(struct objtool_file *file)
678719
return ret;
679720

680721
list_for_each_entry_safe(special_alt, tmp, &special_alts, list) {
681-
alt = malloc(sizeof(*alt));
682-
if (!alt) {
683-
WARN("malloc failed");
684-
ret = -1;
685-
goto out;
686-
}
687722

688723
orig_insn = find_insn(file, special_alt->orig_sec,
689724
special_alt->orig_off);
@@ -694,6 +729,10 @@ static int add_special_section_alts(struct objtool_file *file)
694729
goto out;
695730
}
696731

732+
/* Ignore retpoline alternatives. */
733+
if (orig_insn->ignore_alts)
734+
continue;
735+
697736
new_insn = NULL;
698737
if (!special_alt->group || special_alt->new_len) {
699738
new_insn = find_insn(file, special_alt->new_sec,
@@ -719,6 +758,13 @@ static int add_special_section_alts(struct objtool_file *file)
719758
goto out;
720759
}
721760

761+
alt = malloc(sizeof(*alt));
762+
if (!alt) {
763+
WARN("malloc failed");
764+
ret = -1;
765+
goto out;
766+
}
767+
722768
alt->insn = new_insn;
723769
list_add_tail(&alt->list, &orig_insn->alts);
724770

@@ -1035,6 +1081,10 @@ static int decode_sections(struct objtool_file *file)
10351081

10361082
add_ignores(file);
10371083

1084+
ret = add_nospec_ignores(file);
1085+
if (ret)
1086+
return ret;
1087+
10381088
ret = add_jump_destinations(file);
10391089
if (ret)
10401090
return ret;

tools/objtool/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct instruction {
4444
unsigned int len;
4545
unsigned char type;
4646
unsigned long immediate;
47-
bool alt_group, visited, dead_end, ignore, hint, save, restore;
47+
bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts;
4848
struct symbol *call_dest;
4949
struct instruction *jump_dest;
5050
struct list_head alts;

0 commit comments

Comments
 (0)