summaryrefslogtreecommitdiff
path: root/runtimes
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2021-10-24 01:11:20 +0300
committerMartin Storsjö <martin@martin.st>2021-12-09 21:38:14 +0200
commit529a79302bf35f9a5822cc00395bba99f3575e30 (patch)
treeb6e6036720d1cbdc470f0aba720d62b0fe29cb32 /runtimes
parenta9a14990809dbc4fb081ae0ae61f15c4a422b86c (diff)
downloadllvm-529a79302bf35f9a5822cc00395bba99f3575e30.tar.gz
Reapply #2 of [runtimes] Fix building initial libunwind+libcxxabi+libcxx with compiler implied -lunwind
This does mostly the same as D112126, but for the runtimes cmake files. Most of that is straightforward, but the interdependency between libcxx and libunwind is tricky: Libunwind is built at the same time as libcxx, but libunwind is not installed yet. LIBCXXABI_USE_LLVM_UNWINDER makes libcxx link directly against the just-built libunwind, but the compiler implicit -lunwind isn't found. This patch avoids that by adding --unwindlib=none if supported, if we are going to link explicitly against a newly built unwinder anyway. Since the previous attempt, this no longer uses llvm_enable_language_nolink (and thus doesn't set CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY during the compiler sanity checks). Setting CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY during compiler sanity checks makes cmake not learn about some aspects of the compiler, which can make further find_library or find_package fail. This caused OpenMP to not detect libelf and libffi, disabling some OpenMP target plugins. Instead, require the caller to set CMAKE_{C,CXX}_COMPILER_WORKS=YES when building in a configuration with an incomplete toolchain. Differential Revision: https://reviews.llvm.org/D113253
Diffstat (limited to 'runtimes')
-rw-r--r--runtimes/CMakeLists.txt19
1 files changed, 18 insertions, 1 deletions
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index eeaff6c43184..8f37d0e59feb 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -32,6 +32,8 @@ find_package(Clang PATHS "${LLVM_BINARY_DIR}" NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT
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"
)
@@ -84,14 +86,29 @@ set(LLVM_CMAKE_DIR ${LLVM_MAIN_SRC_DIR}/cmake/modules)
set(LLVM_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../llvm)
include(CheckLibraryExists)
+include(CheckLinkerFlag)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
+
+check_c_compiler_flag("" LLVM_RUNTIMES_LINKING_WORKS)
+if (NOT LLVM_RUNTIMES_LINKING_WORKS)
+ # 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.
+ # Don't add this if not necessary to fix linking, as it can break using
+ # e.g. ASAN/TSAN.
+ llvm_check_linker_flag("--unwindlib=none" LLVM_RUNTIMES_SUPPORT_UNWINDLIB_NONE_FLAG)
+ if (LLVM_RUNTIMES_SUPPORT_UNWINDLIB_NONE_FLAG)
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --unwindlib=none")
+ endif()
+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()