[PATCH] D88958: [sanitizer] Disable fast_unwind_on_malloc as default for arm-linux-gnu

Adhemerval Zanella via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 7 05:14:43 PDT 2020


zatrazz created this revision.
zatrazz added reviewers: vitalybuka, kcc, eugenis, kubamracek.
zatrazz added a project: Sanitizers.
Herald added subscribers: Sanitizers, kristof.beyls, mgorny.
zatrazz requested review of this revision.

This is an updated version of D83143 <https://reviews.llvm.org/D83143>. Instead of disable fast-unwinder
on arm-linux-gnu, it just disable it as *default* instead. It should fix the 
possible false-positive malloc failures when iteracting with thumb build
object by GCC, with the expanse of the slowdown from using the slow
library based unwinder. However users still have the option to use the
fast-unwinder.

-

ARM thumb/thumb2 frame pointer is inconsistent on GCC and Clang [1]
and fast-unwider is also unreliable with mixing arm and thumb code [2].

The fast unwinder ARM tries to probe and compare the frame-pointer
in different stack layout position and it works reliable only on a
systems where all the libraries are built in arm mode (either with
gcc or clang) or with clang (which uses the same stack frame pointer
layout in arm and thumb).

However when mixing objects built with different abi mode the
fast unwinder is still problematic as shown by the failures on the
AddressSanitizer.ThreadStackReuseTest.  For these failures, the
malloc is called by the loader itself and since it has been built
with a thum enabled gcc, the stack frame is not correctly obtained
and the suppression rule and thus not applied (resulting in a leak
warning).

The check for fast-unwinder-works is also changed: instead of checking
f it is explicit enabled in the compiler flags, it now checks if
compiler defined __thumb__ pre-processore.

This should fix BZ#44158.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92172
[2] https://bugs.llvm.org/show_bug.cgi?id=44158


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88958

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
  compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp
  compiler-rt/test/asan/lit.cfg.py
  compiler-rt/test/asan/lit.site.cfg.py.in


Index: compiler-rt/test/asan/lit.site.cfg.py.in
===================================================================
--- compiler-rt/test/asan/lit.site.cfg.py.in
+++ compiler-rt/test/asan/lit.site.cfg.py.in
@@ -5,6 +5,7 @@
 config.target_cflags = "@ASAN_TEST_TARGET_CFLAGS@"
 config.clang = "@ASAN_TEST_TARGET_CC@"
 config.bits = "@ASAN_TEST_BITS@"
+config.arm_thumb = "@COMPILER_RT_ARM_THUMB@"
 config.apple_platform = "@ASAN_TEST_APPLE_PLATFORM@"
 config.apple_platform_min_deployment_target_flag = "@ASAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG@"
 config.asan_dynamic = @ASAN_TEST_DYNAMIC@
Index: compiler-rt/test/asan/lit.cfg.py
===================================================================
--- compiler-rt/test/asan/lit.cfg.py
+++ compiler-rt/test/asan/lit.cfg.py
@@ -205,7 +205,7 @@
 config.available_features.add("asan-" + config.bits + "-bits")
 
 # Fast unwinder doesn't work with Thumb
-if re.search('mthumb', config.target_cflags) is None:
+if not config.arm_thumb:
   config.available_features.add('fast-unwinder-works')
 
 # Turn on leak detection on 64-bit Linux.
Index: compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp
===================================================================
--- compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp
+++ compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp
@@ -1,7 +1,7 @@
-// RUN: %clangxx_asan -O0 -x c %s -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O1 -x c %s -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O2 -x c %s -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 -x c %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 -x c %s -o %t && not %env_asan_opts=fast_unwind_on_malloc=1 %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: (arm-target-arch || armhf-target-arch), fast-unwinder-works
 
Index: compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
+++ compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
@@ -40,7 +40,12 @@
 COMMON_FLAG(bool, fast_unwind_on_fatal, false,
             "If available, use the fast frame-pointer-based unwinder on fatal "
             "errors.")
-COMMON_FLAG(bool, fast_unwind_on_malloc, true,
+// ARM thumb/thumb2 frame pointer is inconsistent on GCC and Clang [1]
+// and fast-unwider is also unreliable with mixing arm and thumb code [2].
+// [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92172
+// [2] https://bugs.llvm.org/show_bug.cgi?id=44158
+COMMON_FLAG(bool, fast_unwind_on_malloc,
+	    !(SANITIZER_LINUX && !SANITIZER_ANDROID && SANITIZER_ARM),
             "If available, use the fast frame-pointer-based unwinder on "
             "malloc/free.")
 COMMON_FLAG(bool, handle_ioctl, false, "Intercept and handle ioctl requests.")
Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -114,6 +114,7 @@
 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*hf$")
   if (${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "^arm")
     set(COMPILER_RT_DEFAULT_TARGET_ARCH "armhf")
+    CHECK_SYMBOL_EXISTS (__thumb__ "" COMPILER_RT_ARM_THUMB)
   endif()
 endif()
 if ("${COMPILER_RT_DEFAULT_TARGET_TRIPLE}" MATCHES ".*android.*")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88958.296646.patch
Type: text/x-patch
Size: 3698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201007/a6238789/attachment.bin>


More information about the llvm-commits mailing list