Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: showing many ld warnings of "building for macOS, but linking in object file" #33214

Open
avence12 opened this issue Jul 22, 2019 · 18 comments

Comments

@avence12
Copy link

commented Jul 22, 2019

What version of Go are you using (go version)?

$ go version go1.12.7 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

Mac Mojave 10.14.5

Result of go env:

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/avence12/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/avence12/.gvm/pkgsets/go1.12.7/global:/Users/avence12/devel/go"
GOPROXY=""
GORACE=""
GOROOT="/Users/avence12/.gvm/gos/go1.12.7"
GOTMPDIR=""
GOTOOLDIR="/Users/avence12/.gvm/gos/go1.12.7/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-build525129295=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Install and use go1.12.7 by GVM
  2. Get into my project and run go build ./...
  3. The build is successful but seeing lots of ld warning. The same situation when I run go test ./...
  4. When I setup export CGO_ENABLED=0, the warning is gone. However I would like to know how to resolve the issue.

What did you expect to see?

No ld warnings when CGO_ENABLED=1

What did you see instead?

$ go build ./cmd/...
# github.com/avence12/myproj/cmd/client
ld: warning: building for macOS, but linking in object file (/var/folders/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-link-703159202/go.o) built for 
# github.com/avence12/myproj/cmd/server
ld: warning: building for macOS, but linking in object file (/var/folders/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-link-846047020/go.o) built for 
@ianlancetaylor ianlancetaylor changed the title Showing many ld warnings of "building for macOS, but linking in object file" cmd/link: showing many ld warnings of "building for macOS, but linking in object file" Jul 22, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 22, 2019

@ianlancetaylor ianlancetaylor modified the milestones: 1.14, Go1.14 Jul 22, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 22, 2019

Which version of XCode do you have installed?

@thanm

This comment has been minimized.

Copy link
Member

commented Jul 22, 2019

Is that the complete warning (e.g. "built for" and then nothing more)? Wondering if the output got truncated somehow.

@avence12

This comment has been minimized.

Copy link
Author

commented Jul 23, 2019

@ianlancetaylor:
I did not install XCode when I saw the issue. After I install XCode Version 10.2.1, the issue remains.

@thanm:
I add the result of go env and complete warning to origin message. There is nothing after "built for".

@juev

This comment has been minimized.

Copy link

commented Jul 23, 2019

The same issue for me.

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/d.evsyukov/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/d.evsyukov/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/3k/hqxhm_y10vx682dnsbb64l7r0000gp/T/go-build135546081=/tmp/go-build -gno-record-gcc-switches -fno-common"
$ go get -u github.com/saibing/bingo
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/var/folders/3k/hqxhm_y10vx682dnsbb64l7r0000gp/T/go-link-834839606/go.o) built for
@xuhrc

This comment has been minimized.

Copy link

commented Jul 24, 2019

ld: warning: building for macOS, but linking in object file (/var/folders/78/6hfbqt9x3z3bvm41rhn81smhx0t1sf/T/go-link-034794354/go.o) built for

go env:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPROXY="https://goproxy.io"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/78/6hfbqt9x3z3bvm41rhn81smhx0t1sf/T/go-build817734651=/tmp/go-build -gno-record-gcc-switches -fno-common"

same issue for me

The warning disappeared after i installed command line tools beta 6

@thanm

This comment has been minimized.

Copy link
Member

commented Jul 24, 2019

I'm not having any luck reproducing this.

I'm working with a MacOS 10.14.5 macbook, Xcode 10.3, installed go 1.12.7 using "gvm", but when I build the projects above I don't see any warnings.

It might help to know what version of the linker you're working with, since it's the linker issuing the warning.

Please try this small experiment: run clang on a tiny C file to invoke the linker, then using the linker path you see in the output, run "ld -v" to see what version it claims to be:

$ echo "int main() { return 0; }" > small.c
$ clang -v small.c 1> transcript.txt 2>&1
$ fgrep /ld transcript
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -o a.out /var/folders/y1/14s910p95pj3vb71ywd53wk8008r__/T/small-788b80.o -L/usr/local/lib -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/lib/darwin/libclang_rt.osx.a
$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -v

@(#)PROGRAM:ld  PROJECT:ld64-450.3
BUILD 18:16:53 Apr  5 2019
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 10.0.1, (clang-1001.0.46.4) (static support for 22, runtime is 22)
TAPI support using: Apple TAPI version 10.0.1 (tapi-1001.0.4.1)
@juev

This comment has been minimized.

Copy link

commented Jul 24, 2019

$ echo "int main() { return 0; }" > small.c
$ clang -v small.c 1> transcript.txt 2>&1
$ ll
total 16K
-rwxr-xr-x 1 d.evsyukov 4.2K Jul 24 19:16 a.out
-rw-r--r-- 1 d.evsyukov   25 Jul 24 19:16 small.c
-rw-r--r-- 1 d.evsyukov 2.5K Jul 24 19:16 transcript.txt

$ grep /ld transcript.txt
 "/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -o a.out /var/folders/ss/g0zcdcj13p54s6fj2353vlxh0000gn/T/small-f8f73a.o -L/usr/local/lib -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/lib/darwin/libclang_rt.osx.a

$ /Library/Developer/CommandLineTools/usr/bin/ld -v
@(#)PROGRAM:ld  PROJECT:ld64-450.3
BUILD 18:45:16 Apr  4 2019
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 10.0.1, (clang-1001.0.46.4) (static support for 22, runtime is 22)
TAPI support using: Apple TAPI version 10.0.1 (tapi-1001.0.4.1)
@thanm

This comment has been minimized.

Copy link
Member

commented Jul 24, 2019

Thanks @juev . Looks like your linker is more or less the same vintage as mine, so nothing notable there.

I also tried deleting Xcode from my Mac and to just the downloaded command line tools, but that didn't help.

How about this as another possible experiment to try: redo the link with -tmpdir set, which should capture the object files feeding into the external linker, then run 'file' on one of the ones the linker is complaining about to see what it looks like. Demo:

$ cd $GOPATH/src/github.com/saibing/bingo
$ go clean -cache ; rm -f bingo
$ mkdir /tmp/xxx
$ go build -ldflags=-tmpdir=/tmp/xxx .
$ ls /tmp/xxx
000000.o	000005.o	000010.o	000015.o	go.dwarf
000001.o	000006.o	000011.o	000016.o	go.o
000002.o	000007.o	000012.o	000017.o	trivial.c
000003.o	000008.o	000013.o	000018.o
000004.o	000009.o	000014.o	a.out
$ file /tmp/xxx/go.o
/tmp/xxx/go.o: Mach-O 64-bit object x86_64
$
@avence12

This comment has been minimized.

Copy link
Author

commented Jul 25, 2019

@thanm My ld is the same as your version.

$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -v
@(#)PROGRAM:ld  PROJECT:ld64-450.3
BUILD 18:16:53 Apr  5 2019
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
LTO support using: LLVM version 10.0.1, (clang-1001.0.46.4) (static support for 22, runtime is 22)
TAPI support using: Apple TAPI version 10.0.1 (tapi-1001.0.4.1)

Another test:

$ go get  github.com/saibing/bingo
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/var/folders/9n/_tfc4bt12ps45qjyzh40jt1h0000gn/T/go-link-110299481/go.o) built for

$ cd $GOPATH/src/github.com/saibing/bingo
$ go clean -cache ; rm -f bingo
$ mkdir /tmp/xxx
$ go build -ldflags=-tmpdir=/tmp/xxx .
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/tmp/xxx/go.o) built for
$ ls /tmp/xxx
000000.o	000005.o	000010.o	000015.o	go.dwarf
000001.o	000006.o	000011.o	000016.o	go.o
000002.o	000007.o	000012.o	000017.o	trivial.c
000003.o	000008.o	000013.o	000018.o
000004.o	000009.o	000014.o	a.out
$ file /tmp/xxx/go.o
/tmp/xxx/go.o: Mach-O 64-bit object x86_64

One thing may be related, the gcc version:

$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.20.17)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
@juev

This comment has been minimized.

Copy link

commented Jul 25, 2019

Confirmed:

