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
cmd/link: An incorrect address was generated when using the LD linker #47416
Comments
Could you explain why it must be written to the binary? If I understand your words correctly, it will be patched at run time by the dynamic linker anyway, so the program runs correctly? Also, I'm don't know what do you mean by 0x000db902 is invalid. It looks like a valid address (pre-dynamic relocation) to me. |
As you use Also, as you mentioned, when using external linking the final bytes are actually written out by the external linker, not the Go linker. I'm not sure we have control with that. (Even we have, I'm not sure this is necessary, as the dynamic linker will overwrite it anyway.) |
Yes, you're right, I didn't consider this option So, do you think this is a bug of ld linker? Is it possible that it is related to the mechanism of go calling external linker? Thanks. |
I don't think this is a bug. The generated program executes correctly (if I understand what you said correctly). I think we can close this. Feel free to reopen if you disagree. Thanks. |
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?
main.go
Build command:
go build -a -buildmode=pie -ldflags='-linkmode=external -extld=gcc -extldflags "-fPIE -pie -Wl,--emit-relocs"'
What did you expect to see?
I run
objdump -r -D main
, get this:I run
readelf -r main
, get this:The first 8 bytes of “runtime.buildVersion” object is the pointer to the string with golang version name. The pointers address (0x000db902) is invalid and fixed at runtime by the relocation on that address (0x190a00).
The address 0xdb0e1 is valid, pointing to the string and works fine at runtime.The same address (0xdb0e1) must be written in the runtime.buildVersion instead of garbage one.
What did you see instead?
The pointers address (0x000db902) is invalid, different from 0xdb0e1.
The text was updated successfully, but these errors were encountered: