-
Notifications
You must be signed in to change notification settings - Fork 258
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
NDK link-time optimization fails missing llvmgold.so, but contains llvmgold.dylib #108
Comments
This is using clang 3.8. |
@stephenhines do we just configure something assuming everything is Linux when we build clang, or does upstream clang actually have the wrong? Maybe it's trying |
We do only target baseline Linux for our configuration (multiple layers of config.h), so perhaps this is a misconfiguration issue. I am not sure whether we will update the existing configuration logic now that we are switching to a more upstream-like build process. |
https://android-review.googlesource.com/233868 should be the fix for this. In the meantime, you might be able to workaround this by symlinking to a .so filename (i.e. LLVMGold.so -> LLVMGold.dylib in that directory). |
Thanks! That got me slightly farther along, but the linker now fails with an inability to recognize the format of the
If I had to guess it's because |
I have the same issue. Or to be more specific:
|
On Windows if I specify
|
The Windows issue is also covered by the fix @stephenhines posted. Given the "file format not recognized" issues though, that probably isn't sufficient. |
@JakeWharton, @kneth -- are you 100% sure that the linker being used for your build is ld.gold and not ld.bfd? Looking at the default for prebuilts on the platform it looks like "ld" defaults to gold for linux but bfd for darwin/aarch64. |
I have tried with R12 today - using Linux (well, Ubuntu 14.04 under vagrant/OS X). I am able to compile and link but something is wrong with the produced |
After creating symlinks as @stephenhines suggested, I now get following linker errors:
for every static library in my project and
for every single symbol in my entire code. When disabling LTO or when using GCC, project compiles without errors. Something is obviously wrong with clang. |
I've seen this happen before when |
I can confirm that This happens with both |
This confuses me a lot because 14 days ago I reported issue #137 and after suggestions from @DanAlbert, I've managed to enable LTO for clang on one of my projects (without symlinks suggested by @stephenhines). This means that either then I had a dirty build (actually built with gcc and then forgot to clean after changing compiler) or I was using NDK older than Can anyone else reproduce this issue on MacOS X with their project? |
I reproduced the same error on ArchLinux using NDK r12b, so this is not MacOSX-specific error (I mean |
@DoDoENT I don't recall the actual error message but it sounds like you have reach the same conclusion as me :-( |
I have "no archive symbol table" error too So looks like linker is taken from gcc 4.9 toolchain, but my toolchain is 'clang' |
This issue is also present in r13. @ahyangyi, setting |
I've also tried configuring cmake to use GCC instead of clang and then I get following output for each compilation unit:
And linker fails with undefined reference to each and every symbol in the code. BTW, I double checked that linker command line contains |
Our basic sample builds with r13b (might have worked earlier, don't have r12 on this machine atm), albeit not out of the box. It looks like the only step necessary (that isn't also necessary on Linux) is that I had to The remaining issues are caused by arm64 still defaulting to ld.bfd, and gold not being supported at all for mips/mips64. Example from #242 (comment) # Gold does not support mips or mips64, but gold is needed for LTO with Clang.
ifeq (,$(filter $(TARGET_ARCH_ABI),mips mips64)
LOCAL_CFLAGS += -flto
LOCAL_LDFLAGS := -flto -fuse-ld=gold
endif You'll have to ask someone else how to write that for gradle :) @stephenhines: can you get the |
This has no chance of making r14, because we are having trouble stabilizing even the latest Clang currently for the platform, and we won't deploy again until that happens. I also still don't understand the actual problem here, so someone who has a better clue on Windows (and a working Windows environment) might have a better chance of resolving this. |
https://github.com/llvm-mirror/clang/blob/master/lib/Driver/Tools.cpp#L2155 is the problem, thanks to some help from Dan. We can fix this in upstream, but he might be able to just alter the filenames to get a quicker fix out. |
QA started working on beta 1 this morning, so unfortunately we just missed that, but I'll have a hack (seems we can just ship with as LLVMgold.so and it'll be technically wrong but work fine) for this in beta 2. |
Well, just making symlink does not work for projects that have static libs. Here is the minimum example project which demonstrates the issue @kneth, @vvaldik and I have. So, when LTO is enabled and gold is used, I get following error:
The example is minimal modification of JNI hello project which is created by Android Studio when creating new project and enabling C++ support. |
Ah, that's right. Sorry, there's quite a lot in this thread and I missed that part in my re-read. I'll try to find some time to poke at that today. Some gradle/NDK mismatch issues came up in testing, so I may end up getting the symlinks into beta 1 anyway. If I can find a workaround for the static library issue in time I'll do the same for that. |
Okay, the static library issue reproduces even on Linux. I think I should have time to look at this today. |
Expanded our test case to catch this: https://android-review.googlesource.com/307477 |
Any progress on this? |
Yes. It seems that we need to use the LLVMgold.so plugin for I haven't tested this in the NDK yet, but it looks straightforward. |
Fix is up for review: https://android-review.googlesource.com/c/318721/ I'll cherry-pick into r14 for beta 2 once that gets approved. |
@DanAlbert, this change only refers to ndk-build. What about CMake toolchain? Will it work there too? |
I was thinking that a non-android cmake project would need to modify it's CMakeLists.txt file to make it work anyway, and in general our goal is to just match a typical CMake use case, but it seems that in a non-Android case the gold plugin actually gets installed to a location that ar will automatically look in and load from, so I think we can actually do better than the fix I made yesterday. Working on something now. |
Okay, better implementation that is build-system agnostic: https://android-review.googlesource.com/c/319310/ |
(plus a cmake test) |
Alright, fixes are in r14. |
We previously hacked this up directly in the prebuilts directory. Rather than continuing to do that, fix it in the build. Test: ./run_tests.py --filter flto --abi armeabi-v7a Test: ./run_tests.py --filter flto --abi armeabi-v7a --toolchain 4.9 Bug: android/ndk#108 Change-Id: Ib3f68d5a4768e142153441415505b2ff29933848
This gets LTO working for Clang on the supported hosts (no Windows support yet) and targets (we don't have gold for MIPS). This also switches us to the small code model when building executables for non-Intel targets (to match the PIC options). Test: ./validate.py --filter flto Bug: android/ndk#108 Change-Id: I465e475282d17b2137dcebcbab53e53b9372c837 (cherry picked from commit 95d6a33)
ar will automatically load any plugins that are installed to ../lib/bfd-plugins. Rather than needing to fix all of our build systems, we can make LTO Just Work if we copy the gold plugin (and its dependencies) into the binutils directory. I've also added a test for cmake LTO. Test: ./validate.py --filter flto Bug: android/ndk#108 Change-Id: I1db61b8ef3405474c64ff20478daa86ca41ab3b3 (cherry picked from commit ec60de8)
Yes, Darwin binaries should be .dylib, but the original LTO code that was submitted to LLVM apparently didn't know that so it `dlopen`s the .so even on Darwin and Windows. LTO on Darwin somewhat works (works for shared libraries, anyway) if we just rename it, so do that until we can fix LLVM correctly. Test: ndk/run_tests.py --filter flto Bug: android/ndk#108 Change-Id: I01dc60da6431e9730dec352f80c04563fbe5e8d2
This gets LTO working for Clang on the supported hosts (no Windows support yet) and targets (we don't have gold for MIPS). This also switches us to the small code model when building executables for non-Intel targets (to match the PIC options). Test: ./validate.py --filter flto Bug: android/ndk#108 Change-Id: I465e475282d17b2137dcebcbab53e53b9372c837
ar will automatically load any plugins that are installed to ../lib/bfd-plugins. Rather than needing to fix all of our build systems, we can make LTO Just Work if we copy the gold plugin (and its dependencies) into the binutils directory. I've also added a test for cmake LTO. Test: ./validate.py --filter flto Bug: android/ndk#108 Change-Id: I1db61b8ef3405474c64ff20478daa86ca41ab3b3
I'm attempting to add
-flto
for link-time optimization to mycFlags
andldFlags
(using the new Gradle experimental plugin) but receiving a failure to loadLLVMgold.so
at link time:A quick look into the NDK reveals that the
lib64/
folder contains anLLVMgold.dylib
file, but not the.so
:Is the
.so
missing, or is there a different way to enable LTO that uses this dynamic lib instead?The text was updated successfully, but these errors were encountered: