]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: use -buildmode=pie for pie testing
authorLynn Boger <laboger@linux.vnet.ibm.com>
Thu, 28 Sep 2017 14:26:39 +0000 (10:26 -0400)
committerLynn Boger <laboger@linux.vnet.ibm.com>
Tue, 3 Oct 2017 18:41:48 +0000 (18:41 +0000)
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>
src/cmd/dist/test.go

index ae7f25cad9c7b28c165a4d430cbab6888959e249..41fc84e3ede781962d3b297458110944ff2fc3e4 100644 (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")
                        }
                }
        }