$ go build -v -ldflags=-tmpdir=/tmp/xxx .
golang.org/x/tools/internal/semver
github.com/saibing/bingo/langserver/internal/sys
github.com/saibing/bingo/langserver/internal/diff
github.com/fsnotify/fsevents
golang.org/x/tools/internal/fastwalk
golang.org/x/tools/internal/module
github.com/sourcegraph/go-lsp
github.com/sourcegraph/jsonrpc2
golang.org/x/tools/go/ast/inspector
golang.org/x/tools/go/cfg
golang.org/x/tools/go/analysis
golang.org/x/tools/go/analysis/passes/internal/analysisutil
golang.org/x/tools/go/ast/astutil
github.com/saibing/bingo/langserver/internal/span
github.com/saibing/bingo/langserver/internal/util
golang.org/x/tools/go/internal/gcimporter
golang.org/x/tools/go/analysis/passes/asmdecl
golang.org/x/tools/go/analysis/passes/inspect
golang.org/x/tools/go/analysis/passes/assign
golang.org/x/tools/go/analysis/passes/atomic
golang.org/x/tools/go/analysis/passes/atomicalign
golang.org/x/tools/go/analysis/passes/bools
golang.org/x/tools/go/analysis/passes/buildtag
golang.org/x/tools/go/analysis/passes/cgocall
golang.org/x/tools/go/analysis/passes/composite
golang.org/x/tools/go/analysis/passes/copylock
golang.org/x/tools/go/analysis/passes/httpresponse
golang.org/x/tools/go/analysis/passes/loopclosure
golang.org/x/tools/go/analysis/passes/nilfunc
golang.org/x/tools/go/analysis/passes/shift
golang.org/x/tools/go/analysis/passes/stdmethods
golang.org/x/tools/go/analysis/passes/structtag
golang.org/x/tools/go/analysis/passes/tests
golang.org/x/tools/go/analysis/passes/unreachable
golang.org/x/tools/go/analysis/passes/unsafeptr
golang.org/x/tools/go/analysis/passes/unusedresult
golang.org/x/tools/go/internal/packagesdriver
golang.org/x/tools/internal/gopathwalk
github.com/saibing/bingo/langserver/internal/protocol
github.com/slimsag/godocmd
github.com/sourcegraph/go-lsp/lspext
golang.org/x/tools/go/types/typeutil
github.com/saibing/bingo/langserver/internal/refs
golang.org/x/tools/go/analysis/passes/ctrlflow
golang.org/x/tools/go/analysis/passes/unmarshal
golang.org/x/tools/go/analysis/passes/printf
golang.org/x/tools/go/analysis/passes/lostcancel
golang.org/x/tools/go/gcexportdata
golang.org/x/tools/go/packages
golang.org/x/tools/internal/imports
golang.org/x/tools/imports
github.com/saibing/bingo/langserver/internal/source
github.com/saibing/bingo/langserver/internal/cache
github.com/saibing/bingo/langserver
github.com/saibing/bingo
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/tmp/xxx/go.o) built for
@juev

This comment has been minimized.

Copy link

commented Jul 25, 2019

I removed go (installed from brew), then install it from gvm.

After this I have the same issue with version 1.12.7 from binary distribution. But when I try compile again, I had:

$ gvm install go1.12.7 -B
Installing go1.12.7 from binary source

$ gvm use go1.12.7
Now using version go1.12.7

$ go version
go version go1.12.7 darwin/amd64

$ cd $GOPATH/src/github.com/saibing/bingo

$ go clean -cache ; rm -f bingo

$ go get -u github.com/saibing/bingo
go: finding github.com/mattn/go-isatty v0.0.8
go: finding github.com/sourcegraph/go-lsp latest
go: finding golang.org/x/crypto latest
go: finding golang.org/x/net latest
go: finding golang.org/x/sys latest
go: finding golang.org/x/tools latest
go: finding gopkg.in/inconshreveable/log15.v2 latest
go: finding golang.org/x/text v0.3.2
go: finding github.com/mattn/go-colorable v0.1.2
go: finding github.com/sourcegraph/jsonrpc2 latest
go: finding github.com/slimsag/godocmd latest
go: finding golang.org/x/net v0.0.0-20190620200207-3b0461eec859
go: finding golang.org/x/sync v0.0.0-20190423024810-112230192c58
go: finding github.com/stretchr/objx v0.2.0
go: finding golang.org/x/sys v0.0.0-20190412213103-97732733099d
go: finding golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
go: finding golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e
go: finding golang.org/x/sync latest
go: downloading github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a
go: downloading golang.org/x/tools v0.0.0-20190724185037-8aa4eac1a7c1
go: extracting github.com/sourcegraph/jsonrpc2 v0.0.0-20190106185902-35a74f039c6a
go: extracting golang.org/x/tools v0.0.0-20190724185037-8aa4eac1a7c1
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/var/folders/3k/hqxhm_y10vx682dnsbb64l7r0000gp/T/go-link-683476025/go.o) built for

$ go get -u github.com/saibing/bingo
go: finding github.com/sourcegraph/go-lsp latest
go: finding github.com/sourcegraph/jsonrpc2 latest
go: finding golang.org/x/tools latest
go: finding golang.org/x/sync latest
go: finding golang.org/x/crypto latest
go: finding golang.org/x/sys latest
go: finding github.com/slimsag/godocmd latest
go: finding golang.org/x/net latest
go: finding gopkg.in/inconshreveable/log15.v2 latest
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/var/folders/3k/hqxhm_y10vx682dnsbb64l7r0000gp/T/go-link-683476025/go.o) built for

$ go get -u github.com/saibing/bingo
go: finding github.com/sourcegraph/go-lsp latest
go: finding github.com/sourcegraph/jsonrpc2 latest
go: finding golang.org/x/sys latest
go: finding golang.org/x/net latest
go: finding golang.org/x/crypto latest
go: finding gopkg.in/inconshreveable/log15.v2 latest
go: finding github.com/slimsag/godocmd latest
go: finding golang.org/x/sync latest
go: finding golang.org/x/tools latest
# github.com/saibing/bingo
ld: warning: building for macOS, but linking in object file (/var/folders/3k/hqxhm_y10vx682dnsbb64l7r0000gp/T/go-link-683476025/go.o) built for

$ go clean -cache ; rm -f bingo

$ go get -u github.com/saibing/bingo
go: finding github.com/sourcegraph/go-lsp latest
go: finding github.com/sourcegraph/jsonrpc2 latest
go: finding golang.org/x/tools latest
go: finding golang.org/x/sys latest
go: finding golang.org/x/net latest
go: finding gopkg.in/inconshreveable/log15.v2 latest
go: finding golang.org/x/sync latest
go: finding golang.org/x/crypto latest
go: finding github.com/slimsag/godocmd latest

This is strange, but after several compilation and clean cache issue was gone.
I repeat again:

$ go get -u github.com/saibing/bingo
go: finding github.com/sourcegraph/go-lsp latest
go: finding github.com/sourcegraph/jsonrpc2 latest
go: finding golang.org/x/sys latest
go: finding golang.org/x/tools latest
go: finding gopkg.in/inconshreveable/log15.v2 latest
go: finding golang.org/x/net latest
go: finding golang.org/x/crypto latest
go: finding golang.org/x/sync latest
go: finding github.com/slimsag/godocmd latest

$ go get -u github.com/saibing/bingo
go: finding github.com/sourcegraph/go-lsp latest
go: finding github.com/sourcegraph/jsonrpc2 latest
go: finding golang.org/x/sys latest
go: finding golang.org/x/net latest
go: finding golang.org/x/tools latest
go: finding golang.org/x/crypto latest
go: finding gopkg.in/inconshreveable/log15.v2 latest
go: finding github.com/slimsag/godocmd latest
go: finding golang.org/x/sync latest

With this package it all ok.

And with other packages too.

