From 698e107ee970ae719b6cad10a783b1957dc11281 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Fri, 15 Apr 2016 20:53:03 -0400 Subject: [PATCH] Workaround clang bug on OSX when the tls variable is too large By allocating the buffer at runtime with `mmap`. Fixes #15647 --- src/julia_threads.h | 3 ++- src/threading.c | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/julia_threads.h b/src/julia_threads.h index f9546bf091e7f..0444549160488 100644 --- a/src/julia_threads.h +++ b/src/julia_threads.h @@ -52,7 +52,8 @@ typedef struct _jl_tls_states_t { jl_jmp_buf *safe_restore; int16_t tid; size_t bt_size; - uintptr_t bt_data[JL_MAX_BT_SIZE + 1]; + // JL_MAX_BT_SIZE + 1 elements long + uintptr_t *bt_data; } jl_tls_states_t; #ifdef __MIC__ diff --git a/src/threading.c b/src/threading.c index 6479813ec4486..89b01db3f9f1f 100644 --- a/src/threading.c +++ b/src/threading.c @@ -105,6 +105,13 @@ static void ti_initthread(int16_t tid) ptls->pgcstack = NULL; ptls->gc_state = 0; // GC unsafe ptls->current_module = NULL; + void *bt_data = malloc(sizeof(uintptr_t) * (JL_MAX_BT_SIZE + 1)); + if (bt_data == NULL) { + jl_printf(JL_STDERR, "could not allocate backtrace buffer\n"); + gc_debug_critical_error(); + abort(); + } + ptls->bt_data = (uintptr_t*)bt_data; #ifdef JULIA_ENABLE_THREADING jl_all_heaps[tid] = jl_mk_thread_heap(); #else