[PATCH v2 02/10] perf symbol: Reduce scope of arch__sym_update

From: Ian Rogers
Date: Mon Dec 01 2025 - 15:55:52 EST


Rather than being a weak arch function, use the e_machine from the ELF
header to determine whether to update or not. This should make the
function work cross-platform, it also reduces the function's scope.

Note, the previous PPC code would compile both for 32 and 64-bit and
when _CALL_ELF==2. Similar testing could be done using the ELF file's
e_machine for PPC32 and e_flags for not EF_PPC_EMB. It can also be
done on the symbol for a non-zero st_other. Given we're just copying
the value, which would otherwise be 0, there's no need to introduce a
st_other != 0 test. The value is only used in arch__fix_tev_from_maps
on PowerPC in the PPC64_LOCAL_ENTRY_OFFSET macro, where 64-bit is
assumed.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/arch/powerpc/util/sym-handling.c | 7 -------
tools/perf/util/symbol-elf.c | 9 ++++++---
tools/perf/util/symbol.h | 4 ----
3 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/tools/perf/arch/powerpc/util/sym-handling.c b/tools/perf/arch/powerpc/util/sym-handling.c
index 947bfad7aa59..afefa9bd0c93 100644
--- a/tools/perf/arch/powerpc/util/sym-handling.c
+++ b/tools/perf/arch/powerpc/util/sym-handling.c
@@ -66,13 +66,6 @@ const char *arch__normalize_symbol_name(const char *name)

#if defined(_CALL_ELF) && _CALL_ELF == 2

-#ifdef HAVE_LIBELF_SUPPORT
-void arch__sym_update(struct symbol *s, GElf_Sym *sym)
-{
- s->arch_sym = sym->st_other;
-}
-#endif
-
#define PPC64LE_LEP_OFFSET 8

void arch__fix_tev_from_maps(struct perf_probe_event *pev,
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index f661ea6c8ac2..99b1e060acf5 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -1338,8 +1338,11 @@ static u64 ref_reloc(struct kmap *kmap)
return 0;
}

-void __weak arch__sym_update(struct symbol *s __maybe_unused,
- GElf_Sym *sym __maybe_unused) { }
+static void arch__sym_update(int e_machine, const GElf_Sym *sym, struct symbol *s)
+{
+ if (e_machine == EM_PPC64)
+ s->arch_sym = sym->st_other;
+}

static int dso__process_kernel_symbol(struct dso *dso, struct map *map,
GElf_Sym *sym, GElf_Shdr *shdr,
@@ -1718,7 +1721,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
if (!f)
goto out_elf_end;

- arch__sym_update(f, &sym);
+ arch__sym_update(ehdr.e_machine, &sym, f);

__symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso));
nr++;
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 9aa0016937b7..f12bb3d0e08b 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -216,10 +216,6 @@ int setup_list(struct strlist **list, const char *list_str,
int setup_intlist(struct intlist **list, const char *list_str,
const char *list_name);

-#ifdef HAVE_LIBELF_SUPPORT
-void arch__sym_update(struct symbol *s, GElf_Sym *sym);
-#endif
-
const char *arch__normalize_symbol_name(const char *name);
#define SYMBOL_A 0
#define SYMBOL_B 1
--
2.52.0.158.g65b55ccf14-goog