diff --git a/include/runtime/header.h b/include/runtime/header.h index ec48ca294..0400f3c13 100644 --- a/include/runtime/header.h +++ b/include/runtime/header.h @@ -47,8 +47,14 @@ size_t hash_k(block *); void k_hash(block *, void *); bool hash_enter(void); void hash_exit(void); - +#ifdef __MACH__ + // + // thread_local disabled for Apple + // +extern bool gc_enabled; +#else extern thread_local bool gc_enabled; +#endif } class k_elem { diff --git a/lib/codegen/CreateTerm.cpp b/lib/codegen/CreateTerm.cpp index 02c8d0b54..690cdb8f9 100644 --- a/lib/codegen/CreateTerm.cpp +++ b/lib/codegen/CreateTerm.cpp @@ -782,11 +782,17 @@ llvm::Value *create_term::disable_gc() { llvm::Constant *global = module_->getOrInsertGlobal("gc_enabled", llvm::Type::getInt1Ty(ctx_)); auto *global_var = llvm::cast(global); - global_var->setThreadLocal(true); #ifdef __MACH__ + // + // thread_local disabled for Apple + // + /* + global_var->setThreadLocal(true); llvm::IRBuilder b(current_block_); auto *global_var_address = b.CreateThreadLocalAddress(global_var); + */ #else + global_var->setThreadLocal(true); auto *global_var_address = global_var; #endif auto *old_val = new llvm::LoadInst( @@ -801,11 +807,17 @@ void create_term::enable_gc(llvm::Value *was_enabled) { llvm::Constant *global = module_->getOrInsertGlobal("gc_enabled", llvm::Type::getInt1Ty(ctx_)); auto *global_var = llvm::cast(global); - global_var->setThreadLocal(true); #ifdef __MACH__ + // + // thread_local disabled for Apple + // + /* + global_var->setThreadLocal(true); llvm::IRBuilder b(current_block_); auto *global_var_address = b.CreateThreadLocalAddress(global_var); + */ #else + global_var->setThreadLocal(true); auto *global_var_address = global_var; #endif new llvm::StoreInst(was_enabled, global_var_address, current_block_); diff --git a/runtime/alloc/arena.cpp b/runtime/alloc/arena.cpp index 183e10d87..b775a0bed 100644 --- a/runtime/alloc/arena.cpp +++ b/runtime/alloc/arena.cpp @@ -149,7 +149,14 @@ static void fresh_block(struct arena *arena) { BLOCK_SIZE - sizeof(memory_block_header)); } +#ifdef __MACH__ + // + // thread_local disabled for Apple + // +bool gc_enabled = true; +#else thread_local bool gc_enabled = true; +#endif __attribute__((noinline)) void * do_alloc_slow(size_t requested, struct arena *arena) { diff --git a/unittests/runtime-collections/lists.cpp b/unittests/runtime-collections/lists.cpp index ce94d2ad7..a8d6ec5e8 100644 --- a/unittests/runtime-collections/lists.cpp +++ b/unittests/runtime-collections/lists.cpp @@ -62,7 +62,15 @@ block D1 = {{1}}; block *DUMMY1 = &D1; } +#ifdef __MACH__ + // + // thread_local disabled for Apple + // +bool gc_enabled; +#else thread_local bool gc_enabled; +#endif + size_t get_gc_threshold() { return SIZE_MAX; }