You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempted to link programs using a hermetic llvm toolchain and sysroot with go tool link.
Reproducing this is a little difficult as the conditions for this bug surfaced through a Bazel build using the rules_go ruleset: bazel-contrib/rules_go#3886
In my case this caused hostLink() to fail with PIE errors when static linking, although I'm sure other errors related to flag ordering are possible.
What did you expect to see?
I expected to see programs link correctly. They in fact did link correctly when no sysroot was used but failed to do so when using a sysroot. Triggering and analyzing this bug was challenging due to the fact that there seems to be no logging that can be turned on for linkerFlagSupported(). This was encountered while building Go code with Bazel using rules_go and fix for the rules_go side of this issue has been proposed here: bazel-contrib/rules_go#4144
The cause of the rules_go bug appears to be an inconsistency in how go tool link calls linkers from linkerFlagSupported() and hostLink() which could affect users more generally than just in rules_go
Calls to linkerFlagSupported() put any -extldflags that were specified before the cgo flags that have been extracted from archives, while hostLink() seems to put them after. In cases where the archives were originally built with a --sysroot parameter which needs to be adjusted (because maybe the archives were built in a different sandbox than the final program for example) this means that linkerFlagSupported() is likely to detect all linker flags as "unsupported". The sysroot parameter specified in -extldflags will basically be ignored for linkerFlagSupported() calls but not for hostLink() calls.
I suspect this is just an oversight and not intended behavior. A simple fix would just be to adjust linkerFlagSupported() to always put -extldflags at the end.
The text was updated successfully, but these errors were encountered:
Go version
1.23.2
Output of
go env
in your module/workspace:What did you do?
Attempted to link programs using a hermetic llvm toolchain and sysroot with
go tool link
.Reproducing this is a little difficult as the conditions for this bug surfaced through a Bazel build using the
rules_go
ruleset: bazel-contrib/rules_go#3886What did you see happen?
Calls to
go tool link
detected all linker flags as unsupported, causinggo tool link
to add flags like-rdynamic
when static linking: https://cs.opensource.google/go/go/+/master:src/cmd/link/internal/ld/lib.go;l=1732?q=hostlinkIn my case this caused
hostLink()
to fail with PIE errors when static linking, although I'm sure other errors related to flag ordering are possible.What did you expect to see?
I expected to see programs link correctly. They in fact did link correctly when no sysroot was used but failed to do so when using a sysroot. Triggering and analyzing this bug was challenging due to the fact that there seems to be no logging that can be turned on for
linkerFlagSupported()
. This was encountered while building Go code with Bazel usingrules_go
and fix for therules_go
side of this issue has been proposed here: bazel-contrib/rules_go#4144The cause of the
rules_go
bug appears to be an inconsistency in howgo tool link
calls linkers fromlinkerFlagSupported()
andhostLink()
which could affect users more generally than just inrules_go
Calls to
linkerFlagSupported()
put any-extldflags
that were specified before the cgo flags that have been extracted from archives, whilehostLink()
seems to put them after. In cases where the archives were originally built with a--sysroot
parameter which needs to be adjusted (because maybe the archives were built in a different sandbox than the final program for example) this means thatlinkerFlagSupported()
is likely to detect all linker flags as "unsupported". The sysroot parameter specified in-extldflags
will basically be ignored forlinkerFlagSupported()
calls but not forhostLink()
calls.I suspect this is just an oversight and not intended behavior. A simple fix would just be to adjust
linkerFlagSupported()
to always put-extldflags
at the end.The text was updated successfully, but these errors were encountered: