All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] objtool: Don't add empty symbols to the rbtree
@ 2021-01-07  3:33 Josh Poimboeuf
  2021-01-07  9:27 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Josh Poimboeuf @ 2021-01-07  3:33 UTC (permalink / raw)
  To: x86; +Cc: linux-kernel, Peter Zijlstra, Nick Desaulniers, Arnd Bergmann

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 <arnd@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
---
 tools/objtool/elf.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index be89c741ba9a..ccee8fc331f0 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -448,6 +448,13 @@ static int read_symbols(struct elf *elf)
 		list_add(&sym->list, entry);
 		elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
 		elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
+
+		/*
+		 * Don't store empty STT_NOTYPE symbols in the rbtree.  They
+		 * can exist within a real function, confusing the sorting.
+		 */
+		if (!sym->len)
+			rb_erase(&sym->node, &sym->sec->symbol_tree);
 	}
 
 	if (stats)
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] objtool: Don't add empty symbols to the rbtree
  2021-01-07  3:33 [PATCH] objtool: Don't add empty symbols to the rbtree Josh Poimboeuf
@ 2021-01-07  9:27 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2021-01-07  9:27 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: x86, linux-kernel, Nick Desaulniers, Arnd Bergmann

On Wed, Jan 06, 2021 at 09:33:20PM -0600, Josh Poimboeuf wrote:
> 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.

Right, overlapping things needs a different data structure, could be
done though, but like you say, moar work.

> Reported-by: Arnd Bergmann <arnd@kernel.org>
> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>

> ---
>  tools/objtool/elf.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index be89c741ba9a..ccee8fc331f0 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -448,6 +448,13 @@ static int read_symbols(struct elf *elf)
>  		list_add(&sym->list, entry);
>  		elf_hash_add(elf->symbol_hash, &sym->hash, sym->idx);
>  		elf_hash_add(elf->symbol_name_hash, &sym->name_hash, str_hash(sym->name));
> +
> +		/*
> +		 * Don't store empty STT_NOTYPE symbols in the rbtree.  They
> +		 * can exist within a real function, confusing the sorting.
> +		 */
> +		if (!sym->len)
> +			rb_erase(&sym->node, &sym->sec->symbol_tree);
>  	}
>  
>  	if (stats)
> -- 
> 2.29.2
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-07  9:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-07  3:33 [PATCH] objtool: Don't add empty symbols to the rbtree Josh Poimboeuf
2021-01-07  9:27 ` Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.