-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: can't build a static binary since Go 1.15 #40711
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
From the Go 1.15 release notes:
So your
to force external linking, like this:
it should produce a static binary. Does this work? |
Yes, thanks, any chance to have this explained in the release note? |
* `-linkmode external` is required since Go 1.15 for static builds: golang/go#40711 * Clarify the meaning of "loading plugins" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Thank you for confirming. I've opened #40719 to track a possible release notes addition. |
* `-linkmode external` is required since Go 1.15 for static builds: golang/go#40711 * Clarify the meaning of "loading plugins" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp> (cherry picked from commit 43cbdf8) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
* `-linkmode external` is required since Go 1.15 for static builds: golang/go#40711 * Clarify the meaning of "loading plugins" Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Hi, I am trying to obtain a simple helloworld elf from go code that is both statically linked and is position independent. Untill now I managed to get one or the other but not both. If I use something like this: If I use something like this: What is the correct way to do this? I am using version 1.15.6 linux/amd64 Update: |
@danield20 We prefer to keep our issues focused on a single problem. Please don't raise different problems on an existing issue. We also don't use our issue tracker for questions. Please see https://golang.org/wiki/Questions. Thanks. |
When PIE mode is enabled, CGO_ENABLED=0 does not give a static link binary, extra ld flags are required golang/go#40711
Go compiler has switched to internal linking mode when building in PIE mode since version 1.15 (https://golang.org/doc/go1.15#linker). This had a side effect of not able to compile a purely statically linked PIE binary with CGO disabled, see: golang/go#40711 As a result, the agent binaries build with PIE mode will fail to run in a container that is built from SCRATCH. In this CR we allow the users to override the build mode with environment variable `CWAGENT_BUILD_MODE`, allowing a non-PIE binary to be built to be used in a container without libc. For example, a non-pie agent can be built with: ``` CWAGENT_BUILD_MODE=default make ```
Go compiler has switched to internal linking mode when building in PIE mode since version 1.15 (https://golang.org/doc/go1.15#linker). This had a side effect of not able to compile a purely statically linked PIE binary with CGO disabled, see: golang/go#40711 As a result, the agent binaries build with PIE mode will fail to run in a container that is built from SCRATCH. In this CR we allow the users to override the build mode with environment variable `CWAGENT_BUILD_MODE`, allowing a non-PIE binary to be built to be used in a container without libc. For example, a non-pie agent can be built with: ``` CWAGENT_BUILD_MODE=default make ```
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes (Go 1.15)
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Can't build a static binary since Go 1.15.
Dockerfile:
✅ Go 1.14.7 produces a static binary as expected
❌ Go 1.15 produces a dynamic binary
What did you expect to see?
Go 1.15 should produce a static binary
What did you see instead?
Go 1.15 produced a dynamic binary
The text was updated successfully, but these errors were encountered: