Skip to content

Commit edb6c16

Browse files
rscandybons
authored andcommitted
[release-branch.go1.11] cmd/go, cmd/link: silence bogus Apple Xcode warning
Certain installations of Xcode are affected by a bug that causes them to print an inconsequential link-time warning that looks like: ld: warning: text-based stub file /System/Library/Frameworks//Security.framework/Security.tbd and library file /System/Library/Frameworks//Security.framework/Security are out of sync. Falling back to library file for linking. This has nothing to do with Go, and we've sent this repro case to Apple: $ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version version: 10.0.0.0.1.1535735448 $ clang --version Apple LLVM version 10.0.0 (clang-1000.10.44.2) Target: x86_64-apple-darwin17.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin $ cat > issue.c int main() { return 0; } ^D $ clang issue.c -framework CoreFoundation ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync. Falling back to library file for linking. $ Even if Apple does release a fixed Xcode, many people are seeing this useless warning, and we might as well make it go away. Fixes #26073. Change-Id: Ifc17ba7da1f6b59e233c11ebdab7241cb6656324 Reviewed-on: https://go-review.googlesource.com/c/144112 Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Andrew Bonventre <[email protected]> (cherry picked from commit 66bb8dd) Reviewed-on: https://go-review.googlesource.com/c/145458 Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 05b2b9b commit edb6c16

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

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

+25-2
Original file line numberDiff line numberDiff line change
@@ -2077,14 +2077,37 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
20772077
}
20782078

20792079
// gccld runs the gcc linker to create an executable from a set of object files.
2080-
func (b *Builder) gccld(p *load.Package, objdir, out string, flags []string, objs []string) error {
2080+
func (b *Builder) gccld(p *load.Package, objdir, outfile string, flags []string, objs []string) error {
20812081
var cmd []string
20822082
if len(p.CXXFiles) > 0 || len(p.SwigCXXFiles) > 0 {
20832083
cmd = b.GxxCmd(p.Dir, objdir)
20842084
} else {
20852085
cmd = b.GccCmd(p.Dir, objdir)
20862086
}
2087-
return b.run(nil, p.Dir, p.ImportPath, b.cCompilerEnv(), cmd, "-o", out, objs, flags)
2087+
2088+
cmdargs := []interface{}{cmd, "-o", outfile, objs, flags}
2089+
dir := p.Dir
2090+
out, err := b.runOut(dir, b.cCompilerEnv(), cmdargs...)
2091+
if len(out) > 0 {
2092+
// Filter out useless linker warnings caused by bugs outside Go.
2093+
// See also cmd/link/internal/ld's hostlink method.
2094+
var save [][]byte
2095+
for _, line := range bytes.SplitAfter(out, []byte("\n")) {
2096+
// golang.org/issue/26073 - Apple Xcode bug
2097+
if bytes.Contains(line, []byte("ld: warning: text-based stub file")) {
2098+
continue
2099+
}
2100+
save = append(save, line)
2101+
}
2102+
out = bytes.Join(save, nil)
2103+
if len(out) > 0 {
2104+
b.showOutput(nil, dir, p.ImportPath, b.processOutput(out))
2105+
if err != nil {
2106+
err = errPrintedOutput
2107+
}
2108+
}
2109+
}
2110+
return err
20882111
}
20892112

20902113
// Grab these before main helpfully overwrites them.

src/cmd/link/internal/ld/lib.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -1323,9 +1323,24 @@ func (ctxt *Link) hostlink() {
13231323
ctxt.Logf("\n")
13241324
}
13251325

1326-
if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil {
1326+
out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput()
1327+
if err != nil {
13271328
Exitf("running %s failed: %v\n%s", argv[0], err, out)
1328-
} else if len(out) > 0 {
1329+
}
1330+
1331+
// Filter out useless linker warnings caused by bugs outside Go.
1332+
// See also cmd/go/internal/work/exec.go's gccld method.
1333+
var save [][]byte
1334+
for _, line := range bytes.SplitAfter(out, []byte("\n")) {
1335+
// golang.org/issue/26073 - Apple Xcode bug
1336+
if bytes.Contains(line, []byte("ld: warning: text-based stub file")) {
1337+
continue
1338+
}
1339+
save = append(save, line)
1340+
}
1341+
out = bytes.Join(save, nil)
1342+
1343+
if len(out) > 0 {
13291344
// always print external output even if the command is successful, so that we don't
13301345
// swallow linker warnings (see https://golang.org/issue/17935).
13311346
ctxt.Logf("%s", out)

0 commit comments

Comments
 (0)