mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go, cmd/link: if -no-pie doesn't work, try -nopie
GCC says -no-pie, clang says -nopie. Fixes #21042 Change-Id: Iadc83ea7a48ea0debc5064c1ee8da4ebff752044 Reviewed-on: https://go-review.googlesource.com/49710 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
9311af79d5
commit
9e859d5e9c
2 changed files with 30 additions and 16 deletions
|
|
@ -1255,13 +1255,20 @@ func (l *Link) hostlink() {
|
|||
if err := ioutil.WriteFile(src, []byte{}, 0666); err != nil {
|
||||
Errorf(nil, "WriteFile trivial.c failed: %v", err)
|
||||
}
|
||||
cmd := exec.Command(argv[0], "-c", "-no-pie", "trivial.c")
|
||||
cmd.Dir = *flagTmpdir
|
||||
cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
supported := err == nil && !bytes.Contains(out, []byte("unrecognized"))
|
||||
if supported {
|
||||
argv = append(argv, "-no-pie")
|
||||
|
||||
// GCC uses -no-pie, clang uses -nopie.
|
||||
for _, nopie := range []string{"-no-pie", "-nopie"} {
|
||||
cmd := exec.Command(argv[0], "-c", nopie, "trivial.c")
|
||||
cmd.Dir = *flagTmpdir
|
||||
cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...)
|
||||
out, _ := 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"))
|
||||
if supported {
|
||||
argv = append(argv, nopie)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue