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/go: go version <binary> fails with -buildmode=pie Linux ELF binaries #31861
Comments
In a |
It's not clear to me why the |
A little off topic, is there an option to disable packaging module versions in building? |
We can certainly fall back to reading the ELF binaries to find the right place in non-stripped binaries. We just can't assume that in general. |
@dotaheor, no there's no such option. |
But why is the section writable? If it weren't writable, it would be in the text segment, and more likely to be found with the current algorithm. |
@ianlancetaylor, just to try to understand the problem I changed That caused the That made |
I looked in to this some more, but I'm in way over my head. I know that the choice to make |
It sounds like making the section readonly didn't help anyhow. On ELF I think we can look for the section by opening the file using |
I think the problem with non-writable was that it contains pointers to writable variables so the relocations were simpler if they were in the same section. |
For ELF binaries, the "go version" command finds the .go.buildinfo data by searching for the first program-header that's read-write, and hoping the version info is near that. Is there any reason why you don't look for a section header named ".go.buildinfo", instead? |
The above fix gets "go version exefile" working for me on amd64 ubuntu 18.04, with or without external linking, with or without pie, with or without stripping the binary. I think it should work on all ELF platforms; I don't know about other file formats. |
Change https://golang.org/cl/186737 mentions this issue: |
Hello @Infinoid, thank you for mailing a fix! |
Change https://golang.org/cl/188957 mentions this issue: |
The updated test fails on darwin. It looks like the only TryBot that runs without I'll prepare a fix for Mach-O. I don't think we need to fix this for PE binaries, since |
Change https://golang.org/cl/189159 mentions this issue: |
$ go build -o /tmp/go.exe
$ go version /tmp/go.exe
/tmp/go.exe: go version not found
$
It's possible I am using too old a tree but I think this is still broken at head.
The text was updated successfully, but these errors were encountered: