Skip to content

Commit ff34548

Browse files
danliew-appledelcypher
authored andcommitted
Fix COMPILER_RT_DEBUG build for targets that don't support thread local storage.
0224399 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). ``` /Volumes/user_data/dev/llvm/llvm.org/main/src/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_mutex.cpp:216:8: error: thread-local storage is not supported for the current target static THREADLOCAL InternalDeadlockDetector deadlock_detector; ^ /Volumes/user_data/dev/llvm/llvm.org/main/src/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h:227:24: note: expanded from macro 'THREADLOCAL' # define THREADLOCAL __thread ^ 1 error generated. ``` 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 Differential Revision: https://reviews.llvm.org/D107524 (cherry picked from commit a756239)
1 parent 9e55f45 commit ff34548

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_mutex.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ enum {
9595

9696
// Go linker does not support THREADLOCAL variables,
9797
// so we can't use per-thread state.
98-
#define SANITIZER_CHECK_DEADLOCKS (SANITIZER_DEBUG && !SANITIZER_GO)
98+
#define SANITIZER_CHECK_DEADLOCKS \
99+
(SANITIZER_DEBUG && !SANITIZER_GO && SANITIZER_SUPPORTS_THREADLOCAL)
99100

100101
#if SANITIZER_CHECK_DEADLOCKS
101102
struct MutexMeta {

compiler-rt/lib/sanitizer_common/sanitizer_platform.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,18 @@
377377
#define SANITIZER_SUPPORTS_INIT_FOR_DLOPEN 0
378378
#endif
379379

380+
// SANITIZER_SUPPORTS_THREADLOCAL
381+
// 1 - THREADLOCAL macro is supported by target
382+
// 0 - THREADLOCAL macro is not supported by target
383+
#ifndef __has_feature
384+
// TODO: Support other compilers here
385+
# define SANITIZER_SUPPORTS_THREADLOCAL 1
386+
#else
387+
# if __has_feature(tls)
388+
# define SANITIZER_SUPPORTS_THREADLOCAL 1
389+
# else
390+
# define SANITIZER_SUPPORTS_THREADLOCAL 0
391+
# endif
392+
#endif
393+
380394
#endif // SANITIZER_PLATFORM_H

0 commit comments

Comments
 (0)