summaryrefslogtreecommitdiff
path: root/tools/perf/util/symbol-elf.c
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2023-01-20 14:34:56 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-01-22 18:10:50 -0300
commitdf8aeaefea026a25f443b8982186127291c6f149 (patch)
treeb4696c268031875b22c6499a79f0b089b9c80191 /tools/perf/util/symbol-elf.c
parent375a44818429a4df3fc18a0ac0ecfad9953f1ac8 (diff)
downloadlwn-df8aeaefea026a25f443b8982186127291c6f149.tar.gz
lwn-df8aeaefea026a25f443b8982186127291c6f149.zip
perf symbols: Check SHT_RELA and SHT_REL type earlier
Make the code more readable by checking for SHT_RELA and SHT_REL type earlier. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lore.kernel.org/r/20230120123456.12449-11-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/symbol-elf.c')
-rw-r--r--tools/perf/util/symbol-elf.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index e274f646ac32..aa62735aea7b 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -434,6 +434,10 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss)
return 0;
}
+ if (shdr_rel_plt.sh_type != SHT_RELA &&
+ shdr_rel_plt.sh_type != SHT_REL)
+ return 0;
+
if (shdr_rel_plt.sh_link != dynsym_idx)
goto out_elf_end;
@@ -466,34 +470,30 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss)
ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA;
- if (shdr_rel_plt.sh_type == SHT_RELA ||
- shdr_rel_plt.sh_type == SHT_REL) {
- for (idx = 0; idx < nr_rel_entries; idx++) {
- const char *elf_name = NULL;
- char *demangled = NULL;
-
- gelf_getsym(syms, get_rel_symidx(&ri, idx), &sym);
-
- elf_name = elf_sym__name(&sym, symstrs);
- demangled = demangle_sym(dso, 0, elf_name);
- if (demangled != NULL)
- elf_name = demangled;
- if (*elf_name)
- snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name);
- else
- snprintf(sympltname, sizeof(sympltname),
- "offset_%#" PRIx64 "@plt", plt_offset);
- free(demangled);
-
- f = symbol__new(plt_offset, plt_entry_size,
- STB_GLOBAL, STT_FUNC, sympltname);
- if (!f)
- goto out_elf_end;
+ for (idx = 0; idx < nr_rel_entries; idx++) {
+ const char *elf_name = NULL;
+ char *demangled = NULL;
- plt_offset += plt_entry_size;
- symbols__insert(&dso->symbols, f);
- ++nr;
- }
+ gelf_getsym(syms, get_rel_symidx(&ri, idx), &sym);
+
+ elf_name = elf_sym__name(&sym, symstrs);
+ demangled = demangle_sym(dso, 0, elf_name);
+ if (demangled)
+ elf_name = demangled;
+ if (*elf_name)
+ snprintf(sympltname, sizeof(sympltname), "%s@plt", elf_name);
+ else
+ snprintf(sympltname, sizeof(sympltname),
+ "offset_%#" PRIx64 "@plt", plt_offset);
+ free(demangled);
+
+ f = symbol__new(plt_offset, plt_entry_size, STB_GLOBAL, STT_FUNC, sympltname);
+ if (!f)
+ goto out_elf_end;
+
+ plt_offset += plt_entry_size;
+ symbols__insert(&dso->symbols, f);
+ ++nr;
}
err = 0;