perf tools: don't adjust symbols in vDSO
PATCH 1/1 perf tools: don't adjust symbols in vDSO
Commit 922d0e4d9f04 ("perf tools: Adjust symbols in VDSO") changed the ELF symbol parsing so that the vDSO is treated the same as ET_EXEC and ET_REL binaries despite being an ET_DYN.
This causes objdump, which expects relative addresses, not to produce any output in conjunction with perf annotate, which cheerfully passes absolute addresses when trying to disassemble vDSO functions.
This patch avoids marking the vDSO as requiring adjustment of symbol addresses, allowing the relative program counter to be used instead.
---
Not sure why I've just started seeing this, but it appears to affect both x86 and arm64. Also, if I revert the patch above then the issue it supposedly fixed doesn't resurface. Maybe it was just masking another bug that has since been addressed?
tools/perf/util/symbol-elf.c | 1 - 1 file changed, 1 deletion(-)
tools/perf/util/symbol-elf.c +0 -1
@@ -706,7 +706,6 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,GElf_Shdr shdr; ss->adjust_symbols = (ehdr.e_type ==ET_EXEC || ehdr.e_type ==ET_REL || -dso__is_vdso (dso) ||elf_section_by_name (elf, &ehdr, &shdr,".gnu.prelink_undo" ,NULL ) !=NULL );
Signature · 1 line
2.1.4
Adrian Hunter
reviewerQuoted 16 lines · Will Deacon
Commit
922d0e4d9f04("perf tools: Adjust symbols in VDSO") changed the ELF symbol parsing so that the vDSO is treated the same asET_EXECandET_RELbinaries despite being anET_DYN.This causes objdump, which expects relative addresses, not to produce any output in conjunction with perf annotate, which cheerfully passes absolute addresses when trying to disassemble vDSO functions.
This patch avoids marking the vDSO as requiring adjustment of symbol addresses, allowing the relative program counter to be used instead.
Cc Vladimir Nikulichev <[email protected]>Cc Adrian Hunter <[email protected]>Cc Namhyung Kim <[email protected]>Reported-by Kristina Martsenko <[email protected]>Signed-off-by Will Deacon <[email protected]>
Quoted 6 lines
---
Not sure why I've just started seeing this, but it appears to affect both x86 and arm64. Also, if I revert the patch above then the issue it supposedly fixed doesn't resurface. Maybe it was just masking another bug that has since been addressed?
No the problem still appears on older kernels.
Probably could look at the vdso section/program headers to decide if it needs adjustment or not.
Quoted 17 lines
tools/perf/util/symbol-elf.c | 1 - 1 file changed, 1 deletion(-)tools/perf/util/symbol-elf.c +0
-1@@ -706,7 +706,6 @@ int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,GElf_Shdr shdr; ss->adjust_symbols = (ehdr.e_type ==ET_EXEC || ehdr.e_type ==ET_REL || -dso__is_vdso (dso) ||elf_section_by_name (elf, &ehdr, &shdr,".gnu.prelink_undo" ,NULL ) !=NULL );
Quoted 19 lines · Adrian Hunter
Quoted 18 lines · Will Deacon
Commit
922d0e4d9f04("perf tools: Adjust symbols in VDSO") changed the ELF symbol parsing so that the vDSO is treated the same asET_EXECandET_RELbinaries despite being anET_DYN.This causes objdump, which expects relative addresses, not to produce any output in conjunction with perf annotate, which cheerfully passes absolute addresses when trying to disassemble vDSO functions.
This patch avoids marking the vDSO as requiring adjustment of symbol addresses, allowing the relative program counter to be used instead.
Cc Vladimir Nikulichev <[email protected]>Cc Adrian Hunter <[email protected]>Cc Namhyung Kim <[email protected]>Reported-by Kristina Martsenko <[email protected]>Signed-off-by Will Deacon <[email protected]>---
Quoted 6 lines
Quoted 4 lines
Not sure why I've just started seeing this, but it appears to affect both x86 and arm64. Also, if I revert the patch above then the issue it supposedly fixed doesn't resurface. Maybe it was just masking another bug that has since been addressed?
No the problem still appears on older kernels.
Can you be more specific, please? I tried with a 3.16 kernel (that I happen to be running on my box) but perf doesn't even detect the vdso there, regardless of this patch.
Quoted 2 lines
Probably could look at the vdso section/program headers to decide if it needs adjustment or not.
Did the x86 kernel change in this regard? Why isn't the vDSO always ET_DYN?
Will
Adrian Hunter
reviewerQuoted 20 lines · Will Deacon
Quoted 19 lines · Adrian Hunter
Quoted 18 lines · Will Deacon
Commit
922d0e4d9f04("perf tools: Adjust symbols in VDSO") changed the ELF symbol parsing so that the vDSO is treated the same asET_EXECandET_RELbinaries despite being anET_DYN.This causes objdump, which expects relative addresses, not to produce any output in conjunction with perf annotate, which cheerfully passes absolute addresses when trying to disassemble vDSO functions.
This patch avoids marking the vDSO as requiring adjustment of symbol addresses, allowing the relative program counter to be used instead.
Cc Vladimir Nikulichev <[email protected]>Cc Adrian Hunter <[email protected]>Cc Namhyung Kim <[email protected]>Reported-by Kristina Martsenko <[email protected]>Signed-off-by Will Deacon <[email protected]>---
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Not sure why I've just started seeing this, but it appears to affect both x86 and arm64. Also, if I revert the patch above then the issue it supposedly fixed doesn't resurface. Maybe it was just masking another bug that has since been addressed?
No the problem still appears on older kernels.
Can you be more specific, please? I tried with a 3.16 kernel (that I happen
3.13 Ubuntu kernel
Quoted 2 lines
to be running on my box) but perf doesn't even detect the vdso there, regardless of this patch.
Don't know what you mean about not detecting vdso
Quoted 5 lines
Quoted 3 lines
Probably could look at the vdso section/program headers to decide if it needs adjustment or not.
Did the x86 kernel change in this regard? Why isn't the vDSO always
ET_DYN?
I guess, but it is ET_DYN
(CC'ing Andy, since the removal of VDSO_PRELINK is user-visible here)
Hi Adrian,
Thanks for your helpful responses.
Quoted 26 lines · Adrian Hunter
Quoted 25 lines · Will Deacon
Quoted 24 lines · Adrian Hunter
Quoted 22 lines · Will Deacon
Commit
922d0e4d9f04("perf tools: Adjust symbols in VDSO") changed the ELF symbol parsing so that the vDSO is treated the same asET_EXECandET_RELbinaries despite being anET_DYN.This causes objdump, which expects relative addresses, not to produce any output in conjunction with perf annotate, which cheerfully passes absolute addresses when trying to disassemble vDSO functions.
This patch avoids marking the vDSO as requiring adjustment of symbol addresses, allowing the relative program counter to be used instead.
Cc Vladimir Nikulichev <[email protected]>Cc Adrian Hunter <[email protected]>Cc Namhyung Kim <[email protected]>Reported-by Kristina Martsenko <[email protected]>Signed-off-by Will Deacon <[email protected]>---
Not sure why I've just started seeing this, but it appears to affect both x86 and arm64. Also, if I revert the patch above then the issue it supposedly fixed doesn't resurface. Maybe it was just masking another bug that has since been addressed?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
No the problem still appears on older kernels.
Can you be more specific, please? I tried with a 3.16 kernel (that I happen
3.13 Ubuntu kernel
So I just tried that on a core2 box and it's broken even without my patch:
# ./perf record -e cycles:u ./vdso-test
[...]
# ./perf report
[...]
# Overhead Command Shared Object Symbol
# ........ ......... ................. ........................
#
99.70% vdso-test [vdso] [.] __vdso_clock_gettime
[...]
# ./perf annotate -v
[...]
annotating [0x2178d10] [vdso] : [0x258bbd0] __vdso_clock_gettime
Executing: objdump --start-address=0x00007fff5eb9a870 --stop-address=0x00007fff5eb9ab4c -l -d --no-show-raw -S -C /home/nanook/.debug/.build-id/51/54a08e7153b1deecc09259d1e970f9b67e1664
[...]
Percent | Source code & Disassembly of [vdso] for cycles:u
----------------------------------------------------------------
870: 4
876: 2
87f: 2
920: 2
93a: 2
967: 2
985: 1
988: 3
9a2: 2
9bb: 1
9c8: 6
9d6: 2
9d9: 4
a9d: 4
ab4: 2
ab8: 13
ac0: 1
ac7: 3763
ac9: 5
h->sum: 3821
:
:
[...]So there's no disassembly output for the vdso using a perf tool build from a vanilla 4.1 kernel.
If I run readelf on the generated ELF object, I see:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: Advanced Micro Devices X86-64 Version: 0x1 Entry point address: 0xffffffffff700700 Start of program headers: 64 (bytes into file) Start of section headers: 3600 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 4 Size of section headers: 64 (bytes) Number of section headers: 18
Section header string table index: 17
Text section:
[15] .text PROGBITS ffffffffff700700 00000700
000000000000062d 0000000000000000 AX 0 0 16
So somehow the Image claims to be loaded at 0xffffffffff700000, whilst perf's map is offset by 0x00007fff5eb9a000. This seems to be down to the #define VDSO_PRELINK 0xffffffffff700000 in older kernels, but your patch doesn't take that fixed address into account, so I don't see how it's ever the right thing to do.
At least with my patch applied, recent kernels work. Without it, vdso disassembly appears to be broken on all kernels for all architectures.
Quoted 4 lines
Quoted 2 lines
to be running on my box) but perf doesn't even detect the vdso there, regardless of this patch.
Don't know what you mean about not detecting vdso
It just prints something like [perf.data.XXXX] instead of [vdso] -- probably a separate bug.
Will
Quoted 1 line · Will Deacon
(CC'ing Andy, since the removal of
VDSO_PRELINKis user-visible here)
What arch is this? I removed VDSO_PRELINK entirely from x86 a while back, and now x86's vdso has a base address of 0 before relocations, and everything works just fine.
(Except one ancient glibc, which fails if the vdso is relocated at all. We no longer support that version of glibc unless you turn off the vdso entirely.)
--Andy
Quoted 6 lines · Andy Lutomirski
Quoted 1 line · Will Deacon
(CC'ing Andy, since the removal of
VDSO_PRELINKis user-visible here)What arch is this? I removed
VDSO_PRELINKentirely from x86 a while back, and now x86's vdso has a base address of 0 before relocations, and everything works just fine.
I think this is only x86, since it's the removal of VDSO_PRELINK that has changed things.
Quoted 3 lines
(Except one ancient glibc, which fails if the vdso is relocated at all. We no longer support that version of glibc unless you turn off the vdso entirely.)
The problem is that perf expects to objdump portions of the vdso using --start-address=foo and --stop-address=bar, but these addresses have changed from being offset by VDSO_PRELINK to 0x0.
Thankfully, it looks like perf tool was always broken in this regard, but I figured you might like to be aware of the issue. I guess perf just needs to add on the load address of the vdso .text section to its relative addresses before passing them to objdump.
Will
Quoted 15 lines · Will Deacon
Quoted 6 lines · Andy Lutomirski
Quoted 1 line · Will Deacon
(CC'ing Andy, since the removal of
VDSO_PRELINKis user-visible here)What arch is this? I removed
VDSO_PRELINKentirely from x86 a while back, and now x86's vdso has a base address of 0 before relocations, and everything works just fine.I think this is only x86, since it's the removal of
VDSO_PRELINKthat has changed things.Quoted 3 lines
(Except one ancient glibc, which fails if the vdso is relocated at all. We no longer support that version of glibc unless you turn off the vdso entirely.)
Quoted 9 lines
The problem is that perf expects to objdump portions of the vdso using --start-address=foo and --stop-address=bar, but these addresses have changed from being offset by
VDSO_PRELINKto0x0.Thankfully, it looks like perf tool was always broken in this regard, but I figured you might like to be aware of the issue. I guess perf just needs to add on the load address of the vdso .text section to its relative addresses before passing them to objdump.
Given that we've randomized the vdso load address on x86 for years, I don't see how perf ever worked here. There was a brief period during which we actually loaded the vdso at the address VDSO_PRELINK, but that's long gone.
Is there a patch I should be looking at?
--Andy
Quoted 26 lines · Andy Lutomirski
Quoted 15 lines · Will Deacon
Quoted 6 lines · Andy Lutomirski
Quoted 1 line · Will Deacon
(CC'ing Andy, since the removal of
VDSO_PRELINKis user-visible here)What arch is this? I removed
VDSO_PRELINKentirely from x86 a while back, and now x86's vdso has a base address of 0 before relocations, and everything works just fine.I think this is only x86, since it's the removal of
VDSO_PRELINKthat has changed things.Quoted 3 lines
(Except one ancient glibc, which fails if the vdso is relocated at all. We no longer support that version of glibc unless you turn off the vdso entirely.)
Quoted 9 lines
The problem is that perf expects to objdump portions of the vdso using --start-address=foo and --stop-address=bar, but these addresses have changed from being offset by
VDSO_PRELINKto0x0.Thankfully, it looks like perf tool was always broken in this regard, but I figured you might like to be aware of the issue. I guess perf just needs to add on the load address of the vdso .text section to its relative addresses before passing them to objdump.
Quoted 4 lines
Given that we've randomized the vdso load address on x86 for years, I don't see how perf ever worked here. There was a brief period during which we actually loaded the vdso at the address
VDSO_PRELINK, but that's long gone.
The symbol resolution works by applying the vdso symbol offset to the [vdso] vma base, but perf annotate had indeed been broken the whole time.
Quoted 1 line
Is there a patch I should be looking at?
I've cooked something, so I'll send it out now.
Will
Adrian Hunter
reviewerQuoted 36 lines · Will Deacon
(CC'ing Andy, since the removal of
VDSO_PRELINKis user-visible here)Quoted 26 lines · Adrian Hunter
Quoted 25 lines · Will Deacon
Quoted 24 lines · Adrian Hunter
Quoted 22 lines · Will Deacon
Commit
922d0e4d9f04("perf tools: Adjust symbols in VDSO") changed the ELF symbol parsing so that the vDSO is treated the same asET_EXECandET_RELbinaries despite being anET_DYN.This causes objdump, which expects relative addresses, not to produce any output in conjunction with perf annotate, which cheerfully passes absolute addresses when trying to disassemble vDSO functions.
This patch avoids marking the vDSO as requiring adjustment of symbol addresses, allowing the relative program counter to be used instead.
Cc Vladimir Nikulichev <[email protected]>Cc Adrian Hunter <[email protected]>Cc Namhyung Kim <[email protected]>Reported-by Kristina Martsenko <[email protected]>Signed-off-by Will Deacon <[email protected]>---
Not sure why I've just started seeing this, but it appears to affect both x86 and arm64. Also, if I revert the patch above then the issue it supposedly fixed doesn't resurface. Maybe it was just masking another bug that has since been addressed?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
No the problem still appears on older kernels.
Can you be more specific, please? I tried with a 3.16 kernel (that I happen
3.13 Ubuntu kernel
So I just tried that on a core2 box and it's broken even without my patch:
Quoted 8 lines
# ./perf record -e cycles:u ./vdso-test
[...]
# ./perf report
[...]
# Overhead Command Shared Object Symbol
# ........ ......... ................. ........................
#
99.70% vdso-test [vdso] [.] __vdso_clock_gettimeAnnotation is broken but the symbol gets resolved.