Skip to content

Commit e2d9494

Browse files
Peter Zijlstraingomolnar
authored andcommitted
objtool: Provide stats for jump_labels
Add objtool --stats to count the jump_label sites it encounters. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210506194158.153101906@infradead.org
1 parent 6d37b83 commit e2d9494

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎tools/objtool/check.c‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,8 +1225,15 @@ static int handle_jump_alt(struct objtool_file *file,
12251225
struct instruction *orig_insn,
12261226
struct instruction **new_insn)
12271227
{
1228-
if (orig_insn->type == INSN_NOP)
1228+
if (orig_insn->type == INSN_NOP) {
1229+
do_nop:
1230+
if (orig_insn->len == 2)
1231+
file->jl_nop_short++;
1232+
else
1233+
file->jl_nop_long++;
1234+
12291235
return 0;
1236+
}
12301237

12311238
if (orig_insn->type != INSN_JUMP_UNCONDITIONAL) {
12321239
WARN_FUNC("unsupported instruction at jump label",
@@ -1245,9 +1252,14 @@ static int handle_jump_alt(struct objtool_file *file,
12451252
orig_insn->offset, orig_insn->len,
12461253
arch_nop_insn(orig_insn->len));
12471254
orig_insn->type = INSN_NOP;
1248-
return 0;
1255+
goto do_nop;
12491256
}
12501257

1258+
if (orig_insn->len == 2)
1259+
file->jl_short++;
1260+
else
1261+
file->jl_long++;
1262+
12511263
*new_insn = list_next_entry(orig_insn, list);
12521264
return 0;
12531265
}
@@ -1328,6 +1340,12 @@ static int add_special_section_alts(struct objtool_file *file)
13281340
free(special_alt);
13291341
}
13301342

1343+
if (stats) {
1344+
printf("jl\\\tNOP\tJMP\n");
1345+
printf("short:\t%ld\t%ld\n", file->jl_nop_short, file->jl_short);
1346+
printf("long:\t%ld\t%ld\n", file->jl_nop_long, file->jl_long);
1347+
}
1348+
13311349
out:
13321350
return ret;
13331351
}

‎tools/objtool/include/objtool/objtool.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ struct objtool_file {
2222
struct list_head static_call_list;
2323
struct list_head mcount_loc_list;
2424
bool ignore_unreachables, c_file, hints, rodata;
25+
26+
unsigned long jl_short, jl_long;
27+
unsigned long jl_nop_short, jl_nop_long;
2528
};
2629

2730
struct objtool_file *objtool_open_read(const char *_objname);

0 commit comments

Comments
 (0)