Skip to content

Commit a2e38df

Browse files
committed
objtool: Don't add empty symbols to the rbtree
Building with the Clang assembler shows the following warning: arch/x86/kernel/ftrace_64.o: warning: objtool: missing symbol for insn at offset 0x16 The Clang assembler strips section symbols. That ends up giving objtool's find_func_containing() much more test coverage than normal. Turns out, find_func_containing() doesn't work so well for overlapping symbols: 2: 000000000000000e 0 NOTYPE LOCAL DEFAULT 2 fgraph_trace 3: 000000000000000f 0 NOTYPE LOCAL DEFAULT 2 trace 4: 0000000000000000 165 FUNC GLOBAL DEFAULT 2 __fentry__ 5: 000000000000000e 0 NOTYPE GLOBAL DEFAULT 2 ftrace_stub The zero-length NOTYPE symbols are inside __fentry__(), confusing the rbtree search for any __fentry__() offset coming after a NOTYPE. Try to avoid this problem by not adding zero-length symbols to the rbtree. They're rare and aren't needed in the rbtree anyway. One caveat, this actually might not end up being the right fix. Non-empty overlapping symbols, if they exist, could have the same problem. But that would need bigger changes, let's see if we can get away with the easy fix for now. Reported-by: Arnd Bergmann <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]>
1 parent 7c53f6b commit a2e38df

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/objtool/elf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ static int read_symbols(struct elf *elf)
448448
list_add(&sym->list, entry);
449449
elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
450450
elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
451+
452+
/*
453+
* Don't store empty STT_NOTYPE symbols in the rbtree. They
454+
* can exist within a function, confusing the sorting.
455+
*/
456+
if (!sym->len)
457+
rb_erase(&sym->node, &sym->sec->symbol_tree);
451458
}
452459

453460
if (stats)

0 commit comments

Comments
 (0)