[PATCH] D146351: sanitizer_common: Use plain thread_local for __sancov_lowest_stack definition.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 21:04:00 PDT 2023


pcc created this revision.
pcc added reviewers: vitalybuka, hctim.
Herald added subscribers: Enna1, krytarowski.
Herald added a project: All.
pcc requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146351

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


Index: compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -37,15 +37,6 @@
 # define SANITIZER_WEAK_ATTRIBUTE  __attribute__((weak))
 #endif
 
-// TLS is handled differently on different 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:
Index: compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cpp
@@ -283,6 +283,6 @@
 // and later linked with code containing a strong definition.
 // E.g., -fsanitize=fuzzer-no-link
 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
-SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE uptr __sancov_lowest_stack;
+thread_local uptr __sancov_lowest_stack;
 
 #endif  // !SANITIZER_FUCHSIA


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146351.506272.patch
Type: text/x-patch
Size: 1481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230318/b5373c90/attachment.bin>


More information about the llvm-commits mailing list