Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf symbols: Allow for .plt without header

A static executable can have a .plt due to the presence of IFUNCs. In
that case the .plt does not have a header. Check for whether there is a
header by comparing the number of entries to the number of relocation
entries.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20230131131625.6964-7-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
60fbb3e4 b7dbc0be

+15 -1
+15 -1
tools/perf/util/symbol-elf.c
··· 489 489 Elf *elf; 490 490 int nr = 0, err = -1; 491 491 struct rel_info ri = { .is_rela = false }; 492 + bool lazy_plt; 492 493 493 494 elf = ss->elf; 494 495 ehdr = ss->ehdr; ··· 524 523 plt_sym->end = plt_sym->start + shdr_plt.sh_size; 525 524 /* Use .plt.sec offset */ 526 525 plt_offset = plt_sec_shdr.sh_offset; 526 + lazy_plt = false; 527 527 } else { 528 - plt_offset = shdr_plt.sh_offset + plt_header_size; 528 + plt_offset = shdr_plt.sh_offset; 529 + lazy_plt = true; 529 530 } 530 531 531 532 scn_dynsym = ss->dynsym; ··· 579 576 ri.nr_entries = shdr_rel_plt.sh_size / shdr_rel_plt.sh_entsize; 580 577 581 578 ri.is_rela = shdr_rel_plt.sh_type == SHT_RELA; 579 + 580 + if (lazy_plt) { 581 + /* 582 + * Assume a .plt with the same number of entries as the number 583 + * of relocation entries is not lazy and does not have a header. 584 + */ 585 + if (ri.nr_entries * plt_entry_size == shdr_plt.sh_size) 586 + dso__delete_symbol(dso, plt_sym); 587 + else 588 + plt_offset += plt_header_size; 589 + } 582 590 583 591 /* 584 592 * x86 doesn't insert IFUNC relocations in .plt order, so sort to get