From 4601ac04c7386f099b546a40384022016fc4c22b Mon Sep 17 00:00:00 2001 From: Michal Gorny Date: Tue, 27 Sep 2016 12:15:35 +0000 Subject: [PATCH] [cmake] Add linker option "-Wl,-z,defs" in standalone build Add the "-Wl,-z,defs" linker option that is used to prevent underlinking. It is already used by LLVM itself but does not get propagated into stand-alone build of libc++. This patch ensures that the option is passed in independently of whether libc++ is built in-tree or out-of-tree. Patch by Lei Zhang. Differential Revision: https://reviews.llvm.org/D24119 llvm-svn: 282483 --- libcxx/CMakeLists.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index 2cf5ced..bc4aa30 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -319,6 +319,18 @@ remove_flags(-stdlib=libc++ -stdlib=libstdc++) # so they don't get transformed into -Wno and -errors respectivly. remove_flags(-Wno-pedantic -pedantic-errors -pedantic) +# FIXME: this is cribbed from HandleLLVMOptions.cmake. +if(LIBCXX_STANDALONE_BUILD) + # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO + # build might work on ELF but fail on MachO/COFF. + if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR + ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR + ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND + NOT LLVM_USE_SANITIZER) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs") + endif() +endif() + # Required flags ============================================================== set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect") add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER}) -- 2.7.4