-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/ld: -linkmode=external doesn't always use the external linker? #5238
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
Labels
Milestone
Comments
Owner changed to @ianlancetaylor. Status changed to Accepted. |
At least on Fedora, the 2 main reasons I see for linking with the system linker are: build-id support: http://fedoraproject.org/wiki/Releases/FeatureBuildId GNU_HASH support: http://www.sourceware.org/ml/binutils/2006-06/msg00418.html Both of these could be added to 6l (and indeed 6l has partial build-id support), but until then it would be nice if the external linker was an option. Plus, this allows for future system-dependent features to be added to the system linker without needing special support in 6l. |
https://golang.org/cl/8716044 Status changed to Started. |
This issue was closed by revision 6969012. Status changed to Fixed. |
This seems to break building of go with GO_LDFLAGS="-linkmode external". It is now refusing to build runtime/cgo.a, I get many messages during the build "warning: unable to find runtime/cgo.a". When I try to run cgo itself, I get a segfault, which makes some sense because I guess it is missing its own runtime code? |
i think we really shouldn't build non-cgo Go programs with -linkmode external, because it's not free, as it makes the program depending on runtime/cgo it has many consequences. (for one, the Go command will fail to see its pseudo dependency on runtime/cgo, for another, it will lose the static linking feature enjoyed by normal non-cgo programs) I suggest we revert rev 54957b8906eb for Go 1.1 and reconsider this issue after Go 1.1 is released (for one, i think external linking a non-cgo program should still produce a static binary). |
I don't see why we should support building Go itself with GO_LDFLAGS="-linkmode external". That seems designed for failure. This bug has a real use case for using -linkmode external. If you want to use -linkmode external and get a statically linked binary, it's easy enough to use -extldflags -static. The dependency on runtime/cgo is a fair point but I don't think it is a major one for most people. |
currently, building Go code with external linking mode means to force it to use cgo and switch to use pthread to create threads (instead of calling clone(2) directly), so every OS thread incurs a bigger thread stack penalty (as we need to accommodate pthread's requirement). using cgo means every program needs runtime/cgo, but there is circular dependency: runtime/cgo needs cmd/cgo to build, but when building in external linking mode, cmd/cgo needs runtime/cgo. To fix this, we must first build a internal linked copy of cmd/cgo to bootstrap the whole process. This is doable, but not at this stage. |
Aha, I did not realize the extent of the changes. The pthreads requirement seems especially invasive. Thanks for the explanation. So it seems that at this point, a better approach would be to extend the Go linker to support the features needed directly. I'll perhaps file some feature request bugs for tracking this separately. |
Yes, the Go binaries should have a build-id in them on Fedora. This helps because Fedora extracts the debug symbols during build and packages them separately. The build-id allows the system to correctly find (and download) the correct debuginfo package for any given binary. http://sourceware.org/binutils/docs-2.23.1/ld/Options.html#index-g_t_002d_002dbuild_002did-271 Go's linker has the build-id support, but does not currently implement the exact sha1 hashing that the system linker does. Actually, perhaps the best way forward is to figure out how to put build-id information into an arbitrary existing binary. This would solve the issue in a general way without anything special from Go. |
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: