Commit df8aeaef authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

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: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarIan 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 375a4481
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment