-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
build: respect environment LDFLAGS and strip the build path #1994
Conversation
Before:
After, with
|
Thank you! I've pushed some tweaks. @eli-schwartz care to review please? |
I've been trying to think what to do for go 1.9, the problem is that From the release notes:
I think the solution is to do string comparison on the output of |
golang does not natively respect LDFLAGS, but you can pass them on the command line using -ldflags=-extldflags=... This is important for distributions, in order to provide common functionality such as hardening flags. Also strip the prefixed root source directory from the embedded source file paths. This is not important information for the debugger, which should only care about paths relative to $GOPATH, and results in less build environment metadata leaking into the final binary. (This also aids in reproducible builds when using different build directories, see e.g. golang/go#16860)
Go 1.10 release notes: > The go build -asmflags, -gcflags, -gccgoflags, and -ldflags options > now apply by default only to the packages listed directly on the > command line. For example, go build -gcflags=-m mypkg passes the > compiler the -m flag when building mypkg but not its dependencies. The > new, more general form -asmflags=pattern=flags (and similarly for the > others) applies the flags only to the packages matching the pattern. > For example: go install -ldflags=cmd/gofmt=-X=main.version=1.2.3 > cmd/... installs all the commands matching cmd/... but only applies > the -X option to the linker flags for cmd/gofmt. For more details, see > go help build.
Thanks for polishing that up. |
golang does not natively respect LDFLAGS, but you can pass them on the command line using -ldflags=-extldflags=...
This is important for distributions, in order to provide common functionality such as hardening flags.
Also strip the prefixed root source directory from the embedded source file paths. This is not important information for the debugger, which should only care about paths relative to $GOPATH, and results in less build environment metadata leaking into the final binary. (This also aids in reproducible builds when using different build directories, see e.g. golang/go#16860)