[PATCH] D142888: [compiler-rt] Fix build on ARM

Leandro Lupori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 30 05:25:16 PST 2023


luporl created this revision.
luporl added reviewers: DavidSpickett, phosek, MaskRay.
luporl added a project: Sanitizers.
Herald added subscribers: yaneury, supersymetrie, Chia-hungDuan, Enna1, cryptoad, kristof.beyls, dberris.
Herald added a project: All.
luporl requested review of this revision.

The build of scudo was failing on armv7l, with undefined references
to unwinder symbols, such as __aeabi_unwind_cpp_pr0. These are
needed by RTGwpAsan and thus, on ARM, scudo must also be linked
against an unwind library.

Besides that, fuzzer build was also failing, but with an invalid
triple error. This happened because CMake's get_compiler_rt_target
function was missing some code to correctly handle arm archs,
such as armhf.

Fixes https://github.com/llvm/llvm-project/issues/60115

The scudo build doesn't fail on other architectures, such as AArch64, because
of differences in the unwind ABI of those. For instance, on AArch64, when
`-funwind-tables` is used, it only adds an `.eh_frame` section, but no
references to an unwind library.

The fix of the invalid triple error was obtained from D140011 <https://reviews.llvm.org/D140011>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142888

Files:
  compiler-rt/cmake/Modules/CompilerRTUtils.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
@@ -38,7 +38,11 @@
 
 # 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)
+# On ARM, we must link against default unwind lib when GWPAsan is used,
+# otherwise we get undefined references to __aeabi_unwind_cpp_pr* symbols.
+if(NOT COMPILER_RT_HAS_GWP_ASAN OR NOT "${LLVM_NATIVE_ARCH}" STREQUAL "ARM")
+  append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)
+endif()
 
 if(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
   list(APPEND SCUDO_CFLAGS "--sysroot=${COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH}")
Index: compiler-rt/cmake/Modules/CompilerRTUtils.cmake
===================================================================
--- compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -433,6 +433,25 @@
     string(REGEX REPLACE "mipsisa64" "mipsisa32" triple_cpu_mips "${triple_cpu}")
     string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}")
     set(target "${triple_cpu_mips}${triple_suffix_gnu}")
+  elseif("${arch}" MATCHES "^arm")
+    # Arch is arm, armhf, armv6m (anything else would come from using
+    # COMPILER_RT_DEFAULT_TARGET_ONLY, which is checked above).
+    if (${arch} STREQUAL "armhf")
+      # If we are building for hard float but our ABI is soft float.
+      if ("${triple_suffix}" MATCHES ".*eabi$")
+        # Change "eabi" -> "eabihf"
+        set(triple_suffix "${triple_suffix}hf")
+      endif()
+      # ABI is already set in the triple, don't repeat it in the architecture.
+      set(arch "arm")
+    else ()
+      # If we are building for soft float, but the triple's ABI is hard float.
+      if ("${triple_suffix}" MATCHES ".*eabihf$")
+        # Change "eabihf" -> "eabi"
+        string(REGEX REPLACE "hf$" "" triple_suffix "${triple_suffix}")
+      endif()
+    endif()
+    set(target "${arch}${triple_suffix}")
   else()
     set(target "${arch}${triple_suffix}")
   endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142888.493278.patch
Type: text/x-patch
Size: 2331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230130/97ceea17/attachment.bin>


More information about the llvm-commits mailing list