Skip to content

Commit 9903346

Browse files
committed
objtool: Support asm jump tables
Objtool detection of asm jump tables would normally just work, except for the fact that asm retpolines use alternatives. Objtool thinks the alternative code path (a jump to the retpoline) is a sibling call. Don't treat alternative indirect branches as sibling calls when the original instruction has a jump table. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Tested-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Ard Biesheuvel <ardb@kernel.org> Tested-by: Sami Tolvanen <samitolvanen@google.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Link: https://lore.kernel.org/r/460cf4dc675d64e1124146562cabd2c05aa322e8.1614182415.git.jpoimboe@redhat.com
1 parent 900b4df commit 9903346

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎tools/objtool/check.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ static struct instruction *prev_insn_same_sym(struct objtool_file *file,
108108
for (insn = next_insn_same_sec(file, insn); insn; \
109109
insn = next_insn_same_sec(file, insn))
110110

111+
static bool is_jump_table_jump(struct instruction *insn)
112+
{
113+
struct alt_group *alt_group = insn->alt_group;
114+
115+
if (insn->jump_table)
116+
return true;
117+
118+
/* Retpoline alternative for a jump table? */
119+
return alt_group && alt_group->orig_group &&
120+
alt_group->orig_group->first_insn->jump_table;
121+
}
122+
111123
static bool is_sibling_call(struct instruction *insn)
112124
{
113125
/*
@@ -120,7 +132,7 @@ static bool is_sibling_call(struct instruction *insn)
120132

121133
/* An indirect jump is either a sibling call or a jump to a table. */
122134
if (insn->type == INSN_JUMP_DYNAMIC)
123-
return list_empty(&insn->alts);
135+
return !is_jump_table_jump(insn);
124136

125137
/* add_jump_destinations() sets insn->call_dest for sibling calls. */
126138
return (is_static_jump(insn) && insn->call_dest);

0 commit comments

Comments
 (0)