CMake: Use LDC as (cross-)archiver for static runtime libs#2319
CMake: Use LDC as (cross-)archiver for static runtime libs#2319kinke merged 1 commit intoldc-developers:masterfrom
Conversation
|
|
||
| # Define a 'D' CMake linker language for the static runtime libs, using LDC as archiver. | ||
| # LDC handles (cross-)archiving internally via LLVM and supports LTO objects. | ||
| set(CMAKE_D_CREATE_STATIC_LIBRARY "${LDC_EXE_FULL} -lib -of=<TARGET> <OBJECTS>") |
There was a problem hiding this comment.
LINKER_LANGUAGE D => CMake looks up command template CMAKE_<LANG>_CREATE_STATIC_LIBRARY with known placeholders (<TARGET>, <OBJECTS> etc.). Found via Google, StackOverflow and finally looking up a few things in the default CMake modules.
The alternative would be way uglier, as we'd have to compile the C/ASM files manually, add custom commands for the LDC archiving command lines etc. etc.
|
LLVM's MSVC archiver/lib.exe driver apparently has issues with objects with debuginfos, leading to MS linker warnings when linking against the static debug libs, e.g.: At least with the currently used LLVM 4.0.1. |
|
Tested this pull on native Android/ARM and cross-compiling to Android from linux/x64 and Wine/x64, no problem. I updated #2301 to rely on this instead of the Android NDK's ar/ranlib, let me know if this won't go in soon so I can go back to the NDK there if needed. |
|
Thanks for testing. With the debuginfo issue above for MSVC targets, it can't be enabled by default (yet), so maybe introducing a |
|
Sounds good. |
By default for all non-MSVC targets; overrideable via CMake var RT_ARCHIVE_WITH_LDC. LDC/LLVM handles cross-archiving and LTO objects out of the box.
joakim-noah
left a comment
There was a problem hiding this comment.
Looks good, need this for #2301.
|
It looks like this breaks with llvm 5.0, in a subtle way. If you archive a library once, it works fine. However, if you then go make a change to some file and rebuild the library, any attempt to use it errors out because of repeated symbols in the C/ASM files. Turns out that all the object files have been archived twice, if you run Looking at the contents of the archive produced by llvm 4.0.1 with this pull, it shows all object files at the top-level, no paths. When you modify a file and re-archive, it simply overwrites the old object file. However, with llvm 5.0, it archives the paths too, ie I see this when compiling |
|
IIRC, we use the equivalent of |
Attempt to fix #2309.