]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: tweak support options test for old compilers
authorIan Lance Taylor <iant@golang.org>
Sat, 18 Nov 2017 00:51:17 +0000 (16:51 -0800)
committerIan Lance Taylor <iant@golang.org>
Sat, 18 Nov 2017 01:35:39 +0000 (01:35 +0000)
Fixes #22787

Change-Id: Ie0f3995e4bb611ee5927345b17b0d5b381a5ed74
Reviewed-on: https://go-review.googlesource.com/78543
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/go/internal/work/exec.go

index 4d6b8a1b9077862a310a83eada4fb9ccd3cfbbfc..405abc4323c4d4744ac0abffb26f37359258e1d7 100644 (file)
@@ -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
 }