[PATCH] D142888: [compiler-rt] Fix building GWPASAN on ARM
Leandro Lupori via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 13:04:44 PST 2023
luporl updated this revision to Diff 494045.
luporl added a comment.
Use built libunwind when possible.
This new diff correctly handles the following configurations:
- COMPILER_RT_USE_LLVM_UNWINDER=ON
- LIBUNWIND_ENABLE_STATIC=ON, LIBUNWIND_ENABLE_SHARED=OFF
- LIBUNWIND_ENABLE_STATIC=OFF, LIBUNWIND_ENABLE_SHARED=ON
- COMPILER_RT_USE_LLVM_UNWINDER=OFF
- LIBUNWIND_ENABLE_STATIC=ON, LIBUNWIND_ENABLE_SHARED=OFF
- LIBUNWIND_ENABLE_STATIC=OFF, LIBUNWIND_ENABLE_SHARED=ON
- libunwind removed from LLVM_ENABLE_RUNTIMES
The built libunwind is always used, except when it's not actually built, then `--unwindlib=none` is removed, to use the host's unwind library, that is the only one available.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142888/new/
https://reviews.llvm.org/D142888
Files:
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
@@ -38,7 +38,31 @@
# 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)
+
+# Link to the apropriate unwind lib, if any.
+set(SCUDO_UNWINDLIB_NONE CXX_SUPPORTS_UNWINDLIB_NONE_FLAG)
+set(SCUDO_LINK_LIBS)
+
+if(COMPILER_RT_USE_LLVM_UNWINDER)
+ list(APPEND SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS} dl)
+
+# On ARM, we must link against an unwind lib when GWPAsan is used, otherwise
+# we get undefined references to __aeabi_unwind_cpp_pr* symbols.
+# This is because object files compiled with -funwind-tables end up referencing
+# these symbols on ARM, while on other architectures, such as x86_64 and
+# AArch64, only the .eh_frame section is added, but no references to an unwind
+# library are made.
+elseif(COMPILER_RT_HAS_GWP_ASAN AND "${LLVM_NATIVE_ARCH}" STREQUAL "ARM")
+ if(LIBUNWIND_ENABLE_STATIC)
+ list(APPEND SCUDO_LINK_LIBS "$<TARGET_LINKER_FILE:unwind_static>" dl)
+ elseif(LIBUNWIND_ENABLE_SHARED)
+ list(APPEND SCUDO_LINK_LIBS "$<TARGET_LINKER_FILE:unwind_shared>")
+ else()
+ set(SCUDO_UNWINDLIB_NONE OFF)
+ endif()
+endif()
+
+append_list_if(SCUDO_UNWINDLIB_NONE --unwindlib=none SCUDO_LINK_FLAGS)
if(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
list(APPEND SCUDO_CFLAGS "--sysroot=${COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH}")
@@ -143,8 +167,6 @@
endif()
-set(SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS})
-
if(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
include_directories(${COMPILER_RT_BINARY_DIR}/../libc/include/)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142888.494045.patch
Type: text/x-patch
Size: 1901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230201/ec61b92f/attachment.bin>
More information about the llvm-commits
mailing list