[PATCH] D38854: [scudo] Allow for non-Android Shared TSD platforms, part 2

Aleksey Shlyapnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 13 11:33:02 PDT 2017


alekseyshl added inline comments.


================
Comment at: lib/scudo/scudo_platform.h:26
 // Android and Fuchsia use a pool of TSDs shared between threads.
-# define SCUDO_TSD_EXCLUSIVE 0
-#elif SANITIZER_LINUX && !SANITIZER_ANDROID
+#  define SCUDO_TSD_EXCLUSIVE 0
+# elif SANITIZER_LINUX && !SANITIZER_ANDROID
----------------
cryptoad wrote:
> alekseyshl wrote:
> > What's going to happen if we define SCUDO_TSD_EXCLUSIVE at compile time on these platforms?
> It will blow up at runtime (see main comment of the patch).
> Android doesn't have ELF TLS but it's planned for some point. They do have emutls but it doesn't work for us.
> Fuchsia I think supports a non emulated TLS, I'd have to double check.
> I can put some safeguards?
Yep, something like this:

  #define SCUDO_TSD_EXCLUSIVE_SUPPORTED (!SANITIZER_ANDROID && !SANITIZER_FUCHSIA)

  #ifndef SCUDO_TSD_EXCLUSIVE
  ...
  #endif  // SCUDO_TSD_EXCLUSIVE

  #if SCUDO_TSD_EXCLUSIVE && !SCUDO_TSD_EXCLUSIVE_SUPPORTED
  # error ...
  #endif



================
Comment at: lib/scudo/scudo_tsd_shared.cpp:35
 static void initOnce() {
-  // Hack: TLS_SLOT_TSAN was introduced in N. To be able to use it on M for
-  // testing, we create an unused key. Since the key_data array follows the tls
-  // array, it basically gives us the extra entry we need.
-  // TODO(kostyak): remove and restrict to N and above.
   CHECK_EQ(pthread_key_create(&PThreadKey, NULL), 0);
   initScudo();
----------------
cryptoad wrote:
> alekseyshl wrote:
> > You do not need this PThreadKey on Android, right? Maybe it does make sense to separate implementations along these lines? Move PThreadKey and Android into separate cpp files and link what you need?
> Correct, it's not needed, it's useful on Android to makes things work on older platforms (the comment that I removed explains it).
> I guess the issue with the separation is that it will end up affecting the .inc as well, which would have to be split or have further #ifs (the pthread key is used there). If you see a way to make this work, I can accommodate that.
If you are going to support O and below, I guess, the current way is fine. If you are not going to support releases before N, I'd suggest to separate implementations and either have 4 more files:
for getCurrentTSD:
  scudo_tsd_shared_android.inc
  scudo_tsd_shared_pthread.inc
for setCurrentTSD and the function called from initOnce (empty for Android):
  scudo_tsd_shared_android_impl.inc
  scudo_tsd_shared_pthread_impl.inc

or, another option is to define SCUDO_TSD_CPP_ and add two files, scudo_tsd_shared_android.inc and scudo_tsd_shared_pthread.inc, the pthread one will do something like this (android inc will look a bit simpler):

  #ifdef SCUDO_TSD_CPP_
  pthread_key_t PThreadKey;
  ALWAYS_INLINE void setCurrentTSD(ScudoTSD *TSD) { ... }
  void initSharedTsdOnce() { ... }
  #else
  extern pthread_key_t PThreadKey;
  ALWAYS_INLINE ScudoTSD* getCurrentTSD() { ... }
  #endif

Both ways are pretty ugly.

Well, ok, I guess enough with that, I'll let you pick the way and accept your choice.


https://reviews.llvm.org/D38854





More information about the llvm-commits mailing list