smeenai created this revision. smeenai added reviewers: EricWF, compnerd. smeenai added subscribers: cfe-commits, kastiglione.
We're compiling libc++ with -nodefaultlibs, so we should also pass this option during the configuration checks to ensure those checks are consistent with the actual build. The primary motivation here is to ease cross-compilation against a non-standard set of C++ libraries. Previously, the configuration checks would attempt to link against the standard C++ libraries, which would cause link failures when cross-compiling, even though the actual library link would go through correctly (because of the use of -nodefaultlibs and explicitly specifying any needed libraries). This is more correct even ignoring the motivation, however. This redoes D23791 but fixes the configuration errors in sanitizer builds by disabling the sanitizers for the configuration checks. Test Plan: - check-libcxx passes on OS X 10.11 - check-libcxx passes on Ubuntu 16.04 - libcxx configures correctly on Ubuntu 16.04 with LLVM_USE_SANITIZER Address, Memory, Thread, and Undefined https://reviews.llvm.org/D23856 Files: cmake/Modules/CheckLibcxxAtomic.cmake cmake/config-ix.cmake Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -1,5 +1,34 @@ include(CheckLibraryExists) include(CheckCXXCompilerFlag) + +check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) +if (NOT LIBCXX_USE_COMPILER_RT) + check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB) +endif() + +# libc++ is built with -nodefaultlibs, so we want all our checks to also +# use this option, otherwise we may end up with an inconsistency between +# the flags we think we require during configuration (if the checks are +# performed without -nodefaultlibs) and the flags that are actually +# required during compilation (which has the -nodefaultlibs). libc is +# required for the link to go through. We remove sanitizers from the +# configuration checks to avoid spurious link errors. +check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) +if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) + list(APPEND CMAKE_REQUIRED_LIBRARIES -nodefaultlibs) + if (LIBCXX_HAS_C_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES c) + endif () + if (LIBCXX_USE_COMPILER_RT) + list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt) + elseif (LIBCXX_HAS_GCC_S_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) + endif () + if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) + list(APPEND CMAKE_REQUIRED_FLAGS -fno-sanitize=all) + endif () +endif () + include(CheckLibcxxAtomic) # Check compiler flags @@ -14,9 +43,5 @@ # Check libraries check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB) -check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) check_library_exists(m ccos "" LIBCXX_HAS_M_LIB) check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB) -if (NOT LIBCXX_USE_COMPILER_RT) - check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB) -endif() Index: cmake/Modules/CheckLibcxxAtomic.cmake =================================================================== --- cmake/Modules/CheckLibcxxAtomic.cmake +++ cmake/Modules/CheckLibcxxAtomic.cmake @@ -13,6 +13,9 @@ if (${LIBCXX_GCC_TOOLCHAIN}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") endif() + if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") + endif() check_cxx_source_compiles(" #include <cstdint> #include <atomic>
Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -1,5 +1,34 @@ include(CheckLibraryExists) include(CheckCXXCompilerFlag) + +check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) +if (NOT LIBCXX_USE_COMPILER_RT) + check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB) +endif() + +# libc++ is built with -nodefaultlibs, so we want all our checks to also +# use this option, otherwise we may end up with an inconsistency between +# the flags we think we require during configuration (if the checks are +# performed without -nodefaultlibs) and the flags that are actually +# required during compilation (which has the -nodefaultlibs). libc is +# required for the link to go through. We remove sanitizers from the +# configuration checks to avoid spurious link errors. +check_cxx_compiler_flag(-nodefaultlibs LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) +if (LIBCXX_SUPPORTS_NODEFAULTLIBS_FLAG) + list(APPEND CMAKE_REQUIRED_LIBRARIES -nodefaultlibs) + if (LIBCXX_HAS_C_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES c) + endif () + if (LIBCXX_USE_COMPILER_RT) + list(APPEND CMAKE_REQUIRED_LIBRARIES -rtlib=compiler-rt) + elseif (LIBCXX_HAS_GCC_S_LIB) + list(APPEND CMAKE_REQUIRED_LIBRARIES gcc_s) + endif () + if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) + list(APPEND CMAKE_REQUIRED_FLAGS -fno-sanitize=all) + endif () +endif () + include(CheckLibcxxAtomic) # Check compiler flags @@ -14,9 +43,5 @@ # Check libraries check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB) -check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) check_library_exists(m ccos "" LIBCXX_HAS_M_LIB) check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB) -if (NOT LIBCXX_USE_COMPILER_RT) - check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB) -endif() Index: cmake/Modules/CheckLibcxxAtomic.cmake =================================================================== --- cmake/Modules/CheckLibcxxAtomic.cmake +++ cmake/Modules/CheckLibcxxAtomic.cmake @@ -13,6 +13,9 @@ if (${LIBCXX_GCC_TOOLCHAIN}) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}") endif() + if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all") + endif() check_cxx_source_compiles(" #include <cstdint> #include <atomic>
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits