diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake --- a/clang/cmake/caches/Fuchsia-stage2.cmake +++ b/clang/cmake/caches/Fuchsia-stage2.cmake @@ -110,6 +110,7 @@ set(RUNTIMES_${target}_CMAKE_SHARED_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "") + set(RUNTIMES_${target}_COMPILER_RT_CXX_LIBRARY "libcxx" CACHE STRING "") set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${target}_COMPILER_RT_USE_LLVM_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${target}_COMPILER_RT_CAN_EXECUTE_TESTS ON CACHE BOOL "") @@ -178,6 +179,7 @@ set(RUNTIMES_${target}_CMAKE_MODULE_LINKER_FLAGS ${FUCHSIA_${target}_LINKER_FLAGS} CACHE STRING "") set(RUNTIMES_${target}_CMAKE_EXE_LINKER_FLAGS ${FUCHSIA_${target}_LINKER_FLAGS} CACHE STRING "") set(RUNTIMES_${target}_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "") + set(RUNTIMES_${target}_COMPILER_RT_CXX_LIBRARY "libcxx" CACHE STRING "") set(RUNTIMES_${target}_COMPILER_RT_USE_BUILTINS_LIBRARY ON CACHE BOOL "") set(RUNTIMES_${target}_COMPILER_RT_USE_LLVM_UNWINDER ON CACHE BOOL "") set(RUNTIMES_${target}_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "") diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -199,6 +199,7 @@ # This is either directly the C++ ABI library or the full C++ library # which pulls in the ABI transitively. +# TODO: Mark this as internal flag, most users should use COMPILER_RT_CXX_LIBRARY. set(SANITIZER_CXX_ABI "default" CACHE STRING "Specify C++ ABI library to use.") set(CXXABIS none default libstdc++ libc++ libcxxabi) @@ -206,6 +207,7 @@ handle_default_cxx_lib(SANITIZER_CXX_ABI) # This needs to be a full C++ library for linking gtest and unit tests. +# TODO: Mark this as internal flag, most users should use COMPILER_RT_CXX_LIBRARY. set(SANITIZER_TEST_CXX "default" CACHE STRING "Specify C++ library to use for tests.") set(CXXLIBS none default libstdc++ libc++) @@ -246,6 +248,15 @@ "Use static libc++ for tests." ${DEFAULT_SANITIZER_USE_STATIC_TEST_CXX}) pythonize_bool(SANITIZER_USE_STATIC_TEST_CXX) +set(COMPILER_RT_SUPPORTED_CXX_LIBRARIES none default libcxx) +set(COMPILER_RT_CXX_LIBRARY "default" CACHE STRING "Specify C++ library to use. Supported values are ${COMPILER_RT_SUPPORTED_CXX_LIBRARIES}.") +if (NOT "${COMPILER_RT_CXX_LIBRARY}" IN_LIST COMPILER_RT_SUPPORTED_CXX_LIBRARIES) + message(FATAL_ERROR "Unsupported C++ library: '${COMPILER_RT_CXX_LIBRARY}'. Supported values are ${COMPILER_RT_SUPPORTED_CXX_LIBRARIES}.") +endif() +cmake_dependent_option(COMPILER_RT_STATIC_CXX_LIBRARY + "Statically link the C++ library." OFF + "COMPILER_RT_CXX_LIBRARY" OFF) + set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF) if (FUCHSIA) set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON) @@ -519,6 +530,26 @@ list(APPEND SANITIZER_CXX_ABI_LIBRARIES "$<$:$>") endif() +if (COMPILER_RT_CXX_LIBRARY STREQUAL "libcxx") + # We are using the in-tree libc++ so avoid including the default one. + append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS) + append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS) + # Use the in-tree libc++ through explicit include and library paths. + if (COMPILER_RT_STATIC_CXX_LIBRARY) + set(cxx_target cxx_static) + else() + set(cxx_target cxx_shared) + endif() + list(APPEND COMPILER_RT_CXX_CFLAGS "$<$:-isystem$,$-isystem>>") + list(APPEND COMPILER_RT_CXX_LINK_LIBS "$<$:$>") +elseif (COMPILER_RT_CXX_LIBRARY STREQUAL "none") + # We aren't using any C++ standard library so avoid including the default one. + append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ COMPILER_RT_COMMON_CFLAGS) + append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ COMPILER_RT_COMMON_LINK_FLAGS) +else() + # Nothing to be done for `default`. +endif() + macro(append_libcxx_libs var) if (${var}_INTREE) if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) diff --git a/compiler-rt/lib/fuzzer/CMakeLists.txt b/compiler-rt/lib/fuzzer/CMakeLists.txt --- a/compiler-rt/lib/fuzzer/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/CMakeLists.txt @@ -66,6 +66,7 @@ append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ LIBFUZZER_CFLAGS) elseif(TARGET cxx-headers OR HAVE_LIBCXX) # libFuzzer uses C++ standard library headers. + list(APPEND LIBFUZZER_CFLAGS ${COMPILER_RT_CXX_CFLAGS}) set(LIBFUZZER_DEPS cxx-headers) endif() diff --git a/compiler-rt/lib/orc/CMakeLists.txt b/compiler-rt/lib/orc/CMakeLists.txt --- a/compiler-rt/lib/orc/CMakeLists.txt +++ b/compiler-rt/lib/orc/CMakeLists.txt @@ -49,7 +49,11 @@ include_directories(..) include_directories(../../include) -set(ORC_CFLAGS ${COMPILER_RT_COMMON_CFLAGS}) +set(ORC_CFLAGS + ${COMPILER_RT_COMMON_CFLAGS} + ${COMPILER_RT_CXX_CFLAGS}) +set(ORC_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS}) +set(ORC_LINK_LIBS ${COMPILER_RT_CXX_LINK_LIBS}) # Allow the ORC runtime to reference LLVM headers. foreach (DIR ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR}) @@ -83,7 +87,7 @@ ARCHS ${ORC_SUPPORTED_ARCH} OBJECT_LIBS RTOrc CFLAGS ${ORC_CFLAGS} - LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} + LINK_FLAGS ${ORC_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${ORC_LINK_LIBS} PARENT_TARGET orc) else() # not Apple @@ -109,6 +113,8 @@ STATIC ARCHS ${arch} CFLAGS ${ORC_CFLAGS} + LINK_FLAGS ${ORC_LINK_FLAGS} + LINK_LIBS ${ORC_LINK_LIBS} OBJECT_LIBS ${ORC_COMMON_RUNTIME_OBJECT_LIBS} RTOrc PARENT_TARGET orc) endforeach() diff --git a/compiler-rt/lib/xray/CMakeLists.txt b/compiler-rt/lib/xray/CMakeLists.txt --- a/compiler-rt/lib/xray/CMakeLists.txt +++ b/compiler-rt/lib/xray/CMakeLists.txt @@ -138,7 +138,9 @@ include_directories(..) include_directories(../../include) -set(XRAY_CFLAGS ${COMPILER_RT_COMMON_CFLAGS}) +set(XRAY_CFLAGS + ${COMPILER_RT_COMMON_CFLAGS} + ${COMPILER_RT_CXX_CFLAGS}) set(XRAY_COMMON_DEFINITIONS XRAY_HAS_EXCEPTIONS=1) # Too many existing bugs, needs cleanup. @@ -147,6 +149,9 @@ # We don't need RTTI in XRay, so turn that off. append_rtti_flag(OFF XRAY_CFLAGS) +set(XRAY_LINK_FLAGS ${COMPILER_RT_COMMON_LINK_FLAGS}) +set(XRAY_LINK_LIBS ${COMPILER_RT_CXX_LINK_LIBS}) + append_list_if( COMPILER_RT_HAS_XRAY_COMPILER_FLAG XRAY_SUPPORTED=1 XRAY_COMMON_DEFINITIONS) append_list_if( @@ -164,7 +169,6 @@ endif() if (APPLE) - set(XRAY_LINK_LIBS ${SANITIZER_COMMON_LINK_LIBS}) add_asm_sources(XRAY_ASM_SOURCES xray_trampoline_x86_64.S) add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS) @@ -213,7 +217,7 @@ RTSanitizerCommonLibc CFLAGS ${XRAY_CFLAGS} DEFS ${XRAY_COMMON_DEFINITIONS} - LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${XRAY_LINK_LIBS} PARENT_TARGET xray) add_compiler_rt_runtime(clang_rt.xray-fdr @@ -223,7 +227,7 @@ OBJECT_LIBS RTXrayFDR CFLAGS ${XRAY_CFLAGS} DEFS ${XRAY_COMMON_DEFINITIONS} - LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${XRAY_LINK_LIBS} PARENT_TARGET xray) add_compiler_rt_runtime(clang_rt.xray-basic @@ -233,7 +237,7 @@ OBJECT_LIBS RTXrayBASIC CFLAGS ${XRAY_CFLAGS} DEFS ${XRAY_COMMON_DEFINITIONS} - LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${XRAY_LINK_LIBS} PARENT_TARGET xray) add_compiler_rt_runtime(clang_rt.xray-profiling @@ -243,7 +247,7 @@ OBJECT_LIBS RTXrayPROFILING CFLAGS ${XRAY_CFLAGS} DEFS ${XRAY_COMMON_DEFINITIONS} - LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${XRAY_LINK_LIBS} PARENT_TARGET xray) else() # not Apple @@ -285,6 +289,8 @@ STATIC ARCHS ${arch} CFLAGS ${XRAY_CFLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} + LINK_LIBS ${XRAY_LINK_LIBS} DEFS ${XRAY_COMMON_DEFINITIONS} OBJECT_LIBS ${XRAY_COMMON_RUNTIME_OBJECT_LIBS} RTXray PARENT_TARGET xray) @@ -293,6 +299,8 @@ STATIC ARCHS ${arch} CFLAGS ${XRAY_CFLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} + LINK_LIBS ${XRAY_LINK_LIBS} DEFS ${XRAY_COMMON_DEFINITIONS} OBJECT_LIBS RTXrayFDR PARENT_TARGET xray) @@ -301,6 +309,8 @@ STATIC ARCHS ${arch} CFLAGS ${XRAY_CFLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} + LINK_LIBS ${XRAY_LINK_LIBS} DEFS ${XRAY_COMMON_DEFINITIONS} OBJECT_LIBS RTXrayBASIC PARENT_TARGET xray) @@ -309,6 +319,8 @@ STATIC ARCHS ${arch} CFLAGS ${XRAY_CFLAGS} + LINK_FLAGS ${XRAY_LINK_FLAGS} + LINK_LIBS ${XRAY_LINK_LIBS} DEFS ${XRAY_COMMON_DEFINITIONS} OBJECT_LIBS RTXrayPROFILING PARENT_TARGET xray)