summaryrefslogtreecommitdiff
path: root/tools/perf/util/symbol-elf.c
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2023-01-20 15:34:48 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2023-01-23 00:10:03 +0300
commitc2d066c090c9fec5de99ae051e97e0f448cbc229 (patch)
tree4ad4e9db4a1b7c97cddb0f731fab2a6412f9eabc /tools/perf/util/symbol-elf.c
parent1b69346e7a0bd18a9c3b00bdd6219d4d8ad73466 (diff)
downloadlinux-c2d066c090c9fec5de99ae051e97e0f448cbc229.tar.xz
perf symbols: Factor out get_plt_sizes()
Factor out get_plt_sizes() to make the code more readable and further changes to dso__synthesize_plt_symbols() easier to follow. 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-3-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, 28 insertions, 26 deletions
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index 96767d1b3f1c..4605680a22a3 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -323,6 +323,33 @@ static char *demangle_sym(struct dso *dso, int kmodule, const char *elf_name)
return demangled;
}
+static void get_plt_sizes(GElf_Ehdr *ehdr, GElf_Shdr *shdr_plt,
+ u64 *plt_header_size, u64 *plt_entry_size)
+{
+ switch (ehdr->e_machine) {
+ case EM_ARM:
+ *plt_header_size = 20;
+ *plt_entry_size = 12;
+ return;
+ case EM_AARCH64:
+ *plt_header_size = 32;
+ *plt_entry_size = 16;
+ return;
+ case EM_SPARC:
+ *plt_header_size = 48;
+ *plt_entry_size = 12;
+ return;
+ case EM_SPARCV9:
+ *plt_header_size = 128;
+ *plt_entry_size = 32;
+ return;
+ default: /* FIXME: s390/alpha/mips/parisc/poperpc/sh/xtensa need to be checked */
+ *plt_header_size = shdr_plt->sh_entsize;
+ *plt_entry_size = shdr_plt->sh_entsize;
+ return;
+ }
+}
+
#define elf_section__for_each_rel(reldata, pos, pos_mem, idx, nr_entries) \
for (idx = 0, pos = gelf_getrel(reldata, 0, &pos_mem); \
idx < nr_entries; \
@@ -411,32 +438,7 @@ int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss)
nr_rel_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize;
plt_offset = shdr_plt.sh_offset;
- switch (ehdr.e_machine) {
- case EM_ARM:
- plt_header_size = 20;
- plt_entry_size = 12;
- break;
-
- case EM_AARCH64:
- plt_header_size = 32;
- plt_entry_size = 16;
- break;
-
- case EM_SPARC:
- plt_header_size = 48;
- plt_entry_size = 12;
- break;
-
- case EM_SPARCV9:
- plt_header_size = 128;
- plt_entry_size = 32;
- break;
-
- default: /* FIXME: s390/alpha/mips/parisc/poperpc/sh/xtensa need to be checked */
- plt_header_size = shdr_plt.sh_entsize;
- plt_entry_size = shdr_plt.sh_entsize;
- break;
- }
+ get_plt_sizes(&ehdr, &shdr_plt, &plt_header_size, &plt_entry_size);
plt_offset += plt_header_size;
if (shdr_rel_plt.sh_type == SHT_RELA) {