From b69a4b52c02475af35a3b213abb352584fc05009 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 4 Sep 2019 12:02:16 +0200 Subject: [PATCH] Fix #147: provide CMake option for alternate TLS mechanism This allows use of dlopen() with mimalloc on Unix. --- CMakeLists.txt | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0600ed5d..8a4f871e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,13 +4,14 @@ include("cmake/mimalloc-config-version.cmake") set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 17) -option(MI_OVERRIDE "Override the standard malloc interface" ON) -option(MI_INTERPOSE "Use interpose to override standard malloc on macOS" ON) -option(MI_SEE_ASM "Generate assembly files" OFF) -option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode" OFF) -option(MI_USE_CXX "Use the C++ compiler to compile the library" OFF) -option(MI_SECURE "Use security mitigations (like guard pages and randomization)" OFF) -option(MI_BUILD_TESTS "Build test executables" ON) +option(MI_OVERRIDE "Override the standard malloc interface" ON) +option(MI_INTERPOSE "Use interpose to override standard malloc on macOS" ON) +option(MI_SEE_ASM "Generate assembly files" OFF) +option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode" OFF) +option(MI_USE_CXX "Use the C++ compiler to compile the library" OFF) +option(MI_SECURE "Use security mitigations (like guard pages and randomization)" OFF) +option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF) +option(MI_BUILD_TESTS "Build test executables" ON) set(mi_install_dir "lib/mimalloc-${mi_version}") @@ -84,7 +85,12 @@ endif() # Compiler flags if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU") - list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -ftls-model=initial-exec) + list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas) + if(MI_LOCAL_DYNAMIC_TLS MATCHES "ON") + list(APPEND mi_cflags -ftls-model=local-dynamic) + else() + list(APPEND mi_cflags -ftls-model=initial-exec) + endif() if(CMAKE_C_COMPILER_ID MATCHES "GNU") list(APPEND mi_cflags -Wno-invalid-memory-model) list(APPEND mi_cflags -fvisibility=hidden)