diff options
author | Michal Gorny <mgorny@gentoo.org> | 2018-12-23 15:09:20 +0000 |
---|---|---|
committer | Michal Gorny <mgorny@gentoo.org> | 2018-12-23 15:09:20 +0000 |
commit | 470ce63251657e1370fedede313b70f15bf55774 (patch) | |
tree | 802ec09d8807b4bc826224cd3410bca523f3e509 /compiler-rt/lib/xray | |
parent | dae01c352b98022dddbf1aec8a25c919d3389d9e (diff) | |
download | bcm5719-llvm-470ce63251657e1370fedede313b70f15bf55774.tar.gz bcm5719-llvm-470ce63251657e1370fedede313b70f15bf55774.zip |
[xray] Disable alignas() for thread_local objects on NetBSD
Disable enforcing alignas() for structs that are used as thread_local
data on NetBSD. The NetBSD ld.so implementation is buggy and does
not enforce correct alignment; however, clang seems to take it for
granted and generates instructions that segv on wrongly aligned objects.
Therefore, disable those alignas() statements on NetBSD until we can
establish a better fix.
Apparently, std::aligned_storage<> does not have any real effect
at the moment, so we can leave it as-is.
Differential Revision: https://reviews.llvm.org/D56000
llvm-svn: 350029
Diffstat (limited to 'compiler-rt/lib/xray')
-rw-r--r-- | compiler-rt/lib/xray/xray_basic_logging.cc | 2 | ||||
-rw-r--r-- | compiler-rt/lib/xray/xray_defs.h | 10 | ||||
-rw-r--r-- | compiler-rt/lib/xray/xray_fdr_logging.cc | 4 |
3 files changed, 14 insertions, 2 deletions
diff --git a/compiler-rt/lib/xray/xray_basic_logging.cc b/compiler-rt/lib/xray/xray_basic_logging.cc index b65c0e43e95..ae1cc0ba79d 100644 --- a/compiler-rt/lib/xray/xray_basic_logging.cc +++ b/compiler-rt/lib/xray/xray_basic_logging.cc @@ -55,7 +55,7 @@ struct alignas(16) StackEntry { static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry"); -struct alignas(64) ThreadLocalData { +struct XRAY_TLS_ALIGNAS(64) ThreadLocalData { void *InMemoryBuffer = nullptr; size_t BufferSize = 0; size_t BufferOffset = 0; diff --git a/compiler-rt/lib/xray/xray_defs.h b/compiler-rt/lib/xray/xray_defs.h index e5c37c0665d..c009bcc879f 100644 --- a/compiler-rt/lib/xray/xray_defs.h +++ b/compiler-rt/lib/xray/xray_defs.h @@ -19,4 +19,14 @@ #define XRAY_NEVER_INSTRUMENT #endif +#if SANITIZER_NETBSD +// NetBSD: thread_local is not aligned properly, and the code relying +// on it segfaults +#define XRAY_TLS_ALIGNAS(x) +#define XRAY_HAS_TLS_ALIGNAS 0 +#else +#define XRAY_TLS_ALIGNAS(x) alignas(x) +#define XRAY_HAS_TLS_ALIGNAS 1 +#endif + #endif // XRAY_XRAY_DEFS_H diff --git a/compiler-rt/lib/xray/xray_fdr_logging.cc b/compiler-rt/lib/xray/xray_fdr_logging.cc index 3893b7a2aaa..1eda26df7a8 100644 --- a/compiler-rt/lib/xray/xray_fdr_logging.cc +++ b/compiler-rt/lib/xray/xray_fdr_logging.cc @@ -51,7 +51,7 @@ namespace { // call so that it can be initialized on first use instead of as a global. We // force the alignment to 64-bytes for x86 cache line alignment, as this // structure is used in the hot path of implementation. -struct alignas(64) ThreadLocalData { +struct XRAY_TLS_ALIGNAS(64) ThreadLocalData { BufferQueue::Buffer Buffer{}; BufferQueue *BQ = nullptr; @@ -124,8 +124,10 @@ static atomic_sint32_t LogFlushStatus = { // critical section, calling a function that might be XRay instrumented (and // thus in turn calling into malloc by virtue of registration of the // thread_local's destructor). +#if XRAY_HAS_TLS_ALIGNAS static_assert(alignof(ThreadLocalData) >= 64, "ThreadLocalData must be cache line aligned."); +#endif static ThreadLocalData &getThreadLocalData() { thread_local typename std::aligned_storage< sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{}; |