mirror of
https://github.com/golang/go.git
synced 2025-05-15 12:24:37 +00:00
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>
This commit is contained in:
parent
5c9a8c0761
commit
c76befe0f4
@ -31,6 +31,12 @@ TODO
|
|||||||
|
|
||||||
<h2 id="ports">Ports</h2>
|
<h2 id="ports">Ports</h2>
|
||||||
|
|
||||||
|
<p> <!-- CL 214397 and CL 230217 -->
|
||||||
|
Go 1.15 now generates Windows ASLR executables when -buildmode=pie
|
||||||
|
cmd/link flag is provided. Go command uses -buildmode=pie by default
|
||||||
|
on Windows.
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
TODO
|
TODO
|
||||||
</p>
|
</p>
|
||||||
|
@ -2082,19 +2082,38 @@ func TestBuildmodePIE(t *testing.T) {
|
|||||||
t.Skipf("skipping test because buildmode=pie is not supported on %s", platform)
|
t.Skipf("skipping test because buildmode=pie is not supported on %s", platform)
|
||||||
}
|
}
|
||||||
t.Run("non-cgo", func(t *testing.T) {
|
t.Run("non-cgo", func(t *testing.T) {
|
||||||
testBuildmodePIE(t, false)
|
testBuildmodePIE(t, false, true)
|
||||||
})
|
})
|
||||||
if canCgo {
|
if canCgo {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "darwin", "freebsd", "linux", "windows":
|
case "darwin", "freebsd", "linux", "windows":
|
||||||
t.Run("cgo", func(t *testing.T) {
|
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)
|
tg := testgo(t)
|
||||||
defer tg.cleanup()
|
defer tg.cleanup()
|
||||||
tg.parallel()
|
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))
|
tg.tempFile("main.go", fmt.Sprintf(`package main;%s func main() { print("hello") }`, s))
|
||||||
src := tg.path("main.go")
|
src := tg.path("main.go")
|
||||||
obj := tg.path("main.exe")
|
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 {
|
switch runtime.GOOS {
|
||||||
case "linux", "android", "freebsd":
|
case "linux", "android", "freebsd":
|
||||||
|
@ -155,6 +155,8 @@ func buildModeInit() {
|
|||||||
case "android":
|
case "android":
|
||||||
codegenArg = "-shared"
|
codegenArg = "-shared"
|
||||||
ldBuildmode = "pie"
|
ldBuildmode = "pie"
|
||||||
|
case "windows":
|
||||||
|
ldBuildmode = "pie"
|
||||||
case "darwin":
|
case "darwin":
|
||||||
switch cfg.Goarch {
|
switch cfg.Goarch {
|
||||||
case "arm64":
|
case "arm64":
|
||||||
|
@ -924,8 +924,8 @@ func TestRuntimeTypeAttrInternal(t *testing.T) {
|
|||||||
t.Skip("skipping on plan9; no DWARF symbol table in executables")
|
t.Skip("skipping on plan9; no DWARF symbol table in executables")
|
||||||
}
|
}
|
||||||
|
|
||||||
if runtime.GOOS == "windows" && runtime.GOARCH == "arm" {
|
if runtime.GOOS == "windows" {
|
||||||
t.Skip("skipping on windows/arm; test is incompatible with relocatable binaries")
|
t.Skip("skipping on windows; test is incompatible with relocatable binaries")
|
||||||
}
|
}
|
||||||
|
|
||||||
testRuntimeTypeAttr(t, "-ldflags=-linkmode=internal")
|
testRuntimeTypeAttr(t, "-ldflags=-linkmode=internal")
|
||||||
@ -944,6 +944,11 @@ func TestRuntimeTypeAttrExternal(t *testing.T) {
|
|||||||
if runtime.GOARCH == "ppc64" {
|
if runtime.GOARCH == "ppc64" {
|
||||||
t.Skip("-linkmode=external not supported on ppc64")
|
t.Skip("-linkmode=external not supported on ppc64")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
t.Skip("skipping on windows; test is incompatible with relocatable binaries")
|
||||||
|
}
|
||||||
|
|
||||||
testRuntimeTypeAttr(t, "-ldflags=-linkmode=external")
|
testRuntimeTypeAttr(t, "-ldflags=-linkmode=external")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func testGoExec(t *testing.T, iscgo, isexternallinker bool) {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" && runtime.GOARCH == "arm" {
|
if runtime.GOOS == "windows" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user