-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
Comments
CC @randall77 @thanm |
Which version of XCode do you have installed? |
Is that the complete warning (e.g. "built for" and then nothing more)? Wondering if the output got truncated somehow. |
@ianlancetaylor: @thanm: |
The same issue for me.
|
same issue for me
|
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) |
|
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 $ |
@thanm My ld is the same as your version.
Another test:
One thing may be related, the
|
Confirmed:
|
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:
This is strange, but after several compilation and clean cache issue was gone.
With this package it all ok. And with other packages too.
one more thing. go version from homebrew is more silence as go version from binary source. |
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. |
@juev I cannot reproduce your case, bad luck to me :( @thanm thanks for investigation. I found a workaround to eliminate the warning:
$ 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 |
I was having the same problem:
when using:
After upgrading to "Command Line Tools for Xcode 11 Beta 5" (available at https://developer.apple.com/download/more/) the problem went away:
|
@avence12 , @caseylucas thanks for finding those workarounds. |
I am also facing a similar issue
|
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 |
I see something similar. still looking for the main cause! $ sw_vers
ProductName: macOS
ProductVersion: 13.2
BuildVersion: 22D49
$ go version
go version go1.19 darwin/amd64
# command-line-arguments
ld: warning: -no_pie is deprecated when targeting new OS versions
ld: warning: non-standard -pagezero_size is deprecated when targeting macOS 13.0 or later |
What version of Go are you using (
go version
)?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
:What did you do?
go build ./...
go test ./...
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?
The text was updated successfully, but these errors were encountered: