Skip to content

Commit e8d8772

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
cmd/go: fix tests that fail when running a cross-compiled GOARCH
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 <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent b8ac61e commit e8d8772

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

src/cmd/go/scriptconds_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func scriptConditions() map[string]script.Cond {
5555
add("msan", sysCondition("-msan", platform.MSanSupported, true))
5656
add("mustlinkext", script.Condition("platform always requires external linking", mustLinkExt))
5757
add("net", script.PrefixCondition("can connect to external network host <suffix>", hasNet))
58+
add("pielinkext", script.Condition("platform requires external linking for PIE", pieLinkExt))
5859
add("race", sysCondition("-race", platform.RaceDetectorSupported, true))
5960
add("symlink", lazyBool("testenv.HasSymlink()", testenv.HasSymlink))
6061
add("trimpath", script.OnceCondition("test binary was built with -trimpath", isTrimpath))
@@ -233,3 +234,9 @@ func mustLinkExt(s *script.State) (bool, error) {
233234
GOARCH, _ := s.LookupEnv("GOARCH")
234235
return platform.MustLinkExternal(GOOS, GOARCH, false), nil
235236
}
237+
238+
func pieLinkExt(s *script.State) (bool, error) {
239+
GOOS, _ := s.LookupEnv("GOOS")
240+
GOARCH, _ := s.LookupEnv("GOARCH")
241+
return !platform.InternalLinkPIESupported(GOOS, GOARCH), nil
242+
}

src/cmd/go/testdata/script/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ The available conditions are:
410410
platform always requires external linking
411411
[net:*]
412412
can connect to external network host <suffix>
413+
[pielinkext]
414+
platform requires external linking for PIE
413415
[race]
414416
GOOS/GOARCH supports -race
415417
[root]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[!buildmode:plugin] skip
22
[short] skip
3+
[!cgo] skip '-buildmode=plugin requires external linking'
34

45
go build -trimpath -buildvcs=false -buildmode=plugin -o a.so main.go
56
go build -trimpath -buildvcs=false -buildmode=plugin -o b.so main.go
@@ -8,4 +9,4 @@ cmp -q a.so b.so
89
-- main.go --
910
package main
1011

11-
func main() {}
12+
func main() {}

src/cmd/go/testdata/script/version.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ stdout '^test2json.exe: .+'
5757
stdout '^\tpath\tcmd/test2json$'
5858
! stdout 'mod[^e]'
5959

60-
# Repeat the test with -buildmode=pie.
60+
# Repeat the test with -buildmode=pie and default linking.
6161
[!buildmode:pie] stop
62+
[pielinkext] [!cgo] stop
6263
go build -buildmode=pie -o external.exe rsc.io/fortune
6364
go version external.exe
6465
stdout '^external.exe: .+'
@@ -68,9 +69,7 @@ stdout '^\tpath\trsc.io/fortune'
6869
stdout '^\tmod\trsc.io/fortune\tv1.0.0'
6970

7071
# Also test PIE with internal linking.
71-
# currently only supported on linux/amd64, linux/arm64 and windows/amd64.
72-
[!GOOS:linux] [!GOOS:windows] stop
73-
[!GOARCH:amd64] [!GOARCH:arm64] stop
72+
[pielinkext] stop
7473
go build -buildmode=pie -ldflags=-linkmode=internal -o internal.exe rsc.io/fortune
7574
go version internal.exe
7675
stdout '^internal.exe: .+'

src/cmd/go/testdata/script/version_cshared.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[short] skip
2+
[!cgo] skip '-buildmode=c-shared requires external linking'
23
[!buildmode:c-shared] stop
34

45
env GO111MODULE=on

0 commit comments

Comments
 (0)