]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: if we get a C compiler dwarf2 warning, try without -g
authorIan Lance Taylor <iant@golang.org>
Sat, 11 Mar 2017 01:03:52 +0000 (17:03 -0800)
committerIan Lance Taylor <iant@golang.org>
Sat, 11 Mar 2017 01:19:13 +0000 (01:19 +0000)
This avoids a problem that occurs on FreeBSD 11, in which the clang
3.8 assembler issues a pointless warning when invoked with -g on a
file that contains an empty .note.GNU-stack section.

No test because there is no reasonable way to write one, but should
fix the build on FreeBSD 11.

Fixes #14705.

Change-Id: I8c49bbf79a2c715c0e75495da19045fc92280e81
Reviewed-on: https://go-review.googlesource.com/38072
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/go/internal/work/build.go

index 060fbd419da1840aab9898961a49fba3691a533a..7b07112508964ed7f24c43175bd1c58635c2b45e 100644 (file)
@@ -2897,6 +2897,26 @@ func (b *Builder) ccompile(p *load.Package, outfile string, flags []string, file
        desc := p.ImportPath
        output, err := b.runOut(p.Dir, desc, nil, compiler, flags, "-o", outfile, "-c", file)
        if len(output) > 0 {
+               // On FreeBSD 11, when we pass -g to clang 3.8 it
+               // invokes its internal assembler with -dwarf-version=2.
+               // When it sees .section .note.GNU-stack, it warns
+               // "DWARF2 only supports one section per compilation unit".
+               // This warning makes no sense, since the section is empty,
+               // but it confuses people.
+               // We work around the problem by detecting the warning
+               // and dropping -g and trying again.
+               if bytes.Contains(output, []byte("DWARF2 only supports one section per compilation unit")) {
+                       newFlags := make([]string, 0, len(flags))
+                       for _, f := range flags {
+                               if !strings.HasPrefix(f, "-g") {
+                                       newFlags = append(newFlags, f)
+                               }
+                       }
+                       if len(newFlags) < len(flags) {
+                               return b.ccompile(p, outfile, newFlags, file, compiler)
+                       }
+               }
+
                b.showOutput(p.Dir, desc, b.processOutput(output))
                if err != nil {
                        err = errPrintedOutput