[PATCH] D115674: [CMake][compiler-rt] Provide a dedicated option for LLVM unwinder
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 13 12:20:08 PDT 2022
phosek updated this revision to Diff 436511.
phosek retitled this revision from "[runtime] Build compiler-rt with --unwindlib=none" to "[CMake][compiler-rt] Provide a dedicated option for LLVM unwinder".
phosek edited the summary of this revision.
Herald added a subscriber: cryptoad.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115674/new/
https://reviews.llvm.org/D115674
Files:
compiler-rt/CMakeLists.txt
compiler-rt/cmake/config-ix.cmake
compiler-rt/lib/scudo/standalone/CMakeLists.txt
Index: compiler-rt/lib/scudo/standalone/CMakeLists.txt
===================================================================
--- compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -36,6 +36,7 @@
# We don't use the C++ standard library, so avoid including it by mistake.
append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
+append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
if(ANDROID)
list(APPEND SCUDO_CFLAGS -fno-emulated-tls)
Index: compiler-rt/cmake/config-ix.cmake
===================================================================
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -4,9 +4,19 @@
include(CheckCXXCompilerFlag)
include(CheckIncludeFiles)
include(CheckLibraryExists)
+include(LLVMCheckCompilerLinkerFlag)
include(CheckSymbolExists)
include(TestBigEndian)
+# The compiler driver may be implicitly trying to link against libunwind.
+# This is normally ok (libcxx relies on an unwinder), but if libunwind is
+# built in the same cmake invocation as compiler-rt and we're using the
+# in tree version of runtimes, we'd be linking against the just-built
+# libunwind (and the compiler implicit -lunwind wouldn't succeed as the newly
+# built libunwind isn't installed yet). For those cases, it'd be good to
+# link with --uwnindlib=none. Check if that option works.
+llvm_check_compiler_linker_flag(C "--unwindlib=none" CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
+
check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
include(HandleCompilerRT)
Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -31,6 +31,7 @@
include(SetPlatformToolchainTools)
include(base-config-ix)
include(CompilerRTUtils)
+include(CMakeDependentOption)
option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON)
mark_as_advanced(COMPILER_RT_BUILD_BUILTINS)
@@ -211,6 +212,11 @@
set_property(CACHE SANITIZER_TEST_CXX PROPERTY STRINGS ;${CXXLIBS})
handle_default_cxx_lib(SANITIZER_TEST_CXX)
+option(COMPILER_RT_USE_LLVM_UNWINDER "Use the LLVM unwinder." OFF)
+cmake_dependent_option(COMPILER_RT_ENABLE_STATIC_UNWINDER
+ "Statically link the LLVM unwinder." OFF
+ "COMPILER_RT_USE_LLVM_UNWINDER" OFF)
+
set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER OFF)
if (FUCHSIA)
set(DEFAULT_SANITIZER_USE_STATIC_LLVM_UNWINDER ON)
@@ -504,8 +510,23 @@
list(APPEND COMPILER_RT_COMMON_CFLAGS ${stdlib_flag})
list(APPEND COMPILER_RT_COMMON_LINK_FLAGS ${stdlib_flag})
+if(COMPILER_RT_USE_LLVM_UNWINDER)
+ # TODO: set --unwindlib=none after https://reviews.llvm.org/D115674 lands.
+ if (COMPILER_RT_ENABLE_STATIC_UNWINDER)
+ set(unwinder_target unwind_static)
+ else()
+ set(unwinder_target unwind_shared)
+ endif()
+ list(APPEND SANITIZER_CXX_ABI_LIBRARIES "$<$<TARGET_EXISTS:${unwind_target}>:$<TARGET_LINKER_FILE:${unwind_target}>>")
+endif()
+
macro(append_libcxx_libs var)
if (${var}_INTREE)
+ # If we're linking directly against the libunwind that we're building
+ # in the same invocation, don't try to link in the toolchain's
+ # default libunwind (which may be missing still).
+ append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SANITIZER_COMMON_LINK_FLAGS)
+
if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))
list(APPEND ${var}_LIBRARIES unwind_static)
elseif (TARGET unwind_shared OR HAVE_LIBUNWIND)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115674.436511.patch
Type: text/x-patch
Size: 3595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220613/4c197132/attachment.bin>
More information about the llvm-commits
mailing list