]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: use full link, not compile, to test for -no-?pie
authorIan Lance Taylor <iant@golang.org>
Mon, 24 Jul 2017 17:13:25 +0000 (10:13 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 24 Jul 2017 17:50:57 +0000 (17:50 +0000)
This avoids an error from clang when using -nopie during compilation,
and permits us to check that the entire build succeeds.

Updates #21042

Change-Id: I2e6c7d5c97a85c223ed3288622bbb58ce33b8774
Reviewed-on: https://go-review.googlesource.com/50874
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/link/internal/ld/lib.go

index 381022081b7bf07d62084e77da3ca739922c83ff..023410512c9d1bdcec776513646eb4238fe18123 100644 (file)
@@ -1252,19 +1252,19 @@ func (l *Link) hostlink() {
        // toolchain if it is supported.
        if Buildmode == BuildmodeExe {
                src := filepath.Join(*flagTmpdir, "trivial.c")
-               if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
+               if err := ioutil.WriteFile(src, []byte("int main() { return 0; }"), 0666); err != nil {
                        Errorf(nil, "WriteFile trivial.c failed: %v", err)
                }
 
                // GCC uses -no-pie, clang uses -nopie.
                for _, nopie := range []string{"-no-pie", "-nopie"} {
-                       cmd := exec.Command(argv[0], "-c", nopie, "trivial.c")
+                       cmd := exec.Command(argv[0], nopie, "trivial.c")
                        cmd.Dir = *flagTmpdir
                        cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
-                       out, _ := cmd.CombinedOutput()
+                       out, err := cmd.CombinedOutput()
                        // GCC says "unrecognized command line option ‘-no-pie’"
                        // clang says "unknown argument: '-no-pie'"
-                       supported := !bytes.Contains(out, []byte("unrecognized")) && !bytes.Contains(out, []byte("unknown"))
+                       supported := err == nil && !bytes.Contains(out, []byte("unrecognized")) && !bytes.Contains(out, []byte("unknown"))
                        if supported {
                                argv = append(argv, nopie)
                                break