You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using NDK r16 Beta 2 (16.0.4414007-beta2), compiling with clang still uses ld.bfd on aarch64 (aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld is aarch64-linux-android-4.9/prebuilt/darwin-x86_64/aarch64-linux-android/bin/ld.bfd).
This makes -flto fail, but only on ARM64, because the linker does not recognize LLVM bitcode files. LTO works just fine on arm and x86.
I added -Wl,-flto=gold to CMAKE_SHARED_LINKER_FLAGS_RELEASE and it fixed the arm64 build.
FYI, adding that flag breaks the x86 build (which works fine without it) with a bunch of errors like this one:
~/Library/Android/sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/darwin-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin/ld: error: ../../../../src/main/jniLibs/x86/Release/libippicv.a(jmp_icvippiDFTGetSize_C_32fc_as.s.o): relocation R_386_GOTOFF against preemptible symbol icv_ippJumpIndexForMergedLibs cannot be used when making a shared object
First, I gave you the wrong flag. It's -fuse-ld=gold. Second, it's -fuse-ld=gold, not -Wl,-fuse-ld=gold. -Wl flags are passed to the linker. If you've reached the linker, it's too late to choose which linker you want :) -f does very different things to the linker.
BTW, for a lot of Clang flags you can actually find pretty good documentation in the GCC docs. A fortunate side effect of Clang trying to maintain command line compatibility with GCC (though probably also a reason Clang's docs aren't as thorough as they ought to be).
This doesn't actually block LTO any more. The latest Clang LTO works with bfd as well.
Is this true on Windows, too? I'm currently seeing an LLVMgold.dll: error loading plugin error with the bfd linker. To fix that, I have to enable Gold (using -fuse-ld=gold.exe, not -fuse-ld=gold).
iirc I needed to fix gold to do the right thing when searching for LLVMgold (since Windows doesn't use rpath and by default only searches the executable's directory). Maybe we just need the same thing for bfd and can get that in time for r17 beta 2.
The Clang driver is passing an absolute path to LLVMgold.dll to ld.bfd.exe.
I see that LTO works on 32-bit Windows, but not 64-bit Windows. I also see that LLVMgold.dll is provided both as part of the GCC toolchain and as part of the LLVM toolchain. For 32-bit Windows, the copy provided with the GCC toolchain is the wrong architecture -- it's a 64-bit binary.
Activity
DanAlbert commentedon Oct 29, 2017
Add
-fuse-ld=goldto your ldflags.We should probably change the default at this point though. It's been the default in the platform for quite a while now.
nsabovic commentedon Nov 1, 2017
That worked, thanks so much!
I added
-Wl,-flto=goldtoCMAKE_SHARED_LINKER_FLAGS_RELEASEand it fixed the arm64 build.FYI, adding that flag breaks the x86 build (which works fine without it) with a bunch of errors like this one:
DanAlbert commentedon Nov 1, 2017
Really? x86 already defaults to gold.
DanAlbert commentedon Nov 1, 2017
Oh, I see a couple problems.
First, I gave you the wrong flag. It's
-fuse-ld=gold. Second, it's-fuse-ld=gold, not-Wl,-fuse-ld=gold.-Wlflags are passed to the linker. If you've reached the linker, it's too late to choose which linker you want :)-fdoes very different things to the linker.nsabovic commentedon Nov 3, 2017
Now that worked perfectly! Thanks again!
If only Clang's documentation did not look like a Siberian tundra—the flag is listed in there, but not what it does :(
Should I close this?
DanAlbert commentedon Nov 3, 2017
No, I'm going to leave it open to track switching the default. Glad to hear that worked for you though.
DanAlbert commentedon Nov 3, 2017
BTW, for a lot of Clang flags you can actually find pretty good documentation in the GCC docs. A fortunate side effect of Clang trying to maintain command line compatibility with GCC (though probably also a reason Clang's docs aren't as thorough as they ought to be).
nsabovic commentedon Nov 3, 2017
Thanks, and you're right, it's well documented on the gcc side.
[-]ARM64 still uses ld.bfd as main linker with clang, breaks LTO[/-][+]switch aarch64 to ld.gold[/+]DanAlbert commentedon Jan 29, 2018
This doesn't actually block LTO any more. The latest Clang LTO works with bfd as well.
rprichard commentedon Jan 29, 2018
Is this true on Windows, too? I'm currently seeing an
LLVMgold.dll: error loading pluginerror with the bfd linker. To fix that, I have to enable Gold (using-fuse-ld=gold.exe, not-fuse-ld=gold).DanAlbert commentedon Jan 29, 2018
Ugh, that's frustrating. Unfortunately this is a no-go for r17 either way because of https://issuetracker.google.com/70838247.
DanAlbert commentedon Jan 29, 2018
iirc I needed to fix gold to do the right thing when searching for LLVMgold (since Windows doesn't use rpath and by default only searches the executable's directory). Maybe we just need the same thing for bfd and can get that in time for r17 beta 2.
rprichard commentedon Jan 29, 2018
The Clang driver is passing an absolute path to
LLVMgold.dlltold.bfd.exe.I see that LTO works on 32-bit Windows, but not 64-bit Windows. I also see that
LLVMgold.dllis provided both as part of the GCC toolchain and as part of the LLVM toolchain. For 32-bit Windows, the copy provided with the GCC toolchain is the wrong architecture -- it's a 64-bit binary.DanAlbert commentedon May 3, 2018
Still blocked by https://issuetracker.google.com/70838247.
DanAlbert commentedon May 14, 2018
Given that we're now shipping lld, I'm guessing this won't ever happen and we'll just go straight to LLD.
Use gold as linker for arm64
DanAlbert commentedon Oct 19, 2018
Closing in favor of lld.