-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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/go: cannot pass multiple -ldflags via GOFLAGS #51194
Labels
Comments
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
I set
GOFLAGS="-ldflags='-s -w'"
to automatically exclude the symbol table on all binaries we compile.What did you expect to see?
I expected it to work the same as if I passed
-ldflags='-s -w'
.What did you see instead?
This is because the compiler naively just splits
GOFLAGS
on spaces without considering quotes. The docs support this unfortunate behavior.There is no workaround for this, other than to not use
GOFLAGS
for this purpose. PassingGOFLAGS="-ldflags=-s -ldflags=-w"
as was previously suggested by the documention does not work, becuase only the last flag will be applied, as per the documentation for-ldflags
.This issue was previously mentioned in #29053 but was not truly fixed.
Either the
GOFLAGS
parsing logic should be amended to account for quotes instead of just splitting on spaces, or another env var (perhpasGO_LDFLAGS
to align with what make.bash offers) should be added.The text was updated successfully, but these errors were encountered: