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/ld: corrupted binaries with -linkmode=external #7234
Labels
Milestone
Comments
I've discovered this while doing race-related changes here: https://golang.org/cl/55100044/ It makes cmd/go broken. The strange thing is that currently -race uses external linking via cgo, and everything works... |
The problem is this call in ld/lib.c: // Provided by the code that imports the package. // Since we are simulating the import, we have to provide this string. addstrdata("go.string.\"runtime/cgo\"", "runtime/cgo"); That defines a symbol go.string."runtime/cgo". When the compiler sees the string constant, it defines the same symbol to hold the string. The compiler builds the symbol as a string header followed immediately by the string data, and it builds a relocation that knows that layout: a relocation to the symbol plus the size of the string header (datastring in gobj.c). The linker uses a different layout in addstrdata--it puts the string header in one section and the string data in a different section. But the symbol name go.string."runtime/cgo" is the same in both cases, and it has to be the same or we get other linker confusion. So it fails when using external linking because we get a reference to an offset from the string symbol expecting to find the string data there, but it isn't there. I haven't quite worked out why works when using internal linking. |
This issue was closed by revision 1683dab. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: