Skip to content

Commit 66bb8dd

Browse files
committed
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]>
1 parent 41d6315 commit 66bb8dd

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
@@ -2080,14 +2080,37 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
20802080
}
20812081

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

20932116
// Grab these before main helpfully overwrites them.

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,24 @@ func (ctxt *Link) hostlink() {
13381338
ctxt.Logf("\n")
13391339
}
13401340

1341-
if out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput(); err != nil {
1341+
out, err := exec.Command(argv[0], argv[1:]...).CombinedOutput()
1342+
if err != nil {
13421343
Exitf("running %s failed: %v\n%s", argv[0], err, out)
1343-
} else if len(out) > 0 {
1344+
}
1345+
1346+
// Filter out useless linker warnings caused by bugs outside Go.
1347+
// See also cmd/go/internal/work/exec.go's gccld method.
1348+
var save [][]byte
1349+
for _, line := range bytes.SplitAfter(out, []byte("\n")) {
1350+
// golang.org/issue/26073 - Apple Xcode bug
1351+
if bytes.Contains(line, []byte("ld: warning: text-based stub file")) {
1352+
continue
1353+
}
1354+
save = append(save, line)
1355+
}
1356+
out = bytes.Join(save, nil)
1357+
1358+
if len(out) > 0 {
13441359
// always print external output even if the command is successful, so that we don't
13451360
// swallow linker warnings (see https://golang.org/issue/17935).
13461361
ctxt.Logf("%s", out)

0 commit comments

Comments
 (0)