From fe3458550bfee0c842393e44e096fd64c666d909 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 10 Mar 2017 17:03:52 -0800 Subject: [PATCH] cmd/go: if we get a C compiler dwarf2 warning, try without -g 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/work/build.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index 060fbd419d..7b07112508 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -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 -- 2.48.1