-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: invalid -ldflags is silently ignored #43177
Comments
From what I can tell, that flag is here: go/src/cmd/go/internal/load/flag.go Line 17 in 64fae25
That triggers the parsing case here: go/src/cmd/go/internal/load/flag.go Lines 52 to 63 in 64fae25
...which succeeds because it finds Before we call |
Change https://golang.org/cl/339289 mentions this issue: |
Not sure if it's this exact issue, but I just noticed that with
vs
In the past I was able to set a build id containing spaces using the syntax in the first command, i.e. |
It seems the order of args matters:
However, this command results in an error if actualy executed (by removing
|
Change https://go.dev/cl/407314 mentions this issue: |
The fix for #19534 (in CL 40994) adjusted escaping in the dynamically-linked name lookup logic for the plugin package. However, the regression test added for it incorrectly included quotes within the -ldflags flag, causing the flag to inadvertently be ignored. Possibly in that same CL or possibly at some other point, the condition that the test thought it was checking stopped working: the dynamic lookup used the path passed to ldflags, but the object file actually contained the symbol indexed by the original package name. Ideally we should stop mucking around with ldflags in this test and run 'go build' from a suitably-named directory instead, to mimic the actual conditions in which the original bug was reported. For now, as a more targeted fix, we can pass the '-p' flag to the compiler to adjust the package path used at compile time to match the one that will be set at link time. For #43177. Updates #19534. Change-Id: I9763961feb37cfb05dee543f273492e91a350663 Reviewed-on: https://go-review.googlesource.com/c/go/+/407314 Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
Change https://go.dev/cl/419594 mentions this issue: |
The pipeline error: ``` Building 'tools/benchmark'... % 'rm' '-f' 'bin/tools/benchmark' % 'env' 'GO_BUILD_FLAGS=-v' 'CGO_ENABLED=0' 'go' 'build' '-v' '-installsuffix=cgo' '-ldflags='\''-X=go.etcd.io/etcd/api/v3/version.GitSHA=01250c9'\''' '-o=bin/tools/benchmark' './tools/benchmark' stderr: invalid value "'-X=go.etcd.io/etcd/api/v3/version.GitSHA=01250c9'" for flag -ldflags: parameter may not start with quote character ' stderr: usage: go build [-o output] [build flags] [packages] stderr: Run 'go help build' for details. FAIL: (code:2): % 'env' 'GO_BUILD_FLAGS=-v' 'CGO_ENABLED=0' 'go' 'build' '-v' '-installsuffix=cgo' '-ldflags='\''-X=go.etcd.io/etcd/api/v3/version.GitSHA=01250c9'\''' '-o=bin/tools/benchmark' './tools/benchmark' FAIL: 'build' failed at Thu Sep 15 03:13:24 UTC 2022 ``` It's caused by golang/go#43177. Previously invalid -ldflags is silently ignored by go cmd. But it isn't ignored anymore in go 1.19 due to the fix in PR https://go-review.googlesource.com/c/go/+/339289. Signed-off-by: Benjamin Wang <[email protected]>
The pipeline error: ``` Building 'tools/benchmark'... % 'rm' '-f' 'bin/tools/benchmark' % 'env' 'GO_BUILD_FLAGS=-v' 'CGO_ENABLED=0' 'go' 'build' '-v' '-installsuffix=cgo' '-ldflags='\''-X=go.etcd.io/etcd/api/v3/version.GitSHA=01250c9'\''' '-o=bin/tools/benchmark' './tools/benchmark' stderr: invalid value "'-X=go.etcd.io/etcd/api/v3/version.GitSHA=01250c9'" for flag -ldflags: parameter may not start with quote character ' stderr: usage: go build [-o output] [build flags] [packages] stderr: Run 'go help build' for details. FAIL: (code:2): % 'env' 'GO_BUILD_FLAGS=-v' 'CGO_ENABLED=0' 'go' 'build' '-v' '-installsuffix=cgo' '-ldflags='\''-X=go.etcd.io/etcd/api/v3/version.GitSHA=01250c9'\''' '-o=bin/tools/benchmark' './tools/benchmark' FAIL: 'build' failed at Thu Sep 15 03:13:24 UTC 2022 ``` It's caused by golang/go#43177. Previously invalid -ldflags is silently ignored by go cmd. But it isn't ignored anymore in go 1.19 due to the fix in PR https://go-review.googlesource.com/c/go/+/339289. Signed-off-by: Benjamin Wang <[email protected]>
go version go1.15.5 linux/amd64
The
-ldflags
of the secondgo run
is in invalid format, but the go command silently ignores it and keeps working.See above
link
command. That's missing-X main.X=Hello
The text was updated successfully, but these errors were encountered: