go: only enable PIE by default when building for GOARCH matching target

We rely on teaching go to use the correct ELF interpreter
for PIE in a way that can't work for packages that 
go off and do their own GOARCH=something cross builds
without touching nixpkgs cross machinery,
so update the default pie patch to bake targetPlatform's
GOARCH and only activate for it.

tailscale works as a testcase for this as it cross compiles
many arches in tstest/archtest/qemu_test.go
This commit is contained in:
Luna Nova
2025-10-07 17:25:46 -07:00
parent ca6a37f817
commit dbb57d8d86
3 changed files with 7 additions and 3 deletions

View File

@@ -65,7 +65,9 @@ stdenv.mkDerivation (finalAttrs: {
./remove-tools-1.11.patch
./go_no_vendor_checks-1.23.patch
./go-env-go_ldso.patch
./go-default-pie.patch
(replaceVars ./go-default-pie.patch {
inherit (stdenv.targetPlatform.go) GOARCH;
})
];
inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM;

View File

@@ -75,7 +75,9 @@ stdenv.mkDerivation (finalAttrs: {
./remove-tools-1.11.patch
./go_no_vendor_checks-1.23.patch
./go-env-go_ldso.patch
./go-default-pie.patch
(replaceVars ./go-default-pie.patch {
inherit (stdenv.targetPlatform.go) GOARCH;
})
];
inherit (stdenv.targetPlatform.go) GOOS GOARCH GOARM;

View File

@@ -7,7 +7,7 @@ index f9706a6988..abac42d550 100644
return true
}
- return false
+ return BuildModeSupported("gc", "pie", goos, goarch)
+ return goarch == "@GOARCH@" && BuildModeSupported("gc", "pie", goos, goarch)
}
// ExecutableHasDWARF reports whether the linked executable includes DWARF