r360946 - Add Clang shared library with C++ exports
Chris Bieneman via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 20:24:19 PDT 2019
I’ll re-land disabling if PIC is off.
This doesn’t replace the static libraries with object libraries, it just creates an object library target (named obj.${name}) for each static library. That allows the objects to be referenced separately from the archives, so we don’t have to do the -load-all/—whole-archive stuff we do for libLLVM.
-Chris
> On May 16, 2019, at 6:40 PM, Nico Weber <thakis at chromium.org> wrote:
>
> To not keep the build broken over night, and since it's a small change that should be easy to reland, I've reverted this for now in r360973.
>
>> On Thu, May 16, 2019 at 8:52 PM Nico Weber <thakis at chromium.org> wrote:
>> Hello,
>>
>> this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target shouldn't be build in those builds?
>>
>>
>> Also, if I read this right, this makes static libraries for clang always be object libraries. Is that correct? If so, this likely makes the normal clang binary larger and less efficient than before: Normal static libraries only get referenced .o files in them loaded, while all files in object libraries are loaded by the linker. In theory, --gc-sections should drop the ones that aren't needed, but due to static initializers and so on that doesn't always work. (When we moved Chrome's build to GN, the thinking was for a long time that we'd use object libraries instead of static libraries everywhere. Turns out that made the binary 10% larger and slower and we had to paddle back.)
>>
>>
>>
>> [2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn
>> FAILED: lib/libclang_shared.so.9svn
>> ...
>> /usr/bin/ld: tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: relocation R_X86_64_32 against `.rodata._ZZNR4llvm15optional_detail15OptionalStorageIiLb1EE8getValueEvE19__PRETTY_FUNCTION__' can not be used when making a shared object; recompile with -fPIC
>> tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: error adding symbols: Bad value
>> collect2: error: ld returned 1 exit status
>>
>>> On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits <cfe-commits at lists.llvm.org> wrote:
>>> Author: cbieneman
>>> Date: Thu May 16 15:06:07 2019
>>> New Revision: 360946
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=360946&view=rev
>>> Log:
>>> Add Clang shared library with C++ exports
>>>
>>> Summary:
>>> This patch adds a libClang_shared library on *nix systems which exports the entire C++ API. In order to support this on Windows we should really refactor llvm-shlib and share code between the two.
>>>
>>> This also uses a slightly different method for generating the shared library, which I should back-port to llvm-shlib. Instead of linking the static archives and passing linker flags to force loading the whole libraries, this patch creates object libraries for every library (which has no cost in the build system), and link the object libraries.
>>>
>>> Reviewers: tstellar, winksaville
>>>
>>> Subscribers: mgorny, cfe-commits
>>>
>>> Tags: #clang
>>>
>>> Differential Revision: https://reviews.llvm.org/D61909
>>>
>>> Added:
>>> cfe/trunk/tools/clang-shlib/
>>> cfe/trunk/tools/clang-shlib/CMakeLists.txt
>>> cfe/trunk/tools/clang-shlib/clang-shlib.cpp
>>> Modified:
>>> cfe/trunk/cmake/modules/AddClang.cmake
>>> cfe/trunk/tools/CMakeLists.txt
>>>
>>> Modified: cfe/trunk/cmake/modules/AddClang.cmake
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946&r1=360945&r2=360946&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/cmake/modules/AddClang.cmake (original)
>>> +++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019
>>> @@ -81,9 +81,12 @@ macro(add_clang_library name)
>>> )
>>> endif()
>>> if(ARG_SHARED)
>>> - set(ARG_ENABLE_SHARED SHARED)
>>> + set(LIBTYPE SHARED)
>>> + else()
>>> + set(LIBTYPE STATIC OBJECT)
>>> + set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})
>>> endif()
>>> - llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>>> + llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
>>>
>>> if(TARGET ${name})
>>> target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
>>>
>>> Modified: cfe/trunk/tools/CMakeLists.txt
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946&r1=360945&r2=360946&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/tools/CMakeLists.txt (original)
>>> +++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019
>>> @@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)
>>>
>>> add_clang_subdirectory(clang-rename)
>>> add_clang_subdirectory(clang-refactor)
>>> +if(UNIX)
>>> + add_clang_subdirectory(clang-shlib)
>>> +endif()
>>>
>>> if(CLANG_ENABLE_ARCMT)
>>> add_clang_subdirectory(arcmt-test)
>>>
>>> Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946&view=auto
>>> ==============================================================================
>>> --- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)
>>> +++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 15:06:07 2019
>>> @@ -0,0 +1,13 @@
>>> +get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)
>>> +
>>> +foreach (lib ${clang_libs})
>>> + list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
>>> + list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)
>>> +endforeach ()
>>> +
>>> +add_clang_library(clang_shared
>>> + SHARED
>>> + clang-shlib.cpp
>>> + ${_OBJECTS}
>>> + LINK_LIBS
>>> + ${_DEPS})
>>>
>>> Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360946&view=auto
>>> ==============================================================================
>>> --- cfe/trunk/tools/clang-shlib/clang-shlib.cpp (added)
>>> +++ cfe/trunk/tools/clang-shlib/clang-shlib.cpp Thu May 16 15:06:07 2019
>>> @@ -0,0 +1 @@
>>> +// Intentionally empty source file to make CMake happy
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190516/9464f718/attachment-0001.html>
More information about the cfe-commits
mailing list