[compiler-rt] 039126c - [sanitizer] Disable fast_unwind_on_malloc as default for arm-linux-gnu

Adhemerval Zanella via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 12 10:36:26 PDT 2020


Author: Adhemerval Zanella
Date: 2020-10-12T14:36:08-03:00
New Revision: 039126c97d39fbd8ca6a82f103db8f2591e793cd

URL: https://github.com/llvm/llvm-project/commit/039126c97d39fbd8ca6a82f103db8f2591e793cd
DIFF: https://github.com/llvm/llvm-project/commit/039126c97d39fbd8ca6a82f103db8f2591e793cd.diff

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

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

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

However when mixing objects built with different abi modes 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 is 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-processor.

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

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D88958

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index c59b4456cd45..45c52f804f48 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -114,6 +114,7 @@ construct_compiler_rt_default_triple()
 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.*")

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
index b83ac03408d8..5964c7020d31 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.inc
@@ -40,7 +40,12 @@ COMMON_FLAG(bool, fast_unwind_on_check, false,
 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.")

diff  --git a/compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp b/compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp
index 0c3fa0aed7d0..314e7d35b460 100644
--- a/compiler-rt/test/asan/TestCases/Linux/clang_gcc_abi.cpp
+++ b/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
 

diff  --git a/compiler-rt/test/asan/lit.cfg.py b/compiler-rt/test/asan/lit.cfg.py
index f9c491846a42..4cfd0b68b761 100644
--- a/compiler-rt/test/asan/lit.cfg.py
+++ b/compiler-rt/test/asan/lit.cfg.py
@@ -205,7 +205,7 @@ def build_invocation(compile_flags):
 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.

diff  --git a/compiler-rt/test/asan/lit.site.cfg.py.in b/compiler-rt/test/asan/lit.site.cfg.py.in
index 81cebde2029e..afecfafeb99f 100644
--- a/compiler-rt/test/asan/lit.site.cfg.py.in
+++ b/compiler-rt/test/asan/lit.site.cfg.py.in
@@ -5,6 +5,7 @@ config.name_suffix = "@ASAN_TEST_CONFIG_SUFFIX@"
 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@


        


More information about the llvm-commits mailing list