perf symbol: Do not fixup end address of labels
authorNamhyung Kim <namhyung@kernel.org>
Thu, 12 Sep 2024 22:42:08 +0000 (15:42 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 26 Sep 2024 05:37:25 +0000 (22:37 -0700)
commit77b004f4c5c3c90b20ad61c5fa2ba7d494c1dba1
treee0a073bf3edfb407e8ed9bbd14dae3555509bb48
parent235f0da3274690f540aa53fccf77d433e344e4b8
perf symbol: Do not fixup end address of labels

When it loads symbols from an ELF file, it loads label symbols which is
0 size.  Sometimes it has the same address with other symbols and might
shadow the original symbols because it fixes up the size of the symbol.

For example, in my system __do_softirq is shadowed and only accepts the
__softirqentry_text_start instead.  But it should accept __do_softirq.

  $ readelf -sW vmlinux | grep -e __do_softirq -e __softirqentry_text_start
  105089: ffffffff82000000   814 FUNC    GLOBAL DEFAULT    1 __do_softirq
  111954: ffffffff82000000     0 NOTYPE  GLOBAL DEFAULT    1 __softirqentry_text_start

  $ perf annotate --stdio __do_softirq
  Error:
  The perf.data data has no samples!

  $ perf annotate --stdio __softirqentry_text_start | head
   Percent | Source code & Disassembly of vmlinux for cycles (26 samples, percent: local period)
  ---------------------------------------------------------------------------------------------------
           : 0                0xffffffff82000000 <__softirqentry_text_start>:
      0.00 :   ffffffff82000000:        nopl    (%rax,%rax)
     30.77 :   ffffffff82000005:        pushq   %rbp
      3.85 :   ffffffff82000006:        movq    %rsp, %rbp
      0.00 :   ffffffff82000009:        pushq   %r15
      3.85 :   ffffffff8200000b:        pushq   %r14
      3.85 :   ffffffff8200000d:        pushq   %r13
      0.00 :   ffffffff8200000f:        pushq   %r12

We can ignore NOTYPE symbols in the symbols__fixup_end() so that it can
pick the __do_softirq() in choose_best_symbol().  This should be fine
since most symbols have either STT_FUNC or STT_OBJECT.

Link: https://lore.kernel.org/r/20240912224208.3360116-1-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/symbol.c