]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix tests that fail when running a cross-compiled GOARCH
authorBryan C. Mills <bcmills@google.com>
Thu, 1 Feb 2024 20:56:05 +0000 (15:56 -0500)
committerGopher Robot <gobot@golang.org>
Mon, 5 Feb 2024 14:52:04 +0000 (14:52 +0000)
In CL 356611 I changed cmd/go to run most of its tests (instead of
skipping them all) when cross-compiled, such as with GOARCH=386 on an
amd64 host. Unfortunately, since we don't have a CI builder that runs
long tests in a cross-compiled configuration, some of the tests have
rotted since then.

This fixes 'GOARCH=386 go test cmd/go' on my workstation.

For #64963.
Updates #53936.

Change-Id: If7f4bc8e8d1ace7d36010d7a1b652fc7b2ceb276
Cq-Include-Trybots: luci.golang.try:gotip-linux-386-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/560782
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/scriptconds_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/build_plugin_reproducible.txt
src/cmd/go/testdata/script/version.txt
src/cmd/go/testdata/script/version_cshared.txt

index 8dd9b0d1cd1a971ba4a87124b31cb960e29c82c6..13007daba5188a88903f91a048fae9a199c85f07 100644 (file)
@@ -55,6 +55,7 @@ func scriptConditions() map[string]script.Cond {
        add("msan", sysCondition("-msan", platform.MSanSupported, true))
        add("mustlinkext", script.Condition("platform always requires external linking", mustLinkExt))
        add("net", script.PrefixCondition("can connect to external network host <suffix>", hasNet))
+       add("pielinkext", script.Condition("platform requires external linking for PIE", pieLinkExt))
        add("race", sysCondition("-race", platform.RaceDetectorSupported, true))
        add("symlink", lazyBool("testenv.HasSymlink()", testenv.HasSymlink))
        add("trimpath", script.OnceCondition("test binary was built with -trimpath", isTrimpath))
@@ -233,3 +234,9 @@ func mustLinkExt(s *script.State) (bool, error) {
        GOARCH, _ := s.LookupEnv("GOARCH")
        return platform.MustLinkExternal(GOOS, GOARCH, false), nil
 }
+
+func pieLinkExt(s *script.State) (bool, error) {
+       GOOS, _ := s.LookupEnv("GOOS")
+       GOARCH, _ := s.LookupEnv("GOARCH")
+       return !platform.InternalLinkPIESupported(GOOS, GOARCH), nil
+}
index 792a158760f6f50c16bcd740df8ba9c2d17b8bca..39971f8029e4a85bddc9f03822ae821c1683a02e 100644 (file)
@@ -410,6 +410,8 @@ The available conditions are:
        platform always requires external linking
 [net:*]
        can connect to external network host <suffix>
+[pielinkext]
+       platform requires external linking for PIE
 [race]
        GOOS/GOARCH supports -race
 [root]
index 5369954859563102a76efc4f977d56db41043c73..3379a6be5f99ceff5589b43f765c14a69b5351d9 100644 (file)
@@ -1,5 +1,6 @@
 [!buildmode:plugin] skip
 [short] skip
+[!cgo] skip '-buildmode=plugin requires external linking'
 
 go build -trimpath -buildvcs=false -buildmode=plugin -o a.so main.go
 go build -trimpath -buildvcs=false -buildmode=plugin -o b.so main.go
@@ -8,4 +9,4 @@ cmp -q a.so b.so
 -- main.go --
 package main
 
-func main() {}
\ No newline at end of file
+func main() {}
index 0a2ac1e1d58f30651ecdbd5fa804d0547090610a..a18bcdd915d40e09653d94c8858603dfb7c9b38c 100644 (file)
@@ -57,8 +57,9 @@ stdout '^test2json.exe: .+'
 stdout '^\tpath\tcmd/test2json$'
 ! stdout 'mod[^e]'
 
-# Repeat the test with -buildmode=pie.
+# Repeat the test with -buildmode=pie and default linking.
 [!buildmode:pie] stop
+[pielinkext] [!cgo] stop
 go build -buildmode=pie -o external.exe rsc.io/fortune
 go version external.exe
 stdout '^external.exe: .+'
@@ -68,9 +69,7 @@ stdout '^\tpath\trsc.io/fortune'
 stdout '^\tmod\trsc.io/fortune\tv1.0.0'
 
 # Also test PIE with internal linking.
-# currently only supported on linux/amd64, linux/arm64 and windows/amd64.
-[!GOOS:linux] [!GOOS:windows] stop
-[!GOARCH:amd64] [!GOARCH:arm64] stop
+[pielinkext] stop
 go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
 go version internal.exe
 stdout '^internal.exe: .+'
index 29e21fc09aae6d492f0e7b0ba64b3a40ab3894f8..18f257f64ab8c04c66febe402606edfc99b077fc 100644 (file)
@@ -1,4 +1,5 @@
 [short] skip
+[!cgo] skip '-buildmode=c-shared requires external linking'
 [!buildmode:c-shared] stop
 
 env GO111MODULE=on