}
// gccld runs the gcc linker to create an executable from a set of object files.
-func (b *Builder) gccld(p *load.Package, objdir, out string, flags []string, objs []string) error {
+func (b *Builder) gccld(p *load.Package, objdir, outfile string, flags []string, objs []string) error {
var cmd []string
if len(p.CXXFiles) > 0 || len(p.SwigCXXFiles) > 0 {
cmd = b.GxxCmd(p.Dir, objdir)
} else {
cmd = b.GccCmd(p.Dir, objdir)
}
- return b.run(nil, p.Dir, p.ImportPath, b.cCompilerEnv(), cmd, "-o", out, objs, flags)
+
+ cmdargs := []interface{}{cmd, "-o", outfile, objs, flags}
+ dir := p.Dir
+ out, err := b.runOut(dir, b.cCompilerEnv(), cmdargs...)
+ if len(out) > 0 {
+ // Filter out useless linker warnings caused by bugs outside Go.
+ // See also cmd/link/internal/ld's hostlink method.
+ var save [][]byte
+ for _, line := range bytes.SplitAfter(out, []byte("\n")) {
+ // golang.org/issue/26073 - Apple Xcode bug
+ if bytes.Contains(line, []byte("ld: warning: text-based stub file")) {
+ continue
+ }
+ save = append(save, line)
+ }
+ out = bytes.Join(save, nil)
+ if len(out) > 0 {
+ b.showOutput(nil, dir, p.ImportPath, b.processOutput(out))
+ if err != nil {
+ err = errPrintedOutput
+ }
+ }
+ }
+ return err
}
// Grab these before main helpfully overwrites them.
ctxt.Logf("\n")
}
- if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil {
+ out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput()
+ if err != nil {
Exitf("running %s failed: %v\n%s", argv[0], err, out)
- } else if len(out) > 0 {
+ }
+
+ // Filter out useless linker warnings caused by bugs outside Go.
+ // See also cmd/go/internal/work/exec.go's gccld method.
+ var save [][]byte
+ for _, line := range bytes.SplitAfter(out, []byte("\n")) {
+ // golang.org/issue/26073 - Apple Xcode bug
+ if bytes.Contains(line, []byte("ld: warning: text-based stub file")) {
+ continue
+ }
+ save = append(save, line)
+ }
+ out = bytes.Join(save, nil)
+
+ if len(out) > 0 {
// always print external output even if the command is successful, so that we don't
// swallow linker warnings (see https://golang.org/issue/17935).
ctxt.Logf("%s", out)