From 6bb88fc280518150e31bf12744596467796a4528 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 24 Jul 2017 10:13:25 -0700 Subject: [PATCH] cmd/link: use full link, not compile, to test for -no-?pie 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 Reviewed-by: Brad Fitzpatrick --- src/cmd/link/internal/ld/lib.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 381022081b..023410512c 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -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 -- 2.48.1