-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: static linking only sometimes works on Alpine Linux #38789
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
Comments
This may be a duplicate of #26492, in that |
@aykevl, can you confirm whether the flags in #26492 (comment) work for your programs? |
Right after posting this issue I discovered that there is a I tested with |
Thanks for confirming. This does seem like the same issue, then. |
Duplicate of #26492 |
The previous build command produces dynamic executables instead of the intended (but not well noted in the Makefile) static executables. This commit includes changes noted in upstream `golang/go` issues which appear to work as intended for others. - refs GH-94 - refs golang/go#38789 - refs golang/go#26492
The previous build command produces dynamic executables instead of the intended (but not well noted in the Makefile) static executables. This commit includes changes noted in upstream `golang/go` issues which appear to work as intended for others. - refs GH-94 - refs golang/go#38789 - refs golang/go#26492
What version of Go are you using (
go version
)?For completeness, also the GCC version:
Does this issue reproduce with the latest release?
Yes, it also reproduces with
go version go1.14.2 linux/amd64
, but with the more confusing error message "relocation target ... not defined for ABI0 (but is defined for ABI0)". Possibly related: #33492, #33028.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run this program:
With the command
CGO_LDFLAGS="-static" go run main.go
, on Alpine Linux.For completeness: Alpine Linux 3.11, with Go built from source (tested both the latest release 1.14.2 and the master branch, see above). I removed Go while testing to make sure I didn't accidentally pick the wrong one.
What did you expect to see?
Run a fully statically linked binary. I know that this can work on Alpine Linux, as I've build a big application this way.
What did you see instead?
I found an interesting workaround, which is to use CGo directly in the main package. Somehow this works with
CGO_LDFLAGS="-static"
:If you wonder why I pass this CGo linker flag to a program that doesn't use CGo, it's because I run many tests in a single command (
go test ./foo ./bar ./baz
). Most use CGo, but some don't - at least not directly.The text was updated successfully, but these errors were encountered: