Commit fe345855 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 2de773d4
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment