[PATCH] D70472: scudo: Only use the Android reserved TLS slot when building libc's copy of the allocator.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 19 15:55:25 PST 2019


pcc created this revision.
pcc added reviewers: cryptoad, cferris.
Herald added subscribers: Sanitizers, mgorny, srhines.
Herald added projects: Sanitizers, LLVM.

When we're not building libc's allocator, just use a regular TLS variable. This
lets the unit tests pass on Android devices whose libc uses Scudo. Otherwise
libc's copy of Scudo and the unit tests' copy will both try to use the same
TLS slot, in likely incompatible ways.

This requires using ELF TLS, so start passing -fno-emulated-tls when building
the library and the unit tests on Android.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70472

Files:
  compiler-rt/lib/scudo/standalone/CMakeLists.txt
  compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
  compiler-rt/lib/scudo/standalone/tsd_shared.h


Index: compiler-rt/lib/scudo/standalone/tsd_shared.h
===================================================================
--- compiler-rt/lib/scudo/standalone/tsd_shared.h
+++ compiler-rt/lib/scudo/standalone/tsd_shared.h
@@ -72,7 +72,7 @@
 
 private:
   ALWAYS_INLINE void setCurrentTSD(TSD<Allocator> *CurrentTSD) {
-#if SCUDO_ANDROID
+#if _BIONIC
     *getAndroidTlsPtr() = reinterpret_cast<uptr>(CurrentTSD);
 #elif SCUDO_LINUX
     ThreadTSD = CurrentTSD;
@@ -84,7 +84,7 @@
   }
 
   ALWAYS_INLINE TSD<Allocator> *getCurrentTSD() {
-#if SCUDO_ANDROID
+#if _BIONIC
     return reinterpret_cast<TSD<Allocator> *>(*getAndroidTlsPtr());
 #elif SCUDO_LINUX
     return ThreadTSD;
@@ -152,12 +152,12 @@
   u32 CoPrimes[MaxTSDCount];
   bool Initialized;
   HybridMutex Mutex;
-#if SCUDO_LINUX && !SCUDO_ANDROID
+#if SCUDO_LINUX && !_BIONIC
   static THREADLOCAL TSD<Allocator> *ThreadTSD;
 #endif
 };
 
-#if SCUDO_LINUX && !SCUDO_ANDROID
+#if SCUDO_LINUX && !_BIONIC
 template <class Allocator, u32 MaxTSDCount>
 THREADLOCAL TSD<Allocator>
     *TSDRegistrySharedT<Allocator, MaxTSDCount>::ThreadTSD;
Index: compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
===================================================================
--- compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
+++ compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
@@ -16,6 +16,10 @@
   # TODO(kostyak): find a way to make -fsized-deallocation work
   -Wno-mismatched-new-delete)
 
+if(ANDROID)
+  list(APPEND SCUDO_UNITTEST_CFLAGS -fno-emulated-tls)
+endif()
+
 set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH})
 
 # gtests requires c++
Index: compiler-rt/lib/scudo/standalone/CMakeLists.txt
===================================================================
--- compiler-rt/lib/scudo/standalone/CMakeLists.txt
+++ compiler-rt/lib/scudo/standalone/CMakeLists.txt
@@ -29,6 +29,8 @@
 append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SCUDO_LINK_FLAGS)
 
 if(ANDROID)
+  list(APPEND SCUDO_CFLAGS -fno-emulated-tls)
+
 # Put the shared library in the global group. For more details, see
 # android-changes-for-ndk-developers.md#changes-to-library-search-order
   append_list_if(COMPILER_RT_HAS_Z_GLOBAL -Wl,-z,global SCUDO_LINK_FLAGS)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70472.230164.patch
Type: text/x-patch
Size: 2233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191119/de11316d/attachment.bin>


More information about the llvm-commits mailing list