cmd/link: relative paths are not respected when checking supported linker flags #59952
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, it even reproduces when building go off of main.
From looking at the code, it seems like all versions of go should be affected.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I created the following script to reproduce the exact issue I'm seeing.
repro.sh
Ran
./repro.sh
. Also ranUSE_DEV_GO=1 ./repro.sh
inside of the go repository after running./all.bash
off of main, to test against main.What did you expect to see?
./repro.sh
to not return an error code.What did you see instead?
./repro.sh
returns an error code because-no-pie
or-nopie
are not added to the external link flags.The way that the
linkerFlagSupported
function works, means that if-extld
or-extldflags
reference relative paths they can causelinkerFlagSupported
to returnfalse
, leading linker flags to not be added when they should be. In my repro script, this manifests itself in-no-pie
not getting added to the external link flags, which can cause downstream issues. For example, when using bazelbuild/rules_go with a relative compiler path and with a compiler that defaults to PIE, the built go binaries end up segfaulting because go was compiled expecting to be run as a static binary but the external linker links it as PIE.The repro script I provided is just one example of issues with
linkerFlagSupported
being run outside of the current working directory, but you could for example also have a relative path in-extldflags
say--sysroot=relative/path/to/sysroot
.The fix is pretty simple,
linkerFlagSupported
should be run in the current working directory instead of inside the created temporary directory. I will put out a PR shortly.The text was updated successfully, but these errors were encountered: