Skip to content

Commit 023f234

Browse files
author
Peter Zijlstra
committed
objtool: Fix weak hole vs prefix symbol
Boris (and the robot) reported that objtool grew a new complaint about unreachable instructions. Upon inspection it was immediately clear the __weak zombie instructions struck again. For the unweary, the linker will simply remove the symbol for overriden __weak symbols but leave the instructions in place, creating unreachable instructions -- and objtool likes to report these. Commit 4adb236 ("objtool: Ignore extra-symbol code") was supposed to have dealt with that, but the new commit 9f2899f ("objtool: Add option to generate prefix symbols") subtly broke that logic by created unvisited symbols. Fixes: 9f2899f ("objtool: Add option to generate prefix symbols") Reported-by: Borislav Petkov <[email protected]> Reported-by: kernel test robot <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
1 parent 1952671 commit 023f234

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tools/objtool/check.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4053,8 +4053,28 @@ static int add_prefix_symbol(struct objtool_file *file, struct symbol *func,
40534053

40544054
offset = func->offset - prev->offset;
40554055
if (offset >= opts.prefix) {
4056-
if (offset == opts.prefix)
4056+
if (offset == opts.prefix) {
4057+
/*
4058+
* Since the sec->symbol_list is ordered by
4059+
* offset (see elf_add_symbol()) the added
4060+
* symbol will not be seen by the iteration in
4061+
* validate_section().
4062+
*
4063+
* Hence the lack of list_for_each_entry_safe()
4064+
* there.
4065+
*
4066+
* The direct concequence is that prefix symbols
4067+
* don't get visited (because pointless), except
4068+
* for the logic in ignore_unreachable_insn()
4069+
* that needs the terminating insn to be visited
4070+
* otherwise it will report the hole.
4071+
*
4072+
* Hence mark the first instruction of the
4073+
* prefix symbol as visisted.
4074+
*/
4075+
prev->visited |= VISITED_BRANCH;
40574076
elf_create_prefix_symbol(file->elf, func, opts.prefix);
4077+
}
40584078
break;
40594079
}
40604080
insn = prev;

0 commit comments

Comments
 (0)