[compiler-rt] 402dd79 - sanitizer_common: Use plain thread_local for __sancov_lowest_stack definition.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 20 16:26:31 PDT 2023


Author: Peter Collingbourne
Date: 2023-03-20T16:26:02-07:00
New Revision: 402dd79a293dc23f0ccf521d79386880e4969584

URL: https://github.com/llvm/llvm-project/commit/402dd79a293dc23f0ccf521d79386880e4969584
DIFF: https://github.com/llvm/llvm-project/commit/402dd79a293dc23f0ccf521d79386880e4969584.diff

LOG: sanitizer_common: Use plain thread_local for __sancov_lowest_stack definition.

We can't use initial-exec for the definition of __sancov_lowest_stack
because it gets linked into shared libraries such as the UBSan and
HWASan runtimes on Android. I think we can expect plain thread_local
to work unconditionally in sanitizer_common as several other sanitizers
are already using it, so drop the platform-dependent macro and just use
thread_local in the definition.

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

Added: 
    

Modified: 
    compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
    compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
index 956b48e0b434b..f2dd6b227ccd3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
@@ -282,7 +282,11 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_pcs_init, const uptr* beg,
 // Weak definition for code instrumented with -fsanitize-coverage=stack-depth
 // and later linked with code containing a strong definition.
 // E.g., -fsanitize=fuzzer-no-link
+// FIXME: Update Apple deployment target so that thread_local is always
+// supported, and remove the #if.
+#if !SANITIZER_APPLE
 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE uptr __sancov_lowest_stack;
+thread_local uptr __sancov_lowest_stack;
+#endif
 
 #endif  // !SANITIZER_FUCHSIA

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index 6b800820ab80b..98186c429e9c0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -37,15 +37,6 @@
 # define SANITIZER_WEAK_ATTRIBUTE  __attribute__((weak))
 #endif
 
-// TLS is handled 
diff erently on 
diff erent platforms
-#if SANITIZER_LINUX || SANITIZER_NETBSD || \
-  SANITIZER_FREEBSD
-# define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \
-    __attribute__((tls_model("initial-exec"))) thread_local
-#else
-# define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE
-#endif
-
 //--------------------------- WEAK FUNCTIONS ---------------------------------//
 // When working with weak functions, to simplify the code and make it more
 // portable, when possible define a default implementation using this macro:


        


More information about the llvm-commits mailing list