mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
7c946c6d61
commit
6bb88fc280
1 changed files with 4 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue