Skip to contentSkip to conversation

perf symbols: Consolidate symbol fixup issue

PATCH Superseded Leo Yan 2 participants 4 messages Mar 3, 2020 – Mar 5, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

PATCH v2 1/1 perf symbols: Consolidate symbol fixup issue

After copying Arm64's perf archive with object files and perf.data file to x86 laptop, the x86's perf kernel symbol resolution fails. It outputs 'unknown' for all symbols parsing.

This issue is root caused by the function elf__needs_adjust_symbols(), x86 perf tool uses one weak version, Arm64 (and powerpc) has rewritten their own version. elf__needs_adjust_symbols() decides if need to parse symbols with the relative offset address; but x86 building uses the weak function which misses to check for the elf type 'ET_DYN', so that it cannot parse symbols in Arm DSOs due to the wrong result from elf__needs_adjust_symbols().

The DSO parsing should not depend on any specific architecture perf building; e.g. x86 perf tool can parse Arm and Arm64 DSOs, vice versa. So this patch changes elf__needs_adjust_symbols() as a common function and removes the arch specific functions for Arm64 and powerpc.

In the common elf__needs_adjust_symbols(), it checks elf header and if the machine type is one of Arm64/ppc/ppc64, it checks extra condition for 'ET_DYN'. Finally, the Arm64 DSO can be parsed properly with x86's perf tool.

Before:

  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 [unknown] ([kernel.kallsyms]) => ffff800010c4eaec [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec [unknown] ([kernel.kallsyms]) => ffff800010c4eb00 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 [unknown] ([kernel.kallsyms]) => ffff800010c4e780 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 [unknown] ([kernel.kallsyms]) => ffff800010c4eeac [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc [unknown] ([kernel.kallsyms]) => ffff800010c4ed80 [unknown] ([kernel.kallsyms])

After:

  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c coresight_timeout+0x54 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 coresight_timeout+0x68 ([kernel.kallsyms]) => ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms]) => ffff800010c4eb00 etm4_enable_hw+0x3e0 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 etm4_enable_hw+0x3e8 ([kernel.kallsyms]) => ffff800010c4e780 etm4_enable_hw+0x60 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 etm4_enable_hw+0x80 ([kernel.kallsyms]) => ffff800010c4eeac etm4_enable+0x2d4 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc etm4_enable+0x2e4 ([kernel.kallsyms]) => ffff800010c4ed80 etm4_enable+0x1a8 ([kernel.kallsyms])

v2: Fixed Arm64 and powerpc native building.

---
 tools/perf/arch/arm64/util/Build            |  1 -
 tools/perf/arch/arm64/util/sym-handling.c   | 19 -------------------
 tools/perf/arch/powerpc/util/Build          |  1 -
 tools/perf/arch/powerpc/util/sym-handling.c | 10 ----------
 tools/perf/util/symbol-elf.c                |  8 +++++++-
 5 files changed, 7 insertions(+), 32 deletions(-)
 delete mode 100644 tools/perf/arch/arm64/util/sym-handling.c
tools/perf/arch/arm64/util/Build +0 -1
index 0a7782c61209..789956f76d85 100644
@@ -1,6 +1,5 @@
 perf-y += header.o
 perf-y += perf_regs.o
-perf-y += sym-handling.o
 perf-$(CONFIG_DWARF)     += dwarf-regs.o
 perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
 perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
tools/perf/arch/arm64/util/sym-handling.c deleted +0 -19
deleted file mode 100644
index 8dfa3e5229f1..000000000000
@@ -1,19 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- *
- * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
- */
-
-#include "symbol.h" // for the elf__needs_adjust_symbols() prototype
-#include <stdbool.h>
-
-#ifdef HAVE_LIBELF_SUPPORT
-#include <gelf.h>
-
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
-{
-	return ehdr.e_type == ET_EXEC ||
-	       ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
-}
-#endif
tools/perf/arch/powerpc/util/Build +0 -1
index 7cf0b8803097..e5c9504f8586 100644
@@ -1,5 +1,4 @@
 perf-y += header.o
-perf-y += sym-handling.o
 perf-y += kvm-stat.o
 perf-y += perf_regs.o
 perf-y += mem-events.o
tools/perf/arch/powerpc/util/sym-handling.c +0 -10
index abb7a12d8f93..0856b32f9e08 100644
@@ -10,16 +10,6 @@
 #include "probe-event.h"
 #include "probe-file.h"
 
-#ifdef HAVE_LIBELF_SUPPORT
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
-{
-	return ehdr.e_type == ET_EXEC ||
-	       ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
-}
-
-#endif
-
 int arch__choose_best_symbol(struct symbol *syma,
 			     struct symbol *symb __maybe_unused)
 {
tools/perf/util/symbol-elf.c +7 -1
index 1965aefccb02..ee788ac67415 100644
@@ -704,8 +704,14 @@ void symsrc__destroy(struct symsrc *ss)
 	close(ss->fd);
 }
 
-bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
+bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
 {
+	if (ehdr.e_machine == EM_AARCH64 ||
+	    ehdr.e_machine == EM_PPC ||
+	    ehdr.e_machine == EM_PPC64)
+		return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL ||
+		       ehdr.e_type == ET_DYN;
+
 	return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;
 }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 34 lines · Leo Yan

After copying Arm64's perf archive with object files and perf.data file to x86 laptop, the x86's perf kernel symbol resolution fails. It outputs 'unknown' for all symbols parsing.

This issue is root caused by the function elf__needs_adjust_symbols(), x86 perf tool uses one weak version, Arm64 (and powerpc) has rewritten their own version. elf__needs_adjust_symbols() decides if need to parse symbols with the relative offset address; but x86 building uses the weak function which misses to check for the elf type 'ET_DYN', so that it cannot parse symbols in Arm DSOs due to the wrong result from elf__needs_adjust_symbols().

The DSO parsing should not depend on any specific architecture perf building; e.g. x86 perf tool can parse Arm and Arm64 DSOs, vice versa. So this patch changes elf__needs_adjust_symbols() as a common function and removes the arch specific functions for Arm64 and powerpc.

In the common elf__needs_adjust_symbols(), it checks elf header and if the machine type is one of Arm64/ppc/ppc64, it checks extra condition for 'ET_DYN'. Finally, the Arm64 DSO can be parsed properly with x86's perf tool.

Before:

  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 [unknown] ([kernel.kallsyms]) => ffff800010c4eaec [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec [unknown] ([kernel.kallsyms]) => ffff800010c4eb00 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 [unknown] ([kernel.kallsyms]) => ffff800010c4e780 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 [unknown] ([kernel.kallsyms]) => ffff800010c4eeac [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc [unknown] ([kernel.kallsyms]) => ffff800010c4ed80 [unknown] ([kernel.kallsyms])

After:

Quoted 8 lines
  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c coresight_timeout+0x54 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 coresight_timeout+0x68 ([kernel.kallsyms]) => ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms]) => ffff800010c4eb00 etm4_enable_hw+0x3e0 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 etm4_enable_hw+0x3e8 ([kernel.kallsyms]) => ffff800010c4e780 etm4_enable_hw+0x60 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 etm4_enable_hw+0x80 ([kernel.kallsyms]) => ffff800010c4eeac etm4_enable+0x2d4 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc etm4_enable+0x2e4 ([kernel.kallsyms]) => ffff800010c4ed80 etm4_enable+0x1a8 ([kernel.kallsyms])

I am not able to reproduce this since powerpc64 kernels are not being built as ET_EXEC anymore.

Quoted 88 lines

v2: Fixed Arm64 and powerpc native building.

---
 tools/perf/arch/arm64/util/Build            |  1 -
 tools/perf/arch/arm64/util/sym-handling.c   | 19 -------------------
 tools/perf/arch/powerpc/util/Build          |  1 -
 tools/perf/arch/powerpc/util/sym-handling.c | 10 ----------
 tools/perf/util/symbol-elf.c                |  8 +++++++-
 5 files changed, 7 insertions(+), 32 deletions(-)
 delete mode 100644 tools/perf/arch/arm64/util/sym-handling.c
tools/perf/arch/arm64/util/Build +0 -1
index 0a7782c61209..789956f76d85 100644
@@ -1,6 +1,5 @@
 perf-y += header.o
 perf-y += perf_regs.o
-perf-y += sym-handling.o
 perf-$(CONFIG_DWARF)     += dwarf-regs.o
 perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
 perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
tools/perf/arch/arm64/util/sym-handling.c deleted +0 -19
deleted file mode 100644
index 8dfa3e5229f1..000000000000
@@ -1,19 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- *
- * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
- */
-
-#include "symbol.h" // for the elf__needs_adjust_symbols() prototype
-#include <stdbool.h>
-
-#ifdef HAVE_LIBELF_SUPPORT
-#include <gelf.h>
-
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
-{
-	return ehdr.e_type == ET_EXEC ||
-	       ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
-}
-#endif
tools/perf/arch/powerpc/util/Build +0 -1
index 7cf0b8803097..e5c9504f8586 100644
@@ -1,5 +1,4 @@
 perf-y += header.o
-perf-y += sym-handling.o
 perf-y += kvm-stat.o
 perf-y += perf_regs.o
 perf-y += mem-events.o
tools/perf/arch/powerpc/util/sym-handling.c +0 -10
index abb7a12d8f93..0856b32f9e08 100644
@@ -10,16 +10,6 @@
 #include "probe-event.h"
 #include "probe-file.h"
 
-#ifdef HAVE_LIBELF_SUPPORT
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
-{
-	return ehdr.e_type == ET_EXEC ||
-	       ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
-}
-
-#endif
-
 int arch__choose_best_symbol(struct symbol *syma,
 			     struct symbol *symb __maybe_unused)
 {
tools/perf/util/symbol-elf.c +0 -0
index 1965aefccb02..ee788ac67415 100644
@@ -704,8 +704,14 @@ void symsrc__destroy(struct symsrc *ss)
 	close(ss->fd);
 }
 

tools/perf/util/symbol-elf.c void symsrc__destroy(struct symsrc *ss) · line 715

Quoted 10 lines
tools/perf/util/symbol-elf.c +7 -1
-bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
+bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
 {
+	if (ehdr.e_machine == EM_AARCH64 ||
+	    ehdr.e_machine == EM_PPC ||
+	    ehdr.e_machine == EM_PPC64)
+		return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL ||
+		       ehdr.e_type == ET_DYN;
+
 	return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;

Patch looks good to me. However:

This is only used for checking kernel, so I wonder if we can simply include check for ET_DYN across all architectures? This would only matter if there are architectures building their kernel as ET_DYN that _don't_ want to adjust symbols.

- Naveen

author
#2 lore raw

Hi Naveen,

Quoted 44 lines · Naveen N. Rao
Quoted 34 lines · Leo Yan

After copying Arm64's perf archive with object files and perf.data file to x86 laptop, the x86's perf kernel symbol resolution fails. It outputs 'unknown' for all symbols parsing.

This issue is root caused by the function elf__needs_adjust_symbols(), x86 perf tool uses one weak version, Arm64 (and powerpc) has rewritten their own version. elf__needs_adjust_symbols() decides if need to parse symbols with the relative offset address; but x86 building uses the weak function which misses to check for the elf type 'ET_DYN', so that it cannot parse symbols in Arm DSOs due to the wrong result from elf__needs_adjust_symbols().

The DSO parsing should not depend on any specific architecture perf building; e.g. x86 perf tool can parse Arm and Arm64 DSOs, vice versa. So this patch changes elf__needs_adjust_symbols() as a common function and removes the arch specific functions for Arm64 and powerpc.

In the common elf__needs_adjust_symbols(), it checks elf header and if the machine type is one of Arm64/ppc/ppc64, it checks extra condition for 'ET_DYN'. Finally, the Arm64 DSO can be parsed properly with x86's perf tool.

Before:

  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 [unknown] ([kernel.kallsyms]) => ffff800010c4eaec [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec [unknown] ([kernel.kallsyms]) => ffff800010c4eb00 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 [unknown] ([kernel.kallsyms]) => ffff800010c4e780 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 [unknown] ([kernel.kallsyms]) => ffff800010c4eeac [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc [unknown] ([kernel.kallsyms]) => ffff800010c4ed80 [unknown] ([kernel.kallsyms])

After:

Quoted 8 lines
  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c coresight_timeout+0x54 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 coresight_timeout+0x68 ([kernel.kallsyms]) => ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms]) => ffff800010c4eb00 etm4_enable_hw+0x3e0 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 etm4_enable_hw+0x3e8 ([kernel.kallsyms]) => ffff800010c4e780 etm4_enable_hw+0x60 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 etm4_enable_hw+0x80 ([kernel.kallsyms]) => ffff800010c4eeac etm4_enable+0x2d4 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc etm4_enable+0x2e4 ([kernel.kallsyms]) => ffff800010c4ed80 etm4_enable+0x1a8 ([kernel.kallsyms])
Quoted 2 lines

I am not able to reproduce this since powerpc64 kernels are not being built as ET_EXEC anymore.

Thanks for reviewing!

Based on the context, I think you mean powerpc64 kernels are not being built as ET_DYN anymore (and now change to ET_EXEC).

Quoted 88 lines
Quoted 88 lines

v2: Fixed Arm64 and powerpc native building.

---
 tools/perf/arch/arm64/util/Build            |  1 -
 tools/perf/arch/arm64/util/sym-handling.c   | 19 -------------------
 tools/perf/arch/powerpc/util/Build          |  1 -
 tools/perf/arch/powerpc/util/sym-handling.c | 10 ----------
 tools/perf/util/symbol-elf.c                |  8 +++++++-
 5 files changed, 7 insertions(+), 32 deletions(-)
 delete mode 100644 tools/perf/arch/arm64/util/sym-handling.c
tools/perf/arch/arm64/util/Build +0 -1
index 0a7782c61209..789956f76d85 100644
@@ -1,6 +1,5 @@
 perf-y += header.o
 perf-y += perf_regs.o
-perf-y += sym-handling.o
 perf-$(CONFIG_DWARF)     += dwarf-regs.o
 perf-$(CONFIG_LOCAL_LIBUNWIND) += unwind-libunwind.o
 perf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
tools/perf/arch/arm64/util/sym-handling.c deleted +0 -19
deleted file mode 100644
index 8dfa3e5229f1..000000000000
@@ -1,19 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- *
- * Copyright (C) 2015 Naveen N. Rao, IBM Corporation
- */
-
-#include "symbol.h" // for the elf__needs_adjust_symbols() prototype
-#include <stdbool.h>
-
-#ifdef HAVE_LIBELF_SUPPORT
-#include <gelf.h>
-
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
-{
-	return ehdr.e_type == ET_EXEC ||
-	       ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
-}
-#endif
tools/perf/arch/powerpc/util/Build +0 -1
index 7cf0b8803097..e5c9504f8586 100644
@@ -1,5 +1,4 @@
 perf-y += header.o
-perf-y += sym-handling.o
 perf-y += kvm-stat.o
 perf-y += perf_regs.o
 perf-y += mem-events.o
tools/perf/arch/powerpc/util/sym-handling.c +0 -10
index abb7a12d8f93..0856b32f9e08 100644
@@ -10,16 +10,6 @@
 #include "probe-event.h"
 #include "probe-file.h"
 
-#ifdef HAVE_LIBELF_SUPPORT
-bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
-{
-	return ehdr.e_type == ET_EXEC ||
-	       ehdr.e_type == ET_REL ||
-	       ehdr.e_type == ET_DYN;
-}
-
-#endif
-
 int arch__choose_best_symbol(struct symbol *syma,
 			     struct symbol *symb __maybe_unused)
 {
tools/perf/util/symbol-elf.c +0 -0
index 1965aefccb02..ee788ac67415 100644
@@ -704,8 +704,14 @@ void symsrc__destroy(struct symsrc *ss)
 	close(ss->fd);
 }
 
Quoted 12 lines

tools/perf/util/symbol-elf.c void symsrc__destroy(struct symsrc *ss) · line 715

Quoted 10 lines
tools/perf/util/symbol-elf.c +7 -1
-bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
+bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
 {
+	if (ehdr.e_machine == EM_AARCH64 ||
+	    ehdr.e_machine == EM_PPC ||
+	    ehdr.e_machine == EM_PPC64)
+		return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL ||
+		       ehdr.e_type == ET_DYN;
+
 	return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;

Patch looks good to me. However:

Can I add your review tag?

Quoted 4 lines

This is only used for checking kernel, so I wonder if we can simply include check for ET_DYN across all architectures? This would only matter if there are architectures building their kernel as ET_DYN that _don't_ want to adjust symbols.

Seems only Arm64 enables the link option '-share' for LDFLAGS_vmlinux; I confirmed with below command:

$ find arch -name 'Makefile' -exec grep -n '\-share' {} + | grep vmlinux
arch/arm64/Makefile:21:LDFLAGS_vmlinux          += -shared -Bsymbolic -z notext -z norelro \

Also reviewed the output for searching '\-share' for all Makefiles under 'arch' folder, many architectures use it for vdso but only Arm64 enables '-share' for vmlinux linkage. If so, your suggestion is valid and we can simply include check for ET_DYN for all archs (and it's better to add comment for this).

I'd like to wait a bit for anyone has other ideas, and if no objection will send out new patch for this.

Thanks,
Leo

Reviewed-by
#3 lore raw
Quoted 4 lines · Leo Yan

Hi Naveen,

Quoted 1 line · Naveen N. Rao

Leo Yan wrote:

<snip>

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines

In the common elf__needs_adjust_symbols(), it checks elf header and if the machine type is one of Arm64/ppc/ppc64, it checks extra condition for 'ET_DYN'. Finally, the Arm64 DSO can be parsed properly with x86's perf tool.

Before:

  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 [unknown] ([kernel.kallsyms]) => ffff800010c4eaec [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec [unknown] ([kernel.kallsyms]) => ffff800010c4eb00 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 [unknown] ([kernel.kallsyms]) => ffff800010c4e780 [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 [unknown] ([kernel.kallsyms]) => ffff800010c4eeac [unknown] ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc [unknown] ([kernel.kallsyms]) => ffff800010c4ed80 [unknown] ([kernel.kallsyms])

After:

  # perf script
  main  3258          1          branches:                 0 [unknown] ([unknown]) => ffff800010c4665c coresight_timeout+0x54 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c46670 coresight_timeout+0x68 ([kernel.kallsyms]) => ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eaec etm4_enable_hw+0x3cc ([kernel.kallsyms]) => ffff800010c4eb00 etm4_enable_hw+0x3e0 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eb08 etm4_enable_hw+0x3e8 ([kernel.kallsyms]) => ffff800010c4e780 etm4_enable_hw+0x60 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4e7a0 etm4_enable_hw+0x80 ([kernel.kallsyms]) => ffff800010c4eeac etm4_enable+0x2d4 ([kernel.kallsyms])
  main  3258          1          branches:  ffff800010c4eebc etm4_enable+0x2e4 ([kernel.kallsyms]) => ffff800010c4ed80 etm4_enable+0x1a8 ([kernel.kallsyms])
Quoted 7 lines
Quoted 2 lines

I am not able to reproduce this since powerpc64 kernels are not being built as ET_EXEC anymore.

Thanks for reviewing!

Based on the context, I think you mean powerpc64 kernels are not being built as ET_DYN anymore (and now change to ET_EXEC).

D'uh, indeed, sorry!

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

v2: Fixed Arm64 and powerpc native building.

---
 tools/perf/arch/arm64/util/Build            |  1 -
 tools/perf/arch/arm64/util/sym-handling.c   | 19 -------------------
 tools/perf/arch/powerpc/util/Build          |  1 -
 tools/perf/arch/powerpc/util/sym-handling.c | 10 ----------
 tools/perf/util/symbol-elf.c                |  8 +++++++-
 5 files changed, 7 insertions(+), 32 deletions(-)
 delete mode 100644 tools/perf/arch/arm64/util/sym-handling.c

<snip>

Quoted 21 lines
Quoted 8 lines
Quoted 8 lines
tools/perf/util/symbol-elf.c +0 -0
index 1965aefccb02..ee788ac67415 100644
@@ -704,8 +704,14 @@ void symsrc__destroy(struct symsrc *ss)
 	close(ss->fd);
 }
 
Quoted 12 lines

tools/perf/util/symbol-elf.c void symsrc__destroy(struct symsrc *ss) · line 715

Quoted 10 lines
tools/perf/util/symbol-elf.c +7 -1
-bool __weak elf__needs_adjust_symbols(GElf_Ehdr ehdr)
+bool elf__needs_adjust_symbols(GElf_Ehdr ehdr)
 {
+	if (ehdr.e_machine == EM_AARCH64 ||
+	    ehdr.e_machine == EM_PPC ||
+	    ehdr.e_machine == EM_PPC64)
+		return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL ||
+		       ehdr.e_type == ET_DYN;
+
 	return ehdr.e_type == ET_EXEC || ehdr.e_type == ET_REL;

Patch looks good to me. However:

Quoted 1 line

Can I add your review tag?

Yes:

Quoted 12 lines
Quoted 5 lines

This is only used for checking kernel, so I wonder if we can simply include check for ET_DYN across all architectures? This would only matter if there are architectures building their kernel as ET_DYN that _don't_ want to adjust symbols.

Seems only Arm64 enables the link option '-share' for LDFLAGS_vmlinux; I confirmed with below command:

$ find arch -name 'Makefile' -exec grep -n '\-share' {} + | grep vmlinux
arch/arm64/Makefile:21:LDFLAGS_vmlinux          += -shared -Bsymbolic -z notext -z norelro \
Quoted 8 lines

Also reviewed the output for searching '\-share' for all Makefiles under 'arch' folder, many architectures use it for vdso but only Arm64 enables '-share' for vmlinux linkage. If so, your suggestion is valid and we can simply include check for ET_DYN for all archs (and it's better to add comment for this).

I'd like to wait a bit for anyone has other ideas, and if no objection will send out new patch for this.

Sure, thanks for checking.

- Naveen