-
Notifications
You must be signed in to change notification settings - Fork 18k
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: -ldflags pattern matching broken when building from symlinked pwd #24359
Comments
I think that |
I also think this is a regression with 1.10 - wasn't there in 1.9 |
/cc @ianlancetaylor |
It works if you use Perhaps the |
Likely could be fixed by calling |
@ianlancetaylor I have verified your version and it turns out to be a working fix. Should we have a proper test for it in go_test.go? |
Yes, it ought to have a test. |
Change https://golang.org/cl/101256 mentions this issue: |
I wrote on the CL:
I think we should leave the current behavior alone. GOPATH is on its way out anyway. |
It worked in every Go version prior to 1.10. Why break it until GOPATH is out? |
It worked by accident in every prior Go version. I don't feel strongly about this particular issue, but as a general rule we don't want to lock ourselves into behavior that was not documented and that worked by accident. |
It's reasonable to disallow symlinks in the GOPATH itself. But whether the cwd is a symlink or not shouldn't matter. At least that's my expectation as a user (and it's not something I would expect to be specifically documented). |
Build info injected via linker flags, like the Git commit SHA, is dropped on the floor when building from a symlink (e.g., ~/roach -> ~/go/src/cockroachdb/cockroach). This issue was filed upstream (golang/go#24359), but the Go team refused to fix it. Luckily, we can work around it by teaching Make to resolve any symlinks in the CWD. Release note: None
Build info injected via linker flags, like the Git commit SHA, is dropped on the floor when building from a symlink (e.g., ~/roach -> ~/go/src/cockroachdb/cockroach). This issue was filed upstream (golang/go#24359), but the Go team refused to fix it. Luckily, we can work around it by teaching Make to resolve any symlinks in the CWD. Release note (build change): Build metadata, like the commit SHA and build time, is properly injected into the binary when using Go 1.10 and building from a symlink.
25008: Makefile: work around symlink bug in Go toolchain r=knz a=benesch Build info injected via linker flags, like the Git commit SHA, is dropped on the floor when building from a symlink (e.g., ~/roach -> ~/go/src/cockroachdb/cockroach). This issue was filed upstream (golang/go#24359), but the Go team refused to fix it. Luckily, we can work around it by teaching Make to resolve any symlinks in the CWD. Release note (build change): Build metadata, like the commit SHA and build time, is properly injected into the binary when using Go 1.10 and building from a symlink. Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
Build info injected via linker flags, like the Git commit SHA, is dropped on the floor when building from a symlink (e.g., ~/roach -> ~/go/src/cockroachdb/cockroach). This issue was filed upstream (golang/go#24359), but the Go team refused to fix it. Luckily, we can work around it by teaching Make to resolve any symlinks in the CWD. Release note (build change): Build metadata, like the commit SHA and build time, is properly injected into the binary when using Go 1.10 and building from a symlink.
25062: backport-2.0: Makefile: work around symlink bug in Go toolchain r=knz a=benesch Backport 1/1 commits from #25008. /cc @cockroachdb/release --- Build info injected via linker flags, like the Git commit SHA, is dropped on the floor when building from a symlink (e.g., ~/roach -> ~/go/src/cockroachdb/cockroach). This issue was filed upstream (golang/go#24359), but the Go team refused to fix it. Luckily, we can work around it by teaching Make to resolve any symlinks in the CWD. Release note (build change): Build metadata, like the commit SHA and build time, is properly injected into the binary when using Go 1.10 and building from a symlink. Co-authored-by: Nikhil Benesch <nikhil.benesch@gmail.com>
tl;dr: if the PWD of the current shell is a symlink to a dir in $GOPATH, then linking with
-X
does not work.What version of Go are you using (
go version
)?go version go1.10 freebsd/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Check the README here: https://github.com/knz/build-x-bug
In short:
go build -ldflags '-X yourpackage/var=val'
-> this worksgo build
command -> this breaks,-X
does not set the var.What did you expect to see?
-X
with a package path relative to$GOPATH
should work regardless of PWD.What did you see instead?
Whether
-X
works properly or not is dependent on the PWD.Suggested fix.
use
filepath.Abs
on the PWD before trying to make clever comparisons in the linker.The text was updated successfully, but these errors were encountered: