summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-03-17 09:56:10 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-03-17 15:01:21 +0300
commitad112a13bdfb04ae7ff768668ba6616577cc100d (patch)
tree2d84d8e12c239a2f8a6542865c76c330b42bd7b7
parent6c63aba2e25ed05005e49a12e187e03063732dd1 (diff)
downloadbdwgc-ad112a13bdfb04ae7ff768668ba6616577cc100d.tar.gz
Fix assertion violation of GC_thread_key alignment if pthread-based TLS
(fix of commit d692eb432) It is needed to push GC_thread_key only in case of USE_CUSTOM_SPECIFIC; it could have any alignment otherwise (e.g., if it is of pthread_key_t type). * thread_support.c [THREAD_LOCAL_ALLOC] (GC_push_thread_structures): Push GC_thread_key only if USE_CUSTOM_SPECIFIC. * win32_threads.c [THREAD_LOCAL_ALLOC] (GC_push_thread_structures): Likewise. * thread_local_alloc.c [THREAD_LOCAL_ALLOC] (GC_init_thread_local): Do not assert GC_thread_key is word-aligned unless USE_CUSTOM_SPECIFIC; add comment.
-rw-r--r--pthread_support.c2
-rw-r--r--thread_local_alloc.c5
-rw-r--r--win32_threads.c2
3 files changed, 6 insertions, 3 deletions
diff --git a/pthread_support.c b/pthread_support.c
index 080dc7aa..4986448b 100644
--- a/pthread_support.c
+++ b/pthread_support.c
@@ -552,7 +552,7 @@ void GC_push_thread_structures(void)
# ifdef E2K
GC_PUSH_ALL_SYM(first_thread.backing_store_end);
# endif
-# if defined(THREAD_LOCAL_ALLOC)
+# if defined(THREAD_LOCAL_ALLOC) && defined(USE_CUSTOM_SPECIFIC)
GC_PUSH_ALL_SYM(GC_thread_key);
# endif
}
diff --git a/thread_local_alloc.c b/thread_local_alloc.c
index 52c5863f..900bcaeb 100644
--- a/thread_local_alloc.c
+++ b/thread_local_alloc.c
@@ -98,7 +98,10 @@ GC_INNER void GC_init_thread_local(GC_tlfs p)
GC_ASSERT(I_HOLD_LOCK());
if (!EXPECT(keys_initialized, TRUE)) {
- GC_ASSERT((word)&GC_thread_key % sizeof(word) == 0);
+# ifdef USE_CUSTOM_SPECIFIC
+ /* Ensure proper alignment of a "pushed" GC symbol. */
+ GC_ASSERT((word)&GC_thread_key % sizeof(word) == 0);
+# endif
res = GC_key_create(&GC_thread_key, reset_thread_key);
if (COVERT_DATAFLOW(res) != 0) {
ABORT("Failed to create key for local allocator");
diff --git a/win32_threads.c b/win32_threads.c
index bef0a224..434350a7 100644
--- a/win32_threads.c
+++ b/win32_threads.c
@@ -1247,7 +1247,7 @@ void GC_push_thread_structures(void)
/* else */ {
GC_PUSH_ALL_SYM(GC_threads);
}
-# if defined(THREAD_LOCAL_ALLOC)
+# if defined(THREAD_LOCAL_ALLOC) && defined(USE_CUSTOM_SPECIFIC)
GC_PUSH_ALL_SYM(GC_thread_key);
/* Just in case we ever use our own TLS implementation. */
# endif