From: Ian Lance Taylor Date: Sat, 18 Nov 2017 00:51:17 +0000 (-0800) Subject: cmd/go: tweak support options test for old compilers X-Git-Tag: go1.10beta1~206 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d48336b7982c641b7c0d323044b5e34167c69049;p=gostls13.git cmd/go: tweak support options test for old compilers Fixes #22787 Change-Id: Ie0f3995e4bb611ee5927345b17b0d5b381a5ed74 Reviewed-on: https://go-review.googlesource.com/78543 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 4d6b8a1b90..405abc4323 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -1759,18 +1759,13 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool { if b.flagCache == nil { b.flagCache = make(map[[2]string]bool) } - // We used to write an empty C file, but we already look to make - // sure the error is specifically about the command-line option, - // so the file does not need to exist at all. This avoids creating a - // file in -n mode and (if -n mode must not create a file) ensures - // that -n mode matches the regular mode. - cmdArgs := str.StringList(compiler, flag, "-c", "does_not_exist.c") - if cfg.BuildN || cfg.BuildX { - b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs)) - if cfg.BuildN { - return false - } - } + // We used to write an empty C file, but that gets complicated with + // go build -n. We tried using a file that does not exist, but that + // fails on systems with GCC version 4.2.1; that is the last GPLv2 + // version of GCC, so some systems have frozen on it. + // Now we pass an empty file on stdin, which should work at least for + // GCC and clang. + cmdArgs := str.StringList(compiler, flag, "-c", "-x", "c", "-") if cfg.BuildN || cfg.BuildX { b.Showcmd(b.WorkDir, "%s", joinUnambiguously(cmdArgs)) if cfg.BuildN { @@ -1783,7 +1778,10 @@ func (b *Builder) gccSupportsFlag(compiler []string, flag string) bool { out, _ := cmd.CombinedOutput() // GCC says "unrecognized command line option". // clang says "unknown argument". - supported := !bytes.Contains(out, []byte("unrecognized")) && !bytes.Contains(out, []byte("unknown")) + // Older versions of GCC say "unrecognised debug output level". + supported := !bytes.Contains(out, []byte("unrecognized")) && + !bytes.Contains(out, []byte("unknown")) && + !bytes.Contains(out, []byte("unrecognised")) b.flagCache[key] = supported return supported }