-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debug/elf: does not properly apply DWARF RELA relocations #40879
Comments
I'm a bit surprised that a vmlinux image has any relocations. Why isn't the image fully linked? |
So I'm a bit out of my depth here - could that be related to CONFIG_RELOCATABLE ? (EDIT: removed non-sensical info) -- Otherwise, the previous iteration of the code in
I'm really no ELF/DWARF expert, but I don't understand the rationale behind "we assume that the symbol value is 0" |
Digged into it a bit more - this is due to
so it looks like passing |
Ok, here's a standalone repro case that doesn't depend on a vmlinux image: https://github.com/vikmik/dwarf-relocation-golang-bug This builds 2 binaries, one with You should be able to just run
|
For now I suppose we'll have to fork Thanks! Happy to provide more info if needed |
FWIW, I suspect the reason the kernel is not fully linked is related to KASLR |
…cations commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. commit df855da added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This commit removes that assumption, and adds support for relocations relative to sections that have non-zero addresses. Typically, sections that are part of a LOAD program segment are such sections. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. This addresses golang#40879, causing relocations for .debug_ranges to be incorrectly applied.
…cations commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. commit df855da added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This commit removes that assumption, and adds support for relocations relative to sections that have non-zero addresses. Typically, sections that are part of a LOAD program segment are such sections. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. This fixes golang#40879, as relocations for .debug_ranges were incorrectly applied due to the above, ignoring the base section address.
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. commit df855da added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section. Typically, sections that are part of a LOAD program segment are such sections. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. This fixes golang#40879, as relocations for .debug_ranges were incorrectly applied due to the above, ignoring the base section address.
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. commit df855da added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section. Typically, sections that are part of a LOAD program segment are such sections. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879 : as relocations for .debug_ranges were incorrectly applied due to the above, ignoring the base section address.
Change https://golang.org/cl/250559 mentions this issue: |
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. commit df855da added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879 : as relocations for .debug_ranges were incorrectly applied due to the above, ignoring the base section address.
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. commit df855da added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879 : as relocations for .debug_ranges were incorrectly applied due to the above, ignoring the base section address.
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. CL 195679 added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section with a non-zero address. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. CL 195679 added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section with a non-zero address. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. CL 195679 added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section with a non-zero address. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. CL 195679 added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section with a non-zero address. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879
…resses commit 72ec930 added basic support for relocations, but assumed that the symbol value would be 0, likely because .debug_info always has address == 0 in the ELF section headers. CL 195679 added further support for relocations, but explicitly encoded the original assumption that section addresses would be 0. This change removes that assumption: all relocations will now be properly computed based on the target symbol value even when that symbol is a section with a non-zero address. Typically, sections that are part of a LOAD program segment have non-zero addresses. For example, .debug_ranges relocations could be relative to .text, which usually has an address > 0. Fixes golang#40879
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
EDIT: I've since added a standalone repro case here:
>>>>>>> #40879 (comment) <<<<<<<
I'm trying to get the PC ranges from the Linux kernel DWARF information:
1) Get the debug version of any mainstream Linux Kernel image, uncompressed (disclaimer: it's big!)
2) Get the DIE offset for a compilation unit (here I'm using
./init/main.c
)3) Try to use the
debug/elf
anddebug/dwarf
libraries to print the PC ranges for this CU:What did you expect to see?
One can use
llvm-dwarfdump
to show the correct PC ranges for this DIE:What did you see instead?
The displayed ranges seem to be completely off:
What seems to be the problem?
There seems to be a problem with the way relocations are applied to the PC ranges.
Here are the relevant relocations for this DIE - looked up with
readelf -r
. The offset0x000023e0
is shown above in theDW_AT_ranges
attribute.As we can see, these relocations are relative to the
.text
and.init.text
sections. If we do the math, addingAddend
toSym.Value
, the result is exactly the output fromllvm-dwarfdump
above.However, the Go program behaves differently. After looking into it, the culprit seems to be the following, in
debug/elf/file.go
:Not sure if I'm reading this correctly, but the first
if
statement seems to assume that relocations relative to sections are either absolute relocations, or that the section addresses are always 0. But this is not the case here.After removing this offending
if
statement, the output of the above program is correct again and matches thellvm-dwarfdump
output:The text was updated successfully, but these errors were encountered: