2022-07-24 02:31:42

by Leo Yan

[permalink] [raw]
Subject: [PATCH v2 2/2] perf symbol: Skip recording symbols in '.gnu.warning.*' sections

Some symbols are observed their 'st_value' field are zeros. E.g.
libc.so.6 in Ubuntu contains a symbol '__evoke_link_warning_getwd' which
resides in the '.gnu.warning.getwd' section, unlike normal symbols, this
kind of symbols are only used for linker warning.

This patch skips to record symbols from '.gnu.warning.*' sections by
detecting the sub string '.gnu.warning' is contained in section name.

Signed-off-by: Leo Yan <[email protected]>
---
tools/perf/util/symbol-elf.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index ef6ced5c5746..4b621e355c0e 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1277,6 +1277,14 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,

section_name = elf_sec__name(&shdr, secstrs);

+ /*
+ * A symbol coming from ".gnu.warning.*" sections is used to
+ * generate linker warnings, its 'sym.st_value' field usually
+ * is zero, skip to record it.
+ */
+ if (strstr(section_name, ".gnu.warning"))
+ continue;
+
/* On ARM, symbols for thumb functions have 1 added to
* the symbol address as a flag - remove it */
if ((ehdr.e_machine == EM_ARM) &&
--
2.25.1


2022-07-24 03:43:41

by Fangrui Song

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] perf symbol: Skip recording symbols in '.gnu.warning.*' sections

On Sat, Jul 23, 2022 at 7:29 PM Leo Yan <[email protected]> wrote:
>
> Some symbols are observed their 'st_value' field are zeros. E.g.
> libc.so.6 in Ubuntu contains a symbol '__evoke_link_warning_getwd' which
> resides in the '.gnu.warning.getwd' section, unlike normal symbols, this
> kind of symbols are only used for linker warning.
>
> This patch skips to record symbols from '.gnu.warning.*' sections by
> detecting the sub string '.gnu.warning' is contained in section name.
>
> Signed-off-by: Leo Yan <[email protected]>

Presumably __evoke_link_warning_getwd is due to `clang -fuse-ld=lld
-static ...` on a file calling the deprecated getwd.
GNU ld and gold implement a .gnu.warning.* feature which removes the
section. ld.lld just ignores this section as the usefulness of the
functionality is unclear.

The section .gnu.warning.getwd does not have the SHF_ALLOC flag. Such
sections are not part of memory images and I think it is more generic
ignoring all symbols residing in a non-SHF_ALLOC section.

> ---
> tools/perf/util/symbol-elf.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
> index ef6ced5c5746..4b621e355c0e 100644
> --- a/tools/perf/util/symbol-elf.c
> +++ b/tools/perf/util/symbol-elf.c
> @@ -1277,6 +1277,14 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
>
> section_name = elf_sec__name(&shdr, secstrs);
>
> + /*
> + * A symbol coming from ".gnu.warning.*" sections is used to
> + * generate linker warnings, its 'sym.st_value' field usually
> + * is zero, skip to record it.
> + */
> + if (strstr(section_name, ".gnu.warning"))
> + continue;
> +
> /* On ARM, symbols for thumb functions have 1 added to
> * the symbol address as a flag - remove it */
> if ((ehdr.e_machine == EM_ARM) &&
> --
> 2.25.1
>


--
宋方睿

2022-07-24 05:41:50

by Leo Yan

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] perf symbol: Skip recording symbols in '.gnu.warning.*' sections

On Sat, Jul 23, 2022 at 08:42:20PM -0700, Fangrui Song wrote:
> On Sat, Jul 23, 2022 at 7:29 PM Leo Yan <[email protected]> wrote:
> >
> > Some symbols are observed their 'st_value' field are zeros. E.g.
> > libc.so.6 in Ubuntu contains a symbol '__evoke_link_warning_getwd' which
> > resides in the '.gnu.warning.getwd' section, unlike normal symbols, this
> > kind of symbols are only used for linker warning.
> >
> > This patch skips to record symbols from '.gnu.warning.*' sections by
> > detecting the sub string '.gnu.warning' is contained in section name.
> >
> > Signed-off-by: Leo Yan <[email protected]>
>
> Presumably __evoke_link_warning_getwd is due to `clang -fuse-ld=lld
> -static ...` on a file calling the deprecated getwd.
> GNU ld and gold implement a .gnu.warning.* feature which removes the
> section. ld.lld just ignores this section as the usefulness of the
> functionality is unclear.
>
> The section .gnu.warning.getwd does not have the SHF_ALLOC flag. Such
> sections are not part of memory images and I think it is more generic
> ignoring all symbols residing in a non-SHF_ALLOC section.

Good point! Will refine the patch for this and send out soon.

Thanks a lot, Fangrui.