Skip to content

Commit 7e01772

Browse files
achartrePeter Zijlstra
authored andcommitted
objtool: Disassemble jump table alternatives
When using the --disas option, also disassemble jump tables. Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org> Link: https://patch.msgid.link/20251121095340.464045-24-alexandre.chartre@oracle.com
1 parent 78df459 commit 7e01772

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

tools/objtool/disas.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,34 @@ static int disas_alt_add_insn(struct disas_alt *dalt, int index, char *insn_str,
639639
return 0;
640640
}
641641

642+
static int disas_alt_jump(struct disas_alt *dalt)
643+
{
644+
struct instruction *orig_insn;
645+
struct instruction *dest_insn;
646+
char suffix[2] = { 0 };
647+
char *str;
648+
649+
orig_insn = dalt->orig_insn;
650+
dest_insn = dalt->alt->insn;
651+
652+
if (orig_insn->type == INSN_NOP) {
653+
if (orig_insn->len == 5)
654+
suffix[0] = 'q';
655+
str = strfmt("jmp%-3s %lx <%s+0x%lx>", suffix,
656+
dest_insn->offset, dest_insn->sym->name,
657+
dest_insn->offset - dest_insn->sym->offset);
658+
} else {
659+
str = strfmt("nop%d", orig_insn->len);
660+
}
661+
662+
if (!str)
663+
return -1;
664+
665+
disas_alt_add_insn(dalt, 0, str, 0);
666+
667+
return 1;
668+
}
669+
642670
/*
643671
* Disassemble an exception table alternative.
644672
*/
@@ -809,19 +837,17 @@ static void *disas_alt(struct disas_context *dctx,
809837
goto done;
810838
}
811839

812-
/*
813-
* Only group alternatives and exception tables are
814-
* supported at the moment.
815-
*/
840+
count = -1;
816841
switch (dalt->alt->type) {
817842
case ALT_TYPE_INSTRUCTIONS:
818843
count = disas_alt_group(dctx, dalt);
819844
break;
820845
case ALT_TYPE_EX_TABLE:
821846
count = disas_alt_extable(dalt);
822847
break;
823-
default:
824-
count = 0;
848+
case ALT_TYPE_JUMP_TABLE:
849+
count = disas_alt_jump(dalt);
850+
break;
825851
}
826852
if (count < 0) {
827853
WARN("%s: failed to disassemble alternative %s",

0 commit comments

Comments
 (0)