Skip to content

Commit 4601ac0

Browse files
committedSep 27, 2016
[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
1 parent 3d3ae6f commit 4601ac0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
 

‎libcxx/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,18 @@ remove_flags(-stdlib=libc++ -stdlib=libstdc++)
319319
# so they don't get transformed into -Wno and -errors respectivly.
320320
remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
321321

322+
# FIXME: this is cribbed from HandleLLVMOptions.cmake.
323+
if(LIBCXX_STANDALONE_BUILD)
324+
# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
325+
# build might work on ELF but fail on MachO/COFF.
326+
if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR
327+
${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR
328+
${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND
329+
NOT LLVM_USE_SANITIZER)
330+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
331+
endif()
332+
endif()
333+
322334
# Required flags ==============================================================
323335
set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect")
324336
add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER})

0 commit comments

Comments
 (0)