diff options
author | Alex Brainman <alex.brainman@gmail.com> | 2020-04-26 10:40:38 +1000 |
---|---|---|
committer | Alex Brainman <alex.brainman@gmail.com> | 2020-04-30 08:07:47 +0000 |
commit | c76befe0f40dfbb38a54c16d1845b97e4580797c (patch) | |
tree | 6d4435935bb20f4e548796c672f4d408d50018ce /src/cmd/go/go_test.go | |
parent | 5c9a8c0761ae643828a4526db764ac7a50a1a24d (diff) | |
download | go-git-c76befe0f40dfbb38a54c16d1845b97e4580797c.tar.gz |
cmd/go: use -buildmode=pie as default on window
This change adjusts go command to pass -buildmode=pie to cmd/link,
if -buildmode is not explicitly provided.
Fixes #35192
Change-Id: Iec020131e676eb3e9a2df9eea1929b2af2b6df04
Reviewed-on: https://go-review.googlesource.com/c/go/+/230217
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/go/go_test.go')
-rw-r--r-- | src/cmd/go/go_test.go | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index e1cf1f8ff5..d7f6b47135 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -2082,19 +2082,38 @@ func TestBuildmodePIE(t *testing.T) { t.Skipf("skipping test because buildmode=pie is not supported on %s", platform) } t.Run("non-cgo", func(t *testing.T) { - testBuildmodePIE(t, false) + testBuildmodePIE(t, false, true) }) if canCgo { switch runtime.GOOS { case "darwin", "freebsd", "linux", "windows": t.Run("cgo", func(t *testing.T) { - testBuildmodePIE(t, true) + testBuildmodePIE(t, true, true) }) } } } -func testBuildmodePIE(t *testing.T, useCgo bool) { +func TestWindowsDefaultBuildmodIsPIE(t *testing.T) { + if testing.Short() && testenv.Builder() == "" { + t.Skipf("skipping in -short mode on non-builder") + } + + if runtime.GOOS != "windows" { + t.Skip("skipping windows only test") + } + + t.Run("non-cgo", func(t *testing.T) { + testBuildmodePIE(t, false, false) + }) + if canCgo { + t.Run("cgo", func(t *testing.T) { + testBuildmodePIE(t, true, false) + }) + } +} + +func testBuildmodePIE(t *testing.T, useCgo, setBuildmodeToPIE bool) { tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -2106,7 +2125,12 @@ func testBuildmodePIE(t *testing.T, useCgo bool) { tg.tempFile("main.go", fmt.Sprintf(`package main;%s func main() { print("hello") }`, s)) src := tg.path("main.go") obj := tg.path("main.exe") - tg.run("build", "-buildmode=pie", "-o", obj, src) + args := []string{"build"} + if setBuildmodeToPIE { + args = append(args, "-buildmode=pie") + } + args = append(args, "-o", obj, src) + tg.run(args...) switch runtime.GOOS { case "linux", "android", "freebsd": |