-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: wrong flag order when checking supported linker flags #69350
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
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
help wanted
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
CC @golang/compiler, @cherrymui. |
@siddharthab Thanks for the detailed bug report and the possible fix! Would you be willing to send a patch? Thanks! See https://go.dev/doc/contribute. |
Change https://go.dev/cl/614275 mentions this issue: |
Thanks @mknyszek for considering this. The sent Gerrit CR should resolve this issue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
help wanted
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
1.23.1
Output of
go env
in your module/workspace:What did you do?
There can probably be a simpler repro, but I am presenting here as I discovered the issue. The context is Bazel rules for Go. As per bazel-contrib/rules_go#4091, I used the repro in https://github.com/DavidZbarsky-at/cgo-repro.
To further investigate the issue, I patched the source code for linkerFlagSupported to print the linker command being executed.
What did you see happen?
All invocations of
linkerFlagSupported
fail because of the wrong order of linker flags:The patched print statement reveals the following information:
Notice the multiple values of
--sysroot
. The first value is coming fromextldflags
, and the two later values are coming from CGo directives from stdlib objects being linked in.What did you expect to see?
CGo directives should get less priority than
extldflags
, and so should be placed before.This is because of how flags are appended in
go/src/cmd/link/internal/ld/lib.go
Line 2128 in 807e01d
Consider the correct behavior in the final link command -
extldflags
after CGo directives (given by the variableldflag
):go/src/cmd/link/internal/ld/lib.go
Lines 1857 to 1882 in 807e01d
The fix can be as simple as to change the above line in linkerFlagSupported to:
The text was updated successfully, but these errors were encountered: