objtool: Fix weak hole vs prefix symbol
authorPeter Zijlstra <peterz@infradead.org>
Thu, 3 Nov 2022 19:57:51 +0000 (20:57 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Sat, 5 Nov 2022 10:28:02 +0000 (11:28 +0100)
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 4adb23686795 ("objtool: Ignore extra-symbol code") was supposed
to have dealt with that, but the new commit 9f2899fe36a6 ("objtool:
Add option to generate prefix symbols") subtly broke that logic by
created unvisited symbols.

Fixes: 9f2899fe36a6 ("objtool: Add option to generate prefix symbols")
Reported-by: Borislav Petkov <bp@alien8.de>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
tools/objtool/check.c

index 55066c49357026dcbfa810397eeeb24a9d8f497d..4f1a7384426b4525a9247c67956396f2ec52748d 100644 (file)
@@ -4053,8 +4053,28 @@ static int add_prefix_symbol(struct objtool_file *file, struct symbol *func,
 
                offset = func->offset - prev->offset;
                if (offset >= opts.prefix) {
-                       if (offset == opts.prefix)
+                       if (offset == opts.prefix) {
+                               /*
+                                * Since the sec->symbol_list is ordered by
+                                * offset (see elf_add_symbol()) the added
+                                * symbol will not be seen by the iteration in
+                                * validate_section().
+                                *
+                                * Hence the lack of list_for_each_entry_safe()
+                                * there.
+                                *
+                                * The direct concequence is that prefix symbols
+                                * don't get visited (because pointless), except
+                                * for the logic in ignore_unreachable_insn()
+                                * that needs the terminating insn to be visited
+                                * otherwise it will report the hole.
+                                *
+                                * Hence mark the first instruction of the
+                                * prefix symbol as visisted.
+                                */
+                               prev->visited |= VISITED_BRANCH;
                                elf_create_prefix_symbol(file->elf, func, opts.prefix);
+                       }
                        break;
                }
                insn = prev;