[PATCH] D83134: [asan] Disable fast unwinder on arm-linux-gnueabi with thumb

Adhemerval Zanella via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 08:02:18 PDT 2020


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

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 hacks to probe and compare the frame-pointer
in different stack layout position works reliable only on a system where
all the libraries are built in arm mode (either with gcc or clang).

However when mixing objects built with different abi mode the
fast unwinder is still problematic.  The quarantine_size_mb.cpp
still fails on ARM on system with libraries built with thumb (Ubuntu
bionic for instance) so make is pass clean this patch forces it to
use the slow unwinder is to avoid a leak warning triggered by the
helper quarantine thread creation (the allocation is done by glibc
pthread_create).  Without proper stack frame information libsanitizer
can not apply the expected suppresion in this case.

This should fix BZ#44158, however the leak sanitizier is still
unreliable on most distros where the system compiler defaults to
use thumb.

[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/D83134

Files:
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/sanitizer_common/sanitizer_platform.h
  compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
  compiler-rt/test/asan/TestCases/Linux/quarantine_size_mb.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
@@ -191,7 +191,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/quarantine_size_mb.cpp
===================================================================
--- compiler-rt/test/asan/TestCases/Linux/quarantine_size_mb.cpp
+++ compiler-rt/test/asan/TestCases/Linux/quarantine_size_mb.cpp
@@ -1,10 +1,10 @@
 // Test quarantine_size_mb (and the deprecated quarantine_size)
 // RUN: %clangxx_asan  %s -o %t
-// RUN: %env_asan_opts=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50 %run %t  2>&1 | FileCheck %s  --check-prefix=Q10
-// RUN: %env_asan_opts=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50    %run %t  2>&1 | FileCheck %s  --check-prefix=Q10
-// RUN: %env_asan_opts=quarantine_size_mb=10:quarantine_size=20:verbosity=1  not %run %t  2>&1 | FileCheck %s  --check-prefix=BOTH
-// RUN: %env_asan_opts=quarantine_size_mb=1000:hard_rss_limit_mb=50 not  %run %t          2>&1 | FileCheck %s  --check-prefix=RSS_LIMIT
-// RUN: %env_asan_opts=hard_rss_limit_mb=20                         not  %run %t          2>&1 | FileCheck %s  --check-prefix=RSS_LIMIT
+// RUN: %env_asan_opts=quarantine_size=10485760:verbosity=1:hard_rss_limit_mb=50:fast_unwind_on_malloc=0 %run %t  2>&1 | FileCheck %s  --check-prefix=Q10
+// RUN: %env_asan_opts=quarantine_size_mb=10:verbosity=1:hard_rss_limit_mb=50:fast_unwind_on_malloc=0    %run %t  2>&1 | FileCheck %s  --check-prefix=Q10
+// RUN: %env_asan_opts=quarantine_size_mb=10:quarantine_size=20:verbosity=1  not %run %t                          2>&1 | FileCheck %s  --check-prefix=BOTH
+// RUN: %env_asan_opts=quarantine_size_mb=1000:hard_rss_limit_mb=50 not  %run %t                                  2>&1 | FileCheck %s  --check-prefix=RSS_LIMIT
+// RUN: %env_asan_opts=hard_rss_limit_mb=20                         not  %run %t                                  2>&1 | FileCheck %s  --check-prefix=RSS_LIMIT
 
 // https://github.com/google/sanitizers/issues/981
 // UNSUPPORTED: android-26
Index: compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
@@ -22,6 +22,8 @@
 
 #if SANITIZER_LINUX && defined(__mips__)
 # define SANITIZER_CAN_FAST_UNWIND 0
+#elif SANITIZER_LINUX && !SANITIZER_ANDROID && SANITIZER_ARM_THUMB
+# define SANITIZER_CAN_FAST_UNWIND 0
 #elif SANITIZER_WINDOWS
 # define SANITIZER_CAN_FAST_UNWIND 0
 #elif SANITIZER_OPENBSD
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_platform.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform.h
@@ -197,8 +197,12 @@
 
 #if defined(__arm__)
 # define SANITIZER_ARM 1
+# ifdef __thumb__
+#  define SANITIZER_ARM_THUMB 1
+# endif
 #else
 # define SANITIZER_ARM 0
+# define SANITIZER_ARM_THUMB 0
 #endif
 
 #if SANITIZER_SOLARIS && SANITIZER_WORDSIZE == 32
@@ -318,7 +322,7 @@
 // pthread_exit() performs unwinding that leads to dlopen'ing libgcc_s.so.
 // dlopen mallocs "libgcc_s.so" string which confuses LSan, it fails to realize
 // that this allocation happens in dynamic linker and should be ignored.
-#if SANITIZER_PPC || defined(__thumb__)
+#if SANITIZER_PPC || SANITIZER_ARM_THUMB
 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 1
 #else
 # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 0
Index: compiler-rt/CMakeLists.txt
===================================================================
--- compiler-rt/CMakeLists.txt
+++ compiler-rt/CMakeLists.txt
@@ -129,6 +129,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: D83134.275395.patch
Type: text/x-patch
Size: 4990 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200703/70c90174/attachment.bin>


More information about the llvm-commits mailing list