Browse files

[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 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:

git-svn-id: 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information...
mgorny committed Dec 23, 2018
1 parent cd741c9 commit aa2e55581abf8c360e78c38454e4c5e6053788e1
Showing with 14 additions and 2 deletions.
  1. +1 −1 lib/xray/
  2. +10 −0 lib/xray/xray_defs.h
  3. +3 −1 lib/xray/
@@ -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;
@@ -19,4 +19,14 @@

// NetBSD: thread_local is not aligned properly, and the code relying
// on it segfaults
#define XRAY_TLS_ALIGNAS(x) alignas(x)

#endif // XRAY_XRAY_DEFS_H
@@ -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).
static_assert(alignof(ThreadLocalData) >= 64,
"ThreadLocalData must be cache line aligned.");
static ThreadLocalData &getThreadLocalData() {
thread_local typename std::aligned_storage<
sizeof(ThreadLocalData), alignof(ThreadLocalData)>::type TLDStorage{};

0 comments on commit aa2e555

Please sign in to comment.