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/link: building static pie binaries using gcc -static-pie #41944
Comments
When I build a simple C program with
That seems consistent with what I get using |
I did not try the -static-pie on a simple c program, my bad. |
In general we don't use the issue tracker for questions. See https://golang.org/wiki/Questions. I'm not sure what you mean by static PIE if that is not the same as what GCC produces with the |
I already tried stack overflow and feel like I've exhausted other avenues of trying to figure out the feasibility of this. The reason I decided to bring this here was that I found that this is actually possible with rust and musl. |
Hello... author of the the You already figured it out! $ go build -ldflags '-linkmode external -s -w -extldflags "--static-pie"' -buildmode=pie -tags 'osusergo,netgo,static_build' -o test main.go The $ readelf -l test
[…]
DYNAMIC 0x000000000028bd18 0x000000000028cd18 0x000000000028cd18
[…] and without the and it runs correctly:
So, I don't see a problem here. |
I don't know what went wrong on my side but you are right, I did solve this! I think I was stuck on getting a statically linked binary from the 'file' output. What I was really trying to accomplish was to have a PIE binary that could execute inside a scratch container. After trying again a binary using this build command it does run in a scratch container!
edit: Figured out the issue, I was using other conflicting gcc flags |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
I tried also to use buildmode=exe but this gave me a relocation warning:
Is there any way to create a static pie binary? If not, is there any plan to support this in go?
The text was updated successfully, but these errors were encountered: