Skip to content
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: linker gives misleading advice on new -ldflags option when option contains spaces #12338

Closed
ae6rt opened this issue Aug 26, 2015 · 4 comments

Comments

Projects
None yet
5 participants
@ae6rt
Copy link

commented Aug 26, 2015

I am migrating from Go 1.4 to Go 1.5. When I build my app, the compiler emits a warning that my -ldflags syntax is likely to be deprecated, and offers a misleading suggestion to correct the warning. My use case is a -X -ldflags value that contains spaces.

$ go build -ldflags "-X main.buildInfo 'Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64'" -o stashkins-darwin-amd64
# github.com/xoom/stashkins
link: warning: option -X main.buildInfo Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64 may not work in future releases; use -X main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64

If I take a variant of the warning advice, I get

$ go build -ldflags -X main.buildInfo='Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64' -o stashkins-darwin-amd64
can't load package: package main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64: cannot find package "main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64" in any of:
    /usr/local/go/src/main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64 (from $GOROOT)
    /Users/mpetrovic/Projects/go/src/main.buildInfo=Version: 2.9, commitID: 4d203fa, build date: Tue Aug 25 19:54:19 PDT 2015, SDK: go version go1.5 darwin/amd64 (from $GOPATH)
can't load package: package -o: cannot find package "-o" in any of:
    /usr/local/go/src/-o (from $GOROOT)
    /Users/mpetrovic/Projects/go/src/-o (from $GOPATH)
can't load package: package stashkins-darwin-amd64: cannot find package "stashkins-darwin-amd64" in any of:
    /usr/local/go/src/stashkins-darwin-amd64 (from $GOROOT)
    /Users/mpetrovic/Projects/go/src/stashkins-darwin-amd64 (from $GOPATH)

Fiddling around with the quotes, I find this invocation works, which the warning did not help me arrive at:

$ go build -ldflags '-X "main.buildInfo=Version: 2.9, commitID: a03e9a7, build date: Tue Aug 25 20:51:38 PDT 2015, SDK: go version go1.5 darwin/amd64"' -o stashkins-darwin-amd64

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 26, 2015

@ianlancetaylor ianlancetaylor changed the title Compiler gives misleading advice on new -ldflags option when option contains spaces cmd/link: Linker gives misleading advice on new -ldflags option when option contains spaces Aug 26, 2015

@schleppy

This comment has been minimized.

Copy link

commented Aug 26, 2015

@ae6rt Thanks for figuring out the proper quoting. Having warnings of each flag for all 30 go binaries being built on our CI box was a bit verbose.

@ae6rt

This comment has been minimized.

Copy link
Author

commented Aug 26, 2015

Thanks to Ian Taylor for responding to a user on go-nuts list. That's where I found the solution, and wanted to capture it here for a fix for posterity.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Nov 5, 2015

It's not possible to guess what quoting you need. The linker doesn't know. We could make the message less specific by saying

-X <name> <value> may not work in future releases; use -X <name>=<value>

but that's much less helpful. At least with the specifics you can try to grep for the name or value to find where it came from.

@rsc rsc changed the title cmd/link: Linker gives misleading advice on new -ldflags option when option contains spaces cmd/link: linker gives misleading advice on new -ldflags option when option contains spaces Nov 5, 2015

@rsc rsc modified the milestones: Go1.7, Go1.6 Dec 5, 2015

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 5, 2015

The quoting issue makes changing the error difficult.

I propose we do nothing about this for Go 1.6 and then remove the old format entirely in Go 1.7. Then the warning will be gone too.

@rsc rsc closed this Dec 5, 2015

@golang golang locked and limited conversation to collaborators Dec 14, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.