$ go get -u github.com/cube2222/octosql/cmd/octosql
go: finding github.com/cube2222/octosql/cmd/octosql latest
go: finding github.com/cube2222/octosql/cmd latest
go: finding github.com/cube2222/octosql v0.1.1
go: downloading github.com/cube2222/octosql v0.1.1
go: extracting github.com/cube2222/octosql v0.1.1
go: finding github.com/go-redis/redis v6.15.2+incompatible
go: finding github.com/shurcooL/sanitized_anchor_name v1.0.0
go: finding github.com/pkg/errors v0.8.1
go: finding github.com/go-sql-driver/mysql v1.4.1
go: finding github.com/kr/pretty v0.1.0
go: finding github.com/onsi/gomega v1.5.0
go: finding github.com/bradleyjkemp/memmap v0.2.2
go: finding github.com/mattn/go-runewidth v0.0.4
go: finding golang.org/x/net v0.0.0-20190522155817-f3200d17e092
go: finding gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127
go: finding golang.org/x/net latest
go: finding github.com/mitchellh/hashstructure v1.0.0
go: finding github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560
go: finding github.com/russross/blackfriday v2.0.0+incompatible
go: finding google.golang.org/appengine v1.5.0
go: finding github.com/spf13/cobra v0.0.5
go: finding golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e
go: finding github.com/golang/protobuf v1.3.1
go: finding golang.org/x/sys latest
go: finding gopkg.in/check.v1 latest
go: finding golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f
go: finding gopkg.in/yaml.v2 v2.2.1
go: finding gopkg.in/fsnotify.v1 v1.4.7
go: finding golang.org/x/crypto latest
go: finding github.com/hpcloud/tail v1.0.0
go: finding golang.org/x/sync latest
go: finding github.com/shurcooL/markdownfmt v0.0.0-20190409060426-3438a10682f5
go: finding github.com/shurcooL/go latest
go: finding golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
go: finding gopkg.in/yaml.v2 v2.2.2
go: finding google.golang.org/appengine v1.6.1
go: finding gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: finding github.com/golang/protobuf v1.3.2
go: finding github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
go: finding github.com/bradleyjkemp/cupaloy v2.3.0+incompatible
go: finding github.com/golang/protobuf v1.2.0
go: finding github.com/shurcooL/markdownfmt latest
go: finding github.com/spf13/viper v1.3.2
go: finding github.com/onsi/ginkgo v1.6.0
go: finding github.com/bradleyjkemp/memviz v0.2.2
go: finding github.com/kr/text v0.1.0
go: finding github.com/russross/blackfriday v1.5.3-0.20190124082335-a477dd164691
go: finding github.com/mitchellh/go-homedir v1.1.0
go: finding gopkg.in/tomb.v1 latest
go: finding golang.org/x/net v0.0.0-20180724234803-3673e40ba225
go: finding github.com/xwb1989/sqlparser latest
go: finding github.com/spf13/pflag v1.0.3
go: finding github.com/inconshreveable/mousetrap v1.0.0
go: finding github.com/olekukonko/tablewriter v0.0.1
go: finding github.com/spf13/viper v1.4.0
go: finding github.com/onsi/ginkgo v1.8.0
go: finding github.com/magiconair/properties v1.8.0
go: finding github.com/BurntSushi/toml v0.3.1
go: finding github.com/mitchellh/mapstructure v1.1.2
go: finding github.com/spf13/cast v1.3.0
go: finding github.com/coreos/go-semver v0.2.0
go: finding github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77
go: finding golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
go: finding github.com/stretchr/testify v1.2.2
go: finding github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8
go: finding github.com/pelletier/go-toml v1.2.0
go: finding golang.org/x/tools latest
go: finding github.com/magiconair/properties v1.8.1
go: finding github.com/lib/pq v1.0.0
go: finding github.com/coreos/go-etcd v2.0.0+incompatible
go: finding github.com/prometheus/client_golang v0.9.3
go: finding github.com/hashicorp/hcl v1.0.0
go: finding github.com/coreos/go-semver v0.3.0
go: finding github.com/xordataexchange/crypt v0.0.2
go: finding github.com/kr/pty v1.1.1
go: finding github.com/pelletier/go-toml v1.4.0
go: finding go.uber.org/atomic v1.4.0
go: finding github.com/gogo/protobuf v1.2.1
go: finding github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef
go: finding github.com/lib/pq v1.2.0
go: finding github.com/ugorji/go/codec v1.1.7
go: finding github.com/spf13/jwalterweatherman v1.0.0
go: finding github.com/prometheus/client_golang v1.0.0
go: finding github.com/coreos/bbolt v1.3.2
go: finding github.com/dgrijalva/jwt-go v3.2.0+incompatible
go: finding github.com/kr/pty v1.1.8
go: finding github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
go: finding github.com/cpuguy83/go-md2man v1.0.10
go: finding github.com/prometheus/common v0.4.0
go: finding github.com/golang/groupcache latest
go: finding github.com/google/btree v1.0.0
go: finding golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
go: finding github.com/spf13/jwalterweatherman v1.1.0
go: finding github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5
go: finding github.com/coreos/bbolt v1.3.3
go: finding github.com/prometheus/tsdb v0.7.1
go: finding github.com/ugorji/go v1.1.4
go: finding golang.org/x/time latest
go: finding github.com/ugorji/go v1.1.7
go: finding github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
go: finding github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
go: finding golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a
go: finding github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084
go: finding github.com/jonboulle/clockwork v0.1.0
go: finding go.uber.org/multierr v1.1.0
go: finding github.com/prometheus/common v0.6.0
go: finding github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
go: finding github.com/tmc/grpc-websocket-proxy latest
go: finding github.com/coreos/etcd v3.3.10+incompatible
go: finding github.com/sirupsen/logrus v1.2.0
go: finding github.com/coreos/go-systemd latest
go: finding github.com/prometheus/client_model latest
go: finding github.com/prometheus/procfs v0.0.3
go: finding github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
go: finding github.com/prometheus/procfs v0.0.2
go: finding golang.org/x/net v0.0.0-20190613194153-d28f0bde5980
go: finding github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
go: finding go.uber.org/zap v1.10.0
go: finding github.com/soheilhy/cmux v0.1.4
go: finding github.com/prometheus/tsdb v0.10.0
go: finding github.com/gogo/protobuf v1.1.1
go: finding github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
go: finding github.com/json-iterator/go v1.1.6
go: finding github.com/beorn7/perks v1.0.0
go: finding gopkg.in/alecthomas/kingpin.v2 v2.2.6
go: finding github.com/sirupsen/logrus v1.4.2
go: finding github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d
go: finding github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce
go: finding github.com/spf13/afero v1.1.2
go: finding github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf
go: finding go.etcd.io/bbolt v1.3.2
go: finding github.com/kr/logfmt latest
go: finding github.com/google/go-cmp v0.3.0
go: finding golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
go: finding github.com/json-iterator/go v1.1.7
go: finding github.com/prometheus/client_golang v0.9.1
go: finding google.golang.org/grpc v1.21.0
go: finding github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223
go: finding github.com/alecthomas/units latest
go: finding golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33
go: finding golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
go: finding github.com/spf13/afero v1.2.2
go: finding go.etcd.io/bbolt v1.3.3
go: finding golang.org/x/crypto v0.0.0-20180904163835-0709b304e793
go: finding github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2
go: finding github.com/matttproud/golang_protobuf_extensions v1.0.1
go: finding github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954
go: finding github.com/prometheus/common v0.4.1
go: finding github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6
go: finding github.com/mwitkow/go-conntrack latest
go: finding github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
go: finding github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742
go: finding github.com/go-logfmt/logfmt v0.4.0
go: finding github.com/dgryski/go-sip13 latest
go: finding golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
go: finding github.com/stretchr/objx v0.1.1
go: finding google.golang.org/grpc v1.22.0
go: finding golang.org/x/net v0.0.0-20190603091049-60506f45cf65
go: finding golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8
go: finding github.com/xiang90/probing latest
go: finding golang.org/x/net v0.0.0-20190311183353-d8887717615a
go: finding github.com/cespare/xxhash v1.1.0
go: finding golang.org/x/sys v0.0.0-20190606165138-5da285871e9c
go: finding github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421
go: finding golang.org/x/sys v0.0.0-20190422165155-953cdadca894
go: finding github.com/grpc-ecosystem/grpc-gateway v1.9.0
go: finding github.com/armon/consul-api latest
go: finding golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
go: finding github.com/modern-go/reflect2 v1.0.1
go: finding github.com/coreos/pkg latest
go: finding github.com/google/go-cmp v0.2.0
go: finding golang.org/x/tools v0.0.0-20190311212946-11955173bddd
go: finding github.com/golang/mock v1.1.1
go: finding github.com/pkg/errors v0.8.0
go: finding github.com/oklog/ulid v1.3.1
go: finding github.com/modern-go/concurrent latest
go: finding golang.org/x/oauth2 latest
go: finding github.com/go-kit/kit v0.8.0
go: finding github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
go: finding github.com/grpc-ecosystem/grpc-gateway v1.9.5
go: finding github.com/ghodss/yaml v1.0.0
go: finding github.com/kisielk/errcheck v1.1.0
go: finding github.com/creack/pty v1.1.7
go: finding github.com/golang/mock v1.3.1
go: finding gopkg.in/resty.v1 v1.12.0
go: finding github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af
go: finding github.com/golang/glog latest
go: finding google.golang.org/grpc v1.19.0
go: finding github.com/go-kit/kit v0.9.0
go: finding github.com/google/gofuzz v1.0.0
go: finding github.com/kisielk/errcheck v1.2.0
go: finding golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b
go: finding golang.org/x/net v0.0.0-20181220203305-927f97764cc3
go: finding golang.org/x/tools v0.0.0-20180221164845-07fd8470d635
go: finding github.com/konsorten/go-windows-terminal-sequences v1.0.1
go: finding cloud.google.com/go v0.26.0
go: finding github.com/russross/blackfriday v1.5.2
go: finding golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3
go: finding github.com/rogpeppe/fastuuid v1.2.0
go: finding github.com/go-logfmt/logfmt v0.3.0
go: finding golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3
go: finding github.com/client9/misspell v0.3.4
go: finding golang.org/x/net v0.0.0-20180826012351-8a410e7b638d
go: finding golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135
go: finding github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
go: finding github.com/konsorten/go-windows-terminal-sequences v1.0.2
go: finding golang.org/x/lint latest
go: finding golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5
go: finding github.com/julienschmidt/httprouter v1.2.0
go: finding github.com/OneOfOne/xxhash v1.2.2
go: finding honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099
go: finding golang.org/x/sync v0.0.0-20181108010431-42b317875d0f
go: finding cloud.google.com/go v0.34.0
go: finding cloud.google.com/go v0.43.0
go: finding golang.org/x/tools v0.0.0-20190425150028-36563e24a262
go: finding golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e
go: finding honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc
go: finding github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc
go: finding google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8
go: finding github.com/spaolacci/murmur3 v1.1.0
go: finding golang.org/x/sys v0.0.0-20180830151530-49385e6e1522
go: finding google.golang.org/appengine v1.1.0
go: finding github.com/OneOfOne/xxhash v1.2.5
go: finding github.com/kisielk/gotool v1.0.0
go: finding honnef.co/go/tools v0.0.0-2019.2.1
go: finding github.com/alecthomas/template latest
go: finding github.com/golang/snappy v0.0.1
go: finding golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563
go: finding google.golang.org/appengine v1.4.0
go: finding golang.org/x/tools v0.0.0-20190114222345-bf090417da8b
go: finding gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7
go: finding golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0
go: finding google.golang.org/genproto v0.0.0-20190716160619-c506a9f90610
go: finding google.golang.org/api v0.7.0
go: finding rsc.io/binaryregexp v0.2.0
go: finding github.com/google/martian v2.1.0+incompatible
go: finding github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024
go: finding golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522
go: finding go.opencensus.io v0.22.0
go: finding google.golang.org/grpc v1.21.1
go: finding github.com/coreos/etcd v3.3.13+incompatible
go: finding golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0
go: finding github.com/googleapis/gax-go/v2 v2.0.5
go: finding github.com/jstemmer/go-junit-report latest
go: finding honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a
go: finding github.com/google/pprof v0.0.0-20190515194954-54271f7e092f
go: finding golang.org/x/exp latest
go: finding golang.org/x/sys v0.0.0-20190312061237-fead79001313
go: finding github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802
go: finding golang.org/x/image v0.0.0-20190227222117-0694c2d4d067
go: finding golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09
go: finding golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846
go: finding google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb
go: finding golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6
go: finding golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd
go: finding google.golang.org/grpc v1.20.1
go: finding golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c
go: finding cloud.google.com/go v0.38.0
go: finding github.com/google/pprof latest
go: finding google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873
go: finding github.com/BurntSushi/xgb latest
go: finding go.opencensus.io v0.21.0
go: finding google.golang.org/genproto latest
go: finding golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
go: finding golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2
go: finding google.golang.org/api v0.4.0
go: finding golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f
go: finding golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6
go: finding honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a
go: finding github.com/golang/mock v1.2.0
go: finding golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
go: finding github.com/hashicorp/golang-lru v0.5.1
go: finding golang.org/x/tools v0.0.0-20190226205152-f727befe758c
go: finding golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c
go: finding golang.org/x/exp v0.0.0-20190121172915-509febef88a4
go: finding google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7
go: finding github.com/googleapis/gax-go/v2 v2.0.4
go: finding github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57
go: finding golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
go: finding golang.org/x/mobile latest
go: finding golang.org/x/image latest
go: finding golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b
go: finding golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961
go: finding github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c
go: finding golang.org/x/mod v0.1.0
go: finding golang.org/x/tools v0.0.0-20190312170243-e65039ee4138
go: finding golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8
go: finding github.com/hashicorp/golang-lru v0.5.0
go: finding google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19
go: finding golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529
go: downloading github.com/spf13/cobra v0.0.5
go: downloading github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
go: downloading github.com/go-sql-driver/mysql v1.4.1
go: downloading github.com/lib/pq v1.2.0
go: downloading github.com/go-redis/redis v6.15.2+incompatible
go: downloading github.com/pkg/errors v0.8.1
go: downloading golang.org/x/net v0.0.0-20190724013045-ca1201d0de80
go: downloading gopkg.in/yaml.v2 v2.2.2
go: downloading github.com/olekukonko/tablewriter v0.0.1
go: downloading github.com/mitchellh/hashstructure v1.0.0
go: extracting github.com/pkg/errors v0.8.1
go: extracting github.com/olekukonko/tablewriter v0.0.1
go: extracting github.com/go-sql-driver/mysql v1.4.1
go: extracting github.com/mitchellh/hashstructure v1.0.0
go: extracting github.com/lib/pq v1.2.0
go: extracting gopkg.in/yaml.v2 v2.2.2
go: downloading github.com/mattn/go-runewidth v0.0.4
go: extracting github.com/go-redis/redis v6.15.2+incompatible
go: extracting github.com/spf13/cobra v0.0.5
go: extracting github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
go: extracting github.com/mattn/go-runewidth v0.0.4
go: downloading github.com/spf13/pflag v1.0.3
go: extracting github.com/spf13/pflag v1.0.3
go: extracting golang.org/x/net v0.0.0-20190724013045-ca1201d0de80

one more thing. go version from homebrew is more silence as go version from binary source.

@thanm

This comment has been minimized.

Copy link
Member

commented Jul 25, 2019

I tried looking at the Apple sources for the linker, but unfortunately they don't seem to have released source code for this version of the linker. The closest I could find was version 409; in that source base there is a somewhat similar error message here at line 2181 but I don't think this is the scenario: from looking at the code that only triggers when using bitcode, and if it does trigger it's a fatal error and not a warning. Too bad we don't have up-to-date source to look at.

@avence12

This comment has been minimized.

Copy link
Author

commented Jul 29, 2019

@juev I cannot reproduce your case, bad luck to me :(

@thanm thanks for investigation. I found a workaround to eliminate the warning:

  1. Go to https://developer.apple.com/download/more/
  2. Download and install Command Line Tools (macOS 10.14) for Xcode 10.1
  3. Downgrade gcc to 10.0.0 and no more ld warning!
  4. (Optional) You can then upgrade to latest version - Command Line Tools (macOS 10.14) for Xcode 10.3 which is released on Jul 22. It works like a charm.
$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
@caseylucas

This comment has been minimized.

Copy link

commented Aug 7, 2019

I was having the same problem:

ld: warning: building for macOS, but linking in object file (/var/folders/fm/l0kfkxsn7lqgl9wdwtz_5lk00000gn/T/go-link-305394611/go.o) built for

when using:

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 11.0.0.0.1.1559496560
volume: /
location: /
install-time: 1559652597
groups: com.apple.FindSystemFiles.pkg-group

After upgrading to "Command Line Tools for Xcode 11 Beta 5" (available at https://developer.apple.com/download/more/) the problem went away:

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 11.0.0.0.1.1564155526
volume: /
location: /
install-time: 1565197651
groups: com.apple.FindSystemFiles.pkg-group
@thanm

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

@avence12 , @caseylucas thanks for finding those workarounds.

@oshankkumar

This comment has been minimized.

Copy link

commented Aug 30, 2019

I am also facing a similar issue

ld: warning: building for macOS, but linking in object file (/var/folders/kr/2n4cw21x2rb76jw6ln6qprdw0000gn/T/go-link-005534797/go.o) built for

oshankkumar@Oshanks-MacBook-Pro:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/oshankkumar/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/oshankkumar/Go-Workspace"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.5/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.5/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kr/2n4cw21x2rb76jw6ln6qprdw0000gn/T/go-build929797784=/tmp/go-build -gno-record-gcc-switches -fno-common"
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@jacob-carlborg

This comment has been minimized.

Copy link

commented Oct 12, 2019

I ran into the same issue with the D compiler.

The issue is that the linker is looking for a load command in each object file which contains the platform, platform version and SDK version. Clang outputs this load command but the D compiler doesn't. I'm guessing the Go compiler isn't outputting this load command either. I'm guessing the output looks cut off because the linker doesn't find this load command and therefore prints nothing.

I'm guessing the linker is doing this to verify that the all the object files being linked are compatible. The linker can also make sure that all features are supported by the target platform. For example, if thread local storage are being used but targeting macOS 10.6 (TLS was added in 10.7) the linker will fail to link the executable.

Have a look at the build_version_command struct in the mach-o/loader.h header file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.