summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-11-07 15:33:56 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-11-07 15:33:56 +0000
commitb3963d680c455407c33168946497840ed63df4b6 (patch)
treee1632ddac23321179fa834c230aa08d2bf5de66c
parent01657f390db6910f4fc5f7ee177c2de04d7b81b4 (diff)
Pass PRIVATE to target_link_libraries if using shared libraries.
A shared library (unlike a .a), has its dependencies recorded in the library and we can pass PRIVATE to target_link_libraries. This patch then removes some bogus dependencies when using BUILD_SHARED_LIBS=ON. For example, we go from build lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/AggressiveAntiDepBreaker.cpp.o: CXX_COMPILER /home/espindola/llvm/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp || include/llvm/IR/intrinsics_gen lib/libLLVMSupport.so lib/libLLVMCore.so lib/libLLVMBitReader.so lib/libLLVMTransformUtils.so lib/libLLVMInstCombine.so lib/libLLVMScalarOpts.so lib/libLLVMipa.so lib/libLLVMAnalysis.so lib/libLLVMMCParser.so lib/libLLVMMC.so lib/libLLVMObject.so lib/libLLVMTarget.so lib/libLLVMProfileData.so to build lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/AggressiveAntiDepBreaker.cpp.o: CXX_COMPILER /home/espindola/llvm/llvm/lib/CodeGen/AggressiveAntiDepBreaker.cpp || include/llvm/IR/intrinsics_gen lib/libLLVMSupport.so lib/libLLVMCore.so lib/libLLVMTransformUtils.so lib/libLLVMScalarOpts.so lib/libLLVMAnalysis.so lib/libLLVMMC.so lib/libLLVMTarget.so In fact, build.ninja goes from 5231028 bytes to 4896759 bytes. With this, old verisons of bfd ld (2.24 is OK, 2.23 warns) will print a bogus warning when building with BUILD_SHARED_LIBS. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221530 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--CMakeLists.txt10
-rw-r--r--cmake/modules/AddLLVM.cmake16
2 files changed, 11 insertions, 15 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b4eac034ae7..f2b3d326148 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -469,6 +469,16 @@ else(UNIX)
endif(NOT DEFINED CMAKE_INSTALL_RPATH)
endif()
+# Work around a broken bfd ld behavior. When linking a binary with a
+# foo.so library, it will try to find any library that foo.so uses and
+# check its symbols. This is wasteful (the check was done when foo.so
+# was created) and can fail since it is not the dynamic linker and
+# doesn't know how to handle search paths correctly.
+if (UNIX AND NOT APPLE)
+ set(CMAKE_EXE_LINKER_FLAGS
+ "${CMAKE_EXE_LINKER_FLAGS} -Wl,-allow-shlib-undefined")
+endif()
+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index 198393dc507..15ce6243ad5 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -359,22 +359,8 @@ function(llvm_add_library name)
${lib_deps}
${llvm_libs}
)
- elseif((CYGWIN OR WIN32) AND ARG_SHARED)
- # Win32's import library may be unaware of its dependent libs.
- target_link_libraries(${name} PRIVATE
- ${ARG_LINK_LIBS}
- ${lib_deps}
- ${llvm_libs}
- )
- elseif(ARG_SHARED AND BUILD_SHARED_LIBS)
- # FIXME: It may be PRIVATE since SO knows its dependent libs.
- target_link_libraries(${name} PUBLIC
- ${ARG_LINK_LIBS}
- ${lib_deps}
- ${llvm_libs}
- )
else()
- # MODULE|SHARED
+ # We can use PRIVATE since SO knows its dependent libs.
target_link_libraries(${name} PRIVATE
${ARG_LINK_LIBS}
${lib_deps}