1
0
mirror of https://github.com/golang/go synced 2024-11-20 07:04:40 -07:00

cmd/dist: use -buildmode=pie for pie testing

Some tests in misc/cgo/test are run with various options including
'-linkmode=external "-extldflags=-pie"'. On ppc64x passing -pie to
the external linker with code that was not compiled as position
independent is incorrect. This works by luck in many cases but is
not guaranteed to work. I suspect it is an issue on other targets
as well.

This will now run the tests using -buildmode=pie for the platforms
that support that buildmode option.

Fixes #21954

Change-Id: I25fc7573f2d3cb5b0d1c691a0ac91aef7715404f
Reviewed-on: https://go-review.googlesource.com/66870
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Lynn Boger 2017-09-28 10:26:39 -04:00
parent 92ba9b5c40
commit ca8c361d86

41
src/cmd/dist/test.go vendored
View File

@ -837,6 +837,16 @@ func (t *tester) supportedBuildmode(mode string) bool {
return true
}
return false
case "pie":
switch pair {
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-s390x",
"android-amd64", "android-arm", "android-arm64", "android-386":
return true
case "darwin-amd64":
return true
}
return false
default:
log.Fatalf("internal error: unknown buildmode %s", mode)
return false
@ -902,33 +912,10 @@ func (t *tester) cgoTest(dt *distTest) error {
// static linking on FreeBSD/ARM with clang. (cgo depends on
// -fPIC fundamentally.)
default:
cmd := t.dirCmd("misc/cgo/test",
defaultcc, "-xc", "-o", "/dev/null", "-static", "-")
cmd.Stdin = strings.NewReader("int main() {}")
if err := cmd.Run(); err != nil {
fmt.Println("No support for static linking found (lacks libc.a?), skip cgo static linking test.")
} else {
if goos != "android" {
t.addCmd(dt, "misc/cgo/testtls", "go", "test", "-ldflags", `-linkmode=external -extldflags "-static -pthread"`)
}
t.addCmd(dt, "misc/cgo/nocgo", "go", "test")
t.addCmd(dt, "misc/cgo/nocgo", "go", "test", "-ldflags", `-linkmode=external`)
if goos != "android" {
t.addCmd(dt, "misc/cgo/nocgo", "go", "test", "-ldflags", `-linkmode=external -extldflags "-static -pthread"`)
}
}
if pair != "freebsd-amd64" { // clang -pie fails to link misc/cgo/test
cmd := t.dirCmd("misc/cgo/test",
defaultcc, "-xc", "-o", "/dev/null", "-pie", "-")
cmd.Stdin = strings.NewReader("int main() {}")
if err := cmd.Run(); err != nil {
fmt.Println("No support for -pie found, skip cgo PIE test.")
} else {
t.addCmd(dt, "misc/cgo/test", "go", "test", "-ldflags", `-linkmode=external -extldflags "-pie"`)
t.addCmd(dt, "misc/cgo/testtls", "go", "test", "-ldflags", `-linkmode=external -extldflags "-pie"`)
t.addCmd(dt, "misc/cgo/nocgo", "go", "test", "-ldflags", `-linkmode=external -extldflags "-pie"`)
}
if t.supportedBuildmode("pie") {
t.addCmd(dt, "misc/cgo/test", "go", "test", "-buildmode=pie")
t.addCmd(dt, "misc/cgo/testtls", "go", "test", "-buildmode=pie")
t.addCmd(dt, "misc/cgo/nocgo", "go", "test", "-buildmode=pie")
}
}
}