<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><span style="background-color: rgba(255, 255, 255, 0);">I’ll re-land disabling if PIC is off.</span><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">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.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">-Chris</span></div><div dir="ltr"><br>On May 16, 2019, at 6:40 PM, Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">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.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 16, 2019 at 8:52 PM Nico Weber <<a href="mailto:thakis@chromium.org">thakis@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>this breaks building with -DLLVM_ENABLE_PIC=OFF. Maybe the new target shouldn't be build in those builds?</div><div><br></div><div><br></div><div>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.)</div><div><br></div><div><br></div><div><div><br></div><div>[2523/2887] Linking CXX shared library lib/libclang_shared.so.9svn<br>FAILED: lib/libclang_shared.so.9svn <br>...</div><div>/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<br>tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Attributes.cpp.o: error adding symbols: Bad value<br>collect2: error: ld returned 1 exit status<br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 16, 2019 at 6:03 PM Chris Bieneman via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: cbieneman<br>
Date: Thu May 16 15:06:07 2019<br>
New Revision: 360946<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=360946&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=360946&view=rev</a><br>
Log:<br>
Add Clang shared library with C++ exports<br>
<br>
Summary:<br>
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.<br>
<br>
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.<br>
<br>
Reviewers: tstellar, winksaville<br>
<br>
Subscribers: mgorny, cfe-commits<br>
<br>
Tags: #clang<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D61909" rel="noreferrer" target="_blank">https://reviews.llvm.org/D61909</a><br>
<br>
Added:<br>
    cfe/trunk/tools/clang-shlib/<br>
    cfe/trunk/tools/clang-shlib/CMakeLists.txt<br>
    cfe/trunk/tools/clang-shlib/clang-shlib.cpp<br>
Modified:<br>
    cfe/trunk/cmake/modules/AddClang.cmake<br>
    cfe/trunk/tools/CMakeLists.txt<br>
<br>
Modified: cfe/trunk/cmake/modules/AddClang.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946&r1=360945&r2=360946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/AddClang.cmake?rev=360946&r1=360945&r2=360946&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/cmake/modules/AddClang.cmake (original)<br>
+++ cfe/trunk/cmake/modules/AddClang.cmake Thu May 16 15:06:07 2019<br>
@@ -81,9 +81,12 @@ macro(add_clang_library name)<br>
       )<br>
   endif()<br>
   if(ARG_SHARED)<br>
-    set(ARG_ENABLE_SHARED SHARED)<br>
+    set(LIBTYPE SHARED)<br>
+  else()<br>
+    set(LIBTYPE STATIC OBJECT)<br>
+    set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})<br>
   endif()<br>
-  llvm_add_library(${name} ${ARG_ENABLE_SHARED} ${ARG_UNPARSED_ARGUMENTS} ${srcs})<br>
+  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})<br>
<br>
   if(TARGET ${name})<br>
     target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})<br>
<br>
Modified: cfe/trunk/tools/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946&r1=360945&r2=360946&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CMakeLists.txt?rev=360946&r1=360945&r2=360946&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/tools/CMakeLists.txt (original)<br>
+++ cfe/trunk/tools/CMakeLists.txt Thu May 16 15:06:07 2019<br>
@@ -13,6 +13,9 @@ add_clang_subdirectory(c-index-test)<br>
<br>
 add_clang_subdirectory(clang-rename)<br>
 add_clang_subdirectory(clang-refactor)<br>
+if(UNIX)<br>
+  add_clang_subdirectory(clang-shlib)<br>
+endif()<br>
<br>
 if(CLANG_ENABLE_ARCMT)<br>
   add_clang_subdirectory(arcmt-test)<br>
<br>
Added: cfe/trunk/tools/clang-shlib/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/CMakeLists.txt?rev=360946&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-shlib/CMakeLists.txt (added)<br>
+++ cfe/trunk/tools/clang-shlib/CMakeLists.txt Thu May 16 15:06:07 2019<br>
@@ -0,0 +1,13 @@<br>
+get_property(clang_libs GLOBAL PROPERTY CLANG_STATIC_LIBS)<br>
+<br>
+foreach (lib ${clang_libs})<br>
+  list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)<br>
+  list(APPEND _DEPS $<TARGET_PROPERTY:${lib},INTERFACE_LINK_LIBRARIES>)<br>
+endforeach ()<br>
+<br>
+add_clang_library(clang_shared<br>
+                  SHARED<br>
+                  clang-shlib.cpp<br>
+                  ${_OBJECTS}<br>
+                  LINK_LIBS<br>
+                  ${_DEPS})<br>
<br>
Added: cfe/trunk/tools/clang-shlib/clang-shlib.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360946&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-shlib/clang-shlib.cpp?rev=360946&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/tools/clang-shlib/clang-shlib.cpp (added)<br>
+++ cfe/trunk/tools/clang-shlib/clang-shlib.cpp Thu May 16 15:06:07 2019<br>
@@ -0,0 +1 @@<br>
+// Intentionally empty source file to make CMake happy<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div>
</div></blockquote></body></html>