[PATCH] D56000: [compiler-rt] [xray] Disable alignas() for thread_local objects on NetBSD
Michał Górny via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 21 06:05:53 PST 2018
mgorny created this revision.
mgorny added reviewers: krytarowski, dberris, vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits.
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.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D56000
Files:
lib/xray/xray_basic_logging.cc
lib/xray/xray_fdr_logging.cc
Index: lib/xray/xray_fdr_logging.cc
===================================================================
--- lib/xray/xray_fdr_logging.cc
+++ lib/xray/xray_fdr_logging.cc
@@ -51,7 +51,12 @@
// 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
+/* TLD is not aligned properly on NetBSD, resulting in segfault */
+#if !SANITIZER_NETBSD
+alignas(64)
+#endif
+ThreadLocalData {
BufferQueue::Buffer Buffer{};
BufferQueue *BQ = nullptr;
@@ -124,8 +129,10 @@
// 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 !SANITIZER_NETBSD
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{};
Index: lib/xray/xray_basic_logging.cc
===================================================================
--- lib/xray/xray_basic_logging.cc
+++ lib/xray/xray_basic_logging.cc
@@ -55,7 +55,12 @@
static_assert(sizeof(StackEntry) == 16, "Wrong size for StackEntry");
-struct alignas(64) ThreadLocalData {
+struct
+/* TLD is not aligned properly on NetBSD, resulting in segfault */
+#if !SANITIZER_NETBSD
+alignas(64)
+#endif
+ThreadLocalData {
void *InMemoryBuffer = nullptr;
size_t BufferSize = 0;
size_t BufferOffset = 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56000.179279.patch
Type: text/x-patch
Size: 1692 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181221/9262f40b/attachment.bin>
More information about the cfe-commits
mailing list