Skip to content

Commit a62e42b

Browse files
Add the --disable-initial-exec-tls configure option.
Right now we always make our TLS use the initial-exec model if the compiler supports it. This change allows configure-time disabling of this setting, which can be helpful when dynamically loading jemalloc is the only option.
1 parent e40b2f7 commit a62e42b

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

INSTALL.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ any of the following arguments (not a definitive list) to 'configure':
265265
configuration, jemalloc will provide additional size classes that are not
266266
16-byte-aligned (24, 40, and 56).
267267

268+
* `--disable-initial-exec-tls`
269+
270+
Disable the initial-exec TLS model for jemalloc's internal thread-local
271+
storage (on those platforms that support explicit settings). This can allow
272+
jemalloc to be dynamically loaded after program starup (e.g. using dlopen).
273+
Note that in this case, there will be two malloc implementations operating
274+
in the same process, which will almost certainly result in confusing runtime
275+
crashes if pointers leak from one implementation to the other.
276+
268277
The following environment variables (not a definitive list) impact configure's
269278
behavior:
270279

configure.ac

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,9 @@ JE_COMPILABLE([tls_model attribute], [],
733733
foo = 0;],
734734
[je_cv_tls_model])
735735
JE_CFLAGS_RESTORE()
736-
if test "x${je_cv_tls_model}" = "xyes" ; then
737-
AC_DEFINE([JEMALLOC_TLS_MODEL],
738-
[__attribute__((tls_model("initial-exec")))])
739-
else
740-
AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
741-
fi
736+
dnl (Setting of JEMALLOC_TLS_MODEL is done later, after we've checked for
737+
dnl --disable-initial-exec-tls)
738+
742739
dnl Check for alloc_size attribute support.
743740
JE_CFLAGS_SAVE()
744741
JE_CFLAGS_ADD([-Werror])
@@ -1993,6 +1990,29 @@ if test "x${enable_zone_allocator}" = "x1" ; then
19931990
AC_DEFINE([JEMALLOC_ZONE], [ ])
19941991
fi
19951992

1993+
dnl ============================================================================
1994+
dnl Use initial-exec TLS by default.
1995+
AC_ARG_ENABLE([initial-exec-tls],
1996+
[AS_HELP_STRING([--disable-initial-exec-tls],
1997+
[Disable the initial-exec tls model])],
1998+
[if test "x$enable_initial_exec_tls" = "xno" ; then
1999+
enable_initial_exec_tls="0"
2000+
else
2001+
enable_initial_exec_tls="1"
2002+
fi
2003+
],
2004+
[enable_initial_exec_tls="1"]
2005+
)
2006+
AC_SUBST([enable_initial_exec_tls])
2007+
2008+
if test "x${je_cv_tls_model}" = "xyes" -a \
2009+
"x${enable_initial_exec_tls}" = "x1" ; then
2010+
AC_DEFINE([JEMALLOC_TLS_MODEL],
2011+
[__attribute__((tls_model("initial-exec")))])
2012+
else
2013+
AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
2014+
fi
2015+
19962016
dnl ============================================================================
19972017
dnl Enable background threads if possible.
19982018

0 commit comments

Comments
 (0)