Commit 6bb88fc2 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 7c946c6d
...@@ -1252,19 +1252,19 @@ func (l *Link) hostlink() { ...@@ -1252,19 +1252,19 @@ func (l *Link) hostlink() {
// toolchain if it is supported. // toolchain if it is supported.
if Buildmode == BuildmodeExe { if Buildmode == BuildmodeExe {
src := filepath.Join(*flagTmpdir, "trivial.c") 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) Errorf(nil, "WriteFile trivial.c failed: %v", err)
} }
// GCC uses -no-pie, clang uses -nopie. // GCC uses -no-pie, clang uses -nopie.
for _, nopie := range []string{"-no-pie", "-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.Dir = *flagTmpdir
cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...) cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
out, _ := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
// GCC says "unrecognized command line option ‘-no-pie’" // GCC says "unrecognized command line option ‘-no-pie’"
// clang says "unknown argument: '-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 { if supported {
argv = append(argv, nopie) argv = append(argv, nopie)
break break
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment