Skip to content

Commit 34c861e

Browse files
jpoimboePeter Zijlstra
authored andcommitted
objtool: Fix sibling call detection in alternatives
In add_jump_destinations(), sibling call detection requires 'insn->func' to be valid. But alternative instructions get their 'func' set in handle_group_alt(), which runs *after* add_jump_destinations(). So sibling calls in alternatives code don't get properly detected. Fix that by changing the initialization order: call add_special_section_alts() *before* add_jump_destinations(). This also means the special case for a missing 'jump_dest' in add_jump_destinations() can be removed, as it has already been dealt with. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/c02e0a0a2a4286b5f848d17c77fdcb7e0caf709c.1649718562.git.jpoimboe@redhat.com
1 parent 26ff604 commit 34c861e

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

tools/objtool/check.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,13 @@ static int add_jump_destinations(struct objtool_file *file)
12771277
unsigned long dest_off;
12781278

12791279
for_each_insn(file, insn) {
1280+
if (insn->jump_dest) {
1281+
/*
1282+
* handle_group_alt() may have previously set
1283+
* 'jump_dest' for some alternatives.
1284+
*/
1285+
continue;
1286+
}
12801287
if (!is_static_jump(insn))
12811288
continue;
12821289

@@ -1308,15 +1315,6 @@ static int add_jump_destinations(struct objtool_file *file)
13081315

13091316
jump_dest = find_insn(file, dest_sec, dest_off);
13101317
if (!jump_dest) {
1311-
1312-
/*
1313-
* This is a special case where an alt instruction
1314-
* jumps past the end of the section. These are
1315-
* handled later in handle_group_alt().
1316-
*/
1317-
if (!strcmp(insn->sec->name, ".altinstr_replacement"))
1318-
continue;
1319-
13201318
WARN_FUNC("can't find jump dest instruction at %s+0x%lx",
13211319
insn->sec, insn->offset, dest_sec->name,
13221320
dest_off);
@@ -1549,13 +1547,13 @@ static int handle_group_alt(struct objtool_file *file,
15491547
continue;
15501548

15511549
dest_off = arch_jump_destination(insn);
1552-
if (dest_off == special_alt->new_off + special_alt->new_len)
1550+
if (dest_off == special_alt->new_off + special_alt->new_len) {
15531551
insn->jump_dest = next_insn_same_sec(file, last_orig_insn);
1554-
1555-
if (!insn->jump_dest) {
1556-
WARN_FUNC("can't find alternative jump destination",
1557-
insn->sec, insn->offset);
1558-
return -1;
1552+
if (!insn->jump_dest) {
1553+
WARN_FUNC("can't find alternative jump destination",
1554+
insn->sec, insn->offset);
1555+
return -1;
1556+
}
15591557
}
15601558
}
15611559

@@ -2254,14 +2252,14 @@ static int decode_sections(struct objtool_file *file)
22542252
return ret;
22552253

22562254
/*
2257-
* Must be before add_special_section_alts() as that depends on
2258-
* jump_dest being set.
2255+
* Must be before add_jump_destinations(), which depends on 'func'
2256+
* being set for alternatives, to enable proper sibling call detection.
22592257
*/
2260-
ret = add_jump_destinations(file);
2258+
ret = add_special_section_alts(file);
22612259
if (ret)
22622260
return ret;
22632261

2264-
ret = add_special_section_alts(file);
2262+
ret = add_jump_destinations(file);
22652263
if (ret)
22662264
return ret;
22672265

0 commit comments

Comments
 (0)