diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -195,6 +195,22 @@ # Build the shared library. if (LIBCXX_ENABLE_SHARED) + if (LIBCXXABI_USE_LLVM_UNWINDER AND (TARGET unwind OR HAVE_LIBUNWIND)) + # If the compiler driver implicitly links -lunwind, and it's built as part + # of this same build but not installed in the compiler's default lib + # directories yet, -lunwind wouldn't be found. (I.e., after adding + # implicit options, the linker would be getting the arguments + # "/libunwind. [...] -lunwind".) + # Add the intermediate lib directory to the linker path, so that the + # linker is given the arguments + # "/libunwind. -L + # [...] -lunwind". The -lunwind should resolve to the recently + # built library and nothing gets linked in from there anyway. + # + # LIBUNWIND_LIBRARY_DIR might not be set yet, but assume it's the same + # as LIBCXX_LIBRARY_DIR. + link_directories(${LIBCXX_LIBRARY_DIR}) + endif() add_library(cxx_shared SHARED ${exclude_from_all} ${LIBCXX_SOURCES} ${LIBCXX_HEADERS}) target_link_libraries(cxx_shared PUBLIC cxx-headers PRIVATE ${LIBCXX_LIBRARIES}) diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt --- a/runtimes/CMakeLists.txt +++ b/runtimes/CMakeLists.txt @@ -1,6 +1,21 @@ # This file handles building LLVM runtime sub-projects. cmake_minimum_required(VERSION 3.13.4) -project(Runtimes C CXX ASM) + +# Add path for custom and the LLVM build's modules to the CMake module path. +list(INSERT CMAKE_MODULE_PATH 0 + "${CMAKE_CURRENT_SOURCE_DIR}/cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" + "${CMAKE_CURRENT_SOURCE_DIR}/../cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Modules" + "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules" +) + +# We may have an incomplete toolchain - do language support tests without +# linking. +include(EnableLanguageNolink) +project(Runtimes LANGUAGES NONE) +llvm_enable_language_nolink(C CXX ASM) set(LLVM_ALL_RUNTIMES "compiler-rt;libc;libcxx;libcxxabi;libunwind;openmp") set(LLVM_ENABLE_RUNTIMES "" CACHE STRING @@ -28,14 +43,6 @@ find_package(LLVM PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) find_package(Clang PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) -# Add path for custom and the LLVM build's modules to the CMake module path. -list(INSERT CMAKE_MODULE_PATH 0 - "${CMAKE_CURRENT_SOURCE_DIR}/cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" - "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake" - "${CMAKE_CURRENT_SOURCE_DIR}/../llvm/cmake/modules" -) - function(get_compiler_rt_path path) foreach(entry ${runtimes}) get_filename_component(projName ${entry} NAME) @@ -86,14 +93,24 @@ endif() include(CheckLibraryExists) +include(CheckLinkerFlag) include(CheckCCompilerFlag) include(CheckCXXCompilerFlag) + +# The compiler driver may be implicitly trying to link against libunwind, which +# might not work if libunwind doesn't exist yet. Try to check if +# --unwindlib=none is supported, and use that if possible. +llvm_check_linker_flag("--unwindlib=none" LIBUNWIND_SUPPORTS_UNWINDLIB_NONE_FLAG) +if (LIBUNWIND_SUPPORTS_UNWINDLIB_NONE_FLAG) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none") +endif() + # Disable use of the installed C++ standard library when building runtimes. # Check for -nostdlib++ first; if there's no C++ standard library yet, # all check_cxx_compiler_flag commands will fail until we add -nostdlib++ # (or -nodefaultlibs). -check_c_compiler_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) +llvm_check_linker_flag(-nostdlib++ LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) if (LLVM_RUNTIMES_SUPPORT_NOSTDLIBXX_FLAG) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++") endif()