[PATCH] D107524: Fix COMPILER_RT_DEBUG build for targets that don't support thread local storage.
Dan Liew via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 4 19:36:57 PDT 2021
delcypher created this revision.
delcypher added reviewers: dvyukov, vitalybuka, aralisza, yln, kubamracek.
delcypher requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.
022439931f5be77efaf80b44d587666b0c9b13b5 <https://reviews.llvm.org/rG022439931f5be77efaf80b44d587666b0c9b13b5> added code that is only enabled
when COMPILER_RT_DEBUG is enabled. This code doesn't build on targets
that don't support thread local storage because the code added uses the
THREADLOCAL macro. Consequently the COMPILER_RT_DEBUG build broke for
some Apple targets (e.g. 32-bit iOS simulators).
To fix this, this patch introduces a `SANITIZER_SUPPORTS_THREADLOCAL`
macro that is `1` iff thread local storage is supported by the current
target. That condition is then added to `SANITIZER_CHECK_DEADLOCKS` to
ensure the code is only enabled when thread local storage is available.
The implementation of `SANITIZER_SUPPORTS_THREADLOCAL` currently assumes
Clang. See `llvm-project/clang/include/clang/Basic/Features.def` for the
definition of the `tls` feature.
rdar://81543007
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107524
Files:
compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
compiler-rt/lib/sanitizer_common/sanitizer_platform.h
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
@@ -377,4 +377,18 @@
#define SANITIZER_SUPPORTS_INIT_FOR_DLOPEN 0
#endif
+// SANITIZER_SUPPORTS_THREADLOCAL
+// 1 - THREADLOCAL macro is supported by target
+// 0 - THREADLOCAL macro is not supported by target
+#ifndef __has_feature
+// TODO: Support other compilers here
+# define SANITIZER_SUPPORTS_THREADLOCAL 1
+#else
+# if __has_feature(tls)
+# define SANITIZER_SUPPORTS_THREADLOCAL 1
+# else
+# define SANITIZER_SUPPORTS_THREADLOCAL 0
+# endif
+#endif
+
#endif // SANITIZER_PLATFORM_H
Index: compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_mutex.h
@@ -95,7 +95,8 @@
// Go linker does not support THREADLOCAL variables,
// so we can't use per-thread state.
-#define SANITIZER_CHECK_DEADLOCKS (SANITIZER_DEBUG && !SANITIZER_GO)
+#define SANITIZER_CHECK_DEADLOCKS \
+ (SANITIZER_DEBUG && !SANITIZER_GO && SANITIZER_SUPPORTS_THREADLOCAL)
#if SANITIZER_CHECK_DEADLOCKS
struct MutexMeta {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107524.364323.patch
Type: text/x-patch
Size: 1331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210805/90474b39/attachment.bin>
More information about the llvm-commits
mailing list