Open dzbarsky opened 1 month ago
To add to the issue, I've also had to workaround this using toolchains_musl and a combination of the pure setting.
I thought this might be fixed by https://github.com/bazelbuild/rules_go/issues/3691 but no luck. I did notice that passing --linkopt=-no-pie
fixes things. @siddharthab @fmeum in case you have thoughts.
Thanks for the repro. This is actually a combination of two things happening.
__GO_BAZEL_CC_PLACEHOLDER__
, which makes the sysroot non-existent and the check for whether the linker supports -nopie
fails, thereby keeping the default pie behavior in clang frontend (reason for #3691). The unwanted prefix is coming from a bug in rules_go, which is setting this placeholder when building the Go stdlib. When you build your own binary, the Go toolchain picks up CGo directives from other objects being linked in, in this case, the stdlib objects like net.a
and cgo.a
.If the placeholder mechanism needs to stay, then I think the only solution is for the linker to also have a wrapper like cc.go.
I am not current in the codebase and I won't have the time to implement a proper solution here, so would appreciate if someone else takes over.
Also filed https://github.com/golang/go/issues/69350 to eventually fix the issue upstream.
Cc @AlessandroPatti for the wrapper
What version of rules_go are you using?
0.50.1
What version of gazelle are you using?
0.38
What version of Bazel are you using?
7.2.1
Does this issue reproduce with the latest releases of all the above?
yes
What did you do?
See https://github.com/DavidZbarsky-at/cgo-repro for repro
This was not an issue with go 1.20.1 but is an issue starting in 1.21 See https://github.com/google/skia/blob/main/.bazelrc#L41-L45 for another example in the wild
What did you expect to see?
No-op binary runs correctly
What did you see instead?