1 dnl Process this file with autoconf to produce a configure script.
4 AC_CONFIG_AUX_DIR([build-aux])
6 dnl ============================================================================
7 dnl Custom macro definitions.
9 dnl JE_CFLAGS_APPEND(cflag)
10 AC_DEFUN([JE_CFLAGS_APPEND],
12 AC_MSG_CHECKING([whether compiler supports $1])
14 if test "x${CFLAGS}" = "x" ; then
19 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
24 [je_cv_cflags_appended=$1]
26 [je_cv_cflags_appended=]
32 dnl JE_COMPILABLE(label, hcode, mcode, rvar)
34 dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
36 AC_DEFUN([JE_COMPILABLE],
38 AC_CACHE_CHECK([whether $1 is compilable],
40 [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
46 dnl ============================================================================
48 CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
56 if test "x${srcroot}" = "x." ; then
62 abs_srcroot="`cd \"${srcdir}\"; pwd`/"
63 AC_SUBST([abs_srcroot])
68 AC_SUBST([abs_objroot])
70 dnl Munge install path variables.
71 if test "x$prefix" = "xNONE" ; then
74 if test "x$exec_prefix" = "xNONE" ; then
79 BINDIR=`eval echo $bindir`
80 BINDIR=`eval echo $BINDIR`
82 INCLUDEDIR=`eval echo $includedir`
83 INCLUDEDIR=`eval echo $INCLUDEDIR`
84 AC_SUBST([INCLUDEDIR])
85 LIBDIR=`eval echo $libdir`
86 LIBDIR=`eval echo $LIBDIR`
88 DATADIR=`eval echo $datadir`
89 DATADIR=`eval echo $DATADIR`
91 MANDIR=`eval echo $mandir`
92 MANDIR=`eval echo $MANDIR`
95 dnl Support for building documentation.
96 AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
97 if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
98 DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
99 elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
100 DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
102 dnl Documentation building will fail if this default gets used.
105 AC_ARG_WITH([xslroot],
106 [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
107 if test "x$with_xslroot" = "xno" ; then
108 XSLROOT="${DEFAULT_XSLROOT}"
110 XSLROOT="${with_xslroot}"
113 XSLROOT="${DEFAULT_XSLROOT}"
117 dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
118 dnl just prevent autoconf from molesting CFLAGS.
121 if test "x$GCC" != "xyes" ; then
122 AC_CACHE_CHECK([whether compiler is MSVC],
124 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
134 if test "x$CFLAGS" = "x" ; then
136 if test "x$GCC" = "xyes" ; then
137 JE_CFLAGS_APPEND([-std=gnu99])
138 if test "x$je_cv_cflags_appended" = "x-std=gnu99" ; then
139 AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
141 JE_CFLAGS_APPEND([-Wall])
142 JE_CFLAGS_APPEND([-Werror=declaration-after-statement])
143 JE_CFLAGS_APPEND([-Wshorten-64-to-32])
144 JE_CFLAGS_APPEND([-pipe])
145 JE_CFLAGS_APPEND([-g3])
146 elif test "x$je_cv_msvc" = "xyes" ; then
148 JE_CFLAGS_APPEND([-Zi])
149 JE_CFLAGS_APPEND([-MT])
150 JE_CFLAGS_APPEND([-W3])
151 JE_CFLAGS_APPEND([-FS])
152 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat"
155 dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
156 if test "x$EXTRA_CFLAGS" != "x" ; then
157 JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
161 AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
162 if test "x${ac_cv_big_endian}" = "x1" ; then
163 AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
166 if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
167 CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
170 if test "x${je_cv_msvc}" = "xyes" ; then
171 LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
172 AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
174 AC_CHECK_SIZEOF([void *])
175 if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
177 elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
180 AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
183 AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
185 AC_CHECK_SIZEOF([int])
186 if test "x${ac_cv_sizeof_int}" = "x8" ; then
188 elif test "x${ac_cv_sizeof_int}" = "x4" ; then
191 AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
193 AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
195 AC_CHECK_SIZEOF([long])
196 if test "x${ac_cv_sizeof_long}" = "x8" ; then
198 elif test "x${ac_cv_sizeof_long}" = "x4" ; then
201 AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
203 AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
205 AC_CHECK_SIZEOF([long long])
206 if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
207 LG_SIZEOF_LONG_LONG=3
208 elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
209 LG_SIZEOF_LONG_LONG=2
211 AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
213 AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
215 AC_CHECK_SIZEOF([intmax_t])
216 if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
218 elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
220 elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
223 AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
225 AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
228 dnl CPU-specific settings.
230 case "${host_cpu}" in
232 if test "x${je_cv_msvc}" = "xyes" ; then
233 AC_CACHE_VAL([je_cv_pause_msvc],
234 [JE_COMPILABLE([pause instruction MSVC], [],
235 [[_mm_pause(); return 0;]],
236 [je_cv_pause_msvc])])
237 if test "x${je_cv_pause_msvc}" = "xyes" ; then
238 CPU_SPINWAIT='_mm_pause()'
241 AC_CACHE_VAL([je_cv_pause],
242 [JE_COMPILABLE([pause instruction], [],
243 [[__asm__ volatile("pause"); return 0;]],
245 if test "x${je_cv_pause}" = "xyes" ; then
246 CPU_SPINWAIT='__asm__ volatile("pause")'
251 AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
256 AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
258 LD_PRELOAD_VAR="LD_PRELOAD"
265 DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
266 RPATH='-Wl,-rpath,$(1)'
268 PIC_CFLAGS='-fPIC -DPIC'
276 AN_MAKEVAR([AR], [AC_PROG_AR])
277 AN_PROGRAM([ar], [AC_PROG_AR])
278 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
281 dnl Platform-specific settings. abi and RPATH can probably be determined
282 dnl programmatically, but doing so is error-prone, which makes it generally
283 dnl not worth the trouble.
285 dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
286 dnl definitions need to be seen before any headers are included, which is a pain
287 dnl to make happen otherwise.
291 *-*-darwin* | *-*-ios*)
294 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
296 LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
300 DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
307 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
313 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
318 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
324 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
328 CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
330 AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
331 AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
332 AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
333 AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
337 AC_MSG_CHECKING([ABI])
338 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
345 [CFLAGS="$CFLAGS"; abi="elf"],
347 AC_MSG_RESULT([$abi])
348 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
353 AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
355 dnl Solaris needs this for sigwait().
356 CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
357 LIBS="$LIBS -lposix4 -lsocket -lnsl"
360 if "$LG_SIZEOF_PTR" = "8"; then
362 LD_PRELOAD_VAR="LDR_PRELOAD64"
365 LD_PRELOAD_VAR="LDR_PRELOAD"
369 *-*-mingw* | *-*-cygwin*)
376 if test "x$je_cv_msvc" = "xyes" ; then
379 EXTRA_LDFLAGS="-link -DEBUG"
383 ARFLAGS='-nologo -out:'
388 DSO_LDFLAGS="-shared"
396 AC_MSG_RESULT([Unsupported operating system: ${host}])
401 JEMALLOC_USABLE_SIZE_CONST=const
402 AC_CHECK_HEADERS([malloc.h], [
403 AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
404 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
407 size_t malloc_usable_size(const void *ptr);
412 JEMALLOC_USABLE_SIZE_CONST=
416 AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
419 AC_SUBST([LD_PRELOAD_VAR])
421 AC_SUBST([importlib])
425 AC_SUBST([libprefix])
426 AC_SUBST([DSO_LDFLAGS])
427 AC_SUBST([EXTRA_LDFLAGS])
429 AC_SUBST([PIC_CFLAGS])
437 JE_COMPILABLE([__attribute__ syntax],
438 [static __attribute__((unused)) void foo(void){}],
441 if test "x${je_cv_attribute}" = "xyes" ; then
442 AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
443 if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
444 JE_CFLAGS_APPEND([-fvisibility=hidden])
447 dnl Check for tls_model attribute support (clang 3.0 still lacks support).
448 SAVED_CFLAGS="${CFLAGS}"
449 JE_CFLAGS_APPEND([-Werror])
450 JE_COMPILABLE([tls_model attribute], [],
452 __attribute__((tls_model("initial-exec"), unused)) foo;
455 CFLAGS="${SAVED_CFLAGS}"
456 if test "x${je_cv_tls_model}" = "xyes" ; then
457 AC_DEFINE([JEMALLOC_TLS_MODEL],
458 [__attribute__((tls_model("initial-exec")))])
460 AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
462 dnl Check for alloc_size attribute support.
463 SAVED_CFLAGS="${CFLAGS}"
464 JE_CFLAGS_APPEND([-Werror])
465 JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
466 [void *foo(size_t size) __attribute__((alloc_size(1)));],
468 CFLAGS="${SAVED_CFLAGS}"
469 if test "x${je_cv_alloc_size}" = "xyes" ; then
470 AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
472 dnl Check for format(gnu_printf, ...) attribute support.
473 SAVED_CFLAGS="${CFLAGS}"
474 JE_CFLAGS_APPEND([-Werror])
475 JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
476 [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
477 [je_cv_format_gnu_printf])
478 CFLAGS="${SAVED_CFLAGS}"
479 if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
480 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
482 dnl Check for format(printf, ...) attribute support.
483 SAVED_CFLAGS="${CFLAGS}"
484 JE_CFLAGS_APPEND([-Werror])
485 JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
486 [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
487 [je_cv_format_printf])
488 CFLAGS="${SAVED_CFLAGS}"
489 if test "x${je_cv_format_printf}" = "xyes" ; then
490 AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
493 dnl Support optional additions to rpath.
495 [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
496 if test "x$with_rpath" = "xno" ; then
499 RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
503 AC_SUBST([RPATH_EXTRA])
505 dnl Disable rules that do automatic regeneration of configure output by default.
506 AC_ARG_ENABLE([autogen],
507 [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
508 if test "x$enable_autogen" = "xno" ; then
516 AC_SUBST([enable_autogen])
520 AC_PATH_PROG([LD], [ld], [false], [$PATH])
521 AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
523 public_syms="malloc_conf malloc_message malloc calloc posix_memalign aligned_alloc realloc free mallocx rallocx xallocx sallocx dallocx sdallocx nallocx mallctl mallctlnametomib mallctlbymib malloc_stats_print malloc_usable_size"
525 dnl Check for allocator-related functions that should be wrapped.
526 AC_CHECK_FUNC([memalign],
527 [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
528 public_syms="${public_syms} memalign"])
529 AC_CHECK_FUNC([valloc],
530 [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
531 public_syms="${public_syms} valloc"])
533 dnl Do not compute test code coverage by default.
535 AC_ARG_ENABLE([code-coverage],
536 [AS_HELP_STRING([--enable-code-coverage],
537 [Enable code coverage])],
538 [if test "x$enable_code_coverage" = "xno" ; then
539 enable_code_coverage="0"
541 enable_code_coverage="1"
544 [enable_code_coverage="0"]
546 if test "x$enable_code_coverage" = "x1" ; then
548 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
549 if test "x${deoptimize}" = "xyes" ; then
550 JE_CFLAGS_APPEND([-O0])
552 JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
553 EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
554 AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
556 AC_SUBST([enable_code_coverage])
558 dnl Perform no name mangling by default.
559 AC_ARG_WITH([mangling],
560 [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
561 [mangling_map="$with_mangling"], [mangling_map=""])
563 dnl Do not prefix public APIs by default.
564 AC_ARG_WITH([jemalloc_prefix],
565 [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
566 [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
567 [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
570 JEMALLOC_PREFIX="je_"
573 if test "x$JEMALLOC_PREFIX" != "x" ; then
574 JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
575 AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
576 AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
578 AC_SUBST([JEMALLOC_CPREFIX])
580 AC_ARG_WITH([export],
581 [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
582 [if test "x$with_export" = "xno"; then
583 AC_DEFINE([JEMALLOC_EXPORT],[])
587 dnl Mangle library-private APIs.
588 AC_ARG_WITH([private_namespace],
589 [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
590 [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
591 [JEMALLOC_PRIVATE_NAMESPACE="je_"]
593 AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
594 private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
595 AC_SUBST([private_namespace])
597 dnl Do not add suffix to installed files by default.
598 AC_ARG_WITH([install_suffix],
599 [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
600 [INSTALL_SUFFIX="$with_install_suffix"],
603 install_suffix="$INSTALL_SUFFIX"
604 AC_SUBST([install_suffix])
606 dnl Specify default malloc_conf.
607 AC_ARG_WITH([malloc_conf],
608 [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
609 [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
610 [JEMALLOC_CONFIG_MALLOC_CONF=""]
612 config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
613 AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
615 dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
616 dnl jemalloc_protos_jet.h easy.
620 cfgoutputs_in="Makefile.in"
621 cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
622 cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
623 cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
624 cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
625 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
626 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
627 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
628 cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
629 cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
630 cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
632 cfgoutputs_out="Makefile"
633 cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
634 cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
635 cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
636 cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
637 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
638 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
639 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
640 cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
641 cfgoutputs_out="${cfgoutputs_out} test/test.sh"
642 cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
644 cfgoutputs_tup="Makefile"
645 cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
646 cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
647 cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
648 cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
649 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
650 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
651 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
652 cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
653 cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
654 cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
656 cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
657 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
658 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
659 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
660 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
661 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
662 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
663 cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
664 cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
665 cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
666 cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
667 cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
669 cfghdrs_out="include/jemalloc/jemalloc_defs.h"
670 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
671 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
672 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
673 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
674 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
675 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
676 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
677 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
678 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
679 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
680 cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
681 cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
682 cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
684 cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
685 cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
686 cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
688 dnl Silence irrelevant compiler warnings by default.
689 AC_ARG_ENABLE([cc-silence],
690 [AS_HELP_STRING([--disable-cc-silence],
691 [Do not silence irrelevant compiler warnings])],
692 [if test "x$enable_cc_silence" = "xno" ; then
693 enable_cc_silence="0"
695 enable_cc_silence="1"
698 [enable_cc_silence="1"]
700 if test "x$enable_cc_silence" = "x1" ; then
701 AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
704 dnl Do not compile with debugging by default.
705 AC_ARG_ENABLE([debug],
706 [AS_HELP_STRING([--enable-debug],
707 [Build debugging code (implies --enable-ivsalloc)])],
708 [if test "x$enable_debug" = "xno" ; then
716 if test "x$enable_debug" = "x1" ; then
717 AC_DEFINE([JEMALLOC_DEBUG], [ ])
719 if test "x$enable_debug" = "x1" ; then
720 AC_DEFINE([JEMALLOC_DEBUG], [ ])
723 AC_SUBST([enable_debug])
725 dnl Do not validate pointers by default.
726 AC_ARG_ENABLE([ivsalloc],
727 [AS_HELP_STRING([--enable-ivsalloc],
728 [Validate pointers passed through the public API])],
729 [if test "x$enable_ivsalloc" = "xno" ; then
735 [enable_ivsalloc="0"]
737 if test "x$enable_ivsalloc" = "x1" ; then
738 AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
741 dnl Only optimize if not debugging.
742 if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
743 dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
745 echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
746 if test "x${optimize}" = "xyes" ; then
747 if test "x$GCC" = "xyes" ; then
748 JE_CFLAGS_APPEND([-O3])
749 JE_CFLAGS_APPEND([-funroll-loops])
750 elif test "x$je_cv_msvc" = "xyes" ; then
751 JE_CFLAGS_APPEND([-O2])
753 JE_CFLAGS_APPEND([-O])
758 dnl Enable statistics calculation by default.
759 AC_ARG_ENABLE([stats],
760 [AS_HELP_STRING([--disable-stats],
761 [Disable statistics calculation/reporting])],
762 [if test "x$enable_stats" = "xno" ; then
770 if test "x$enable_stats" = "x1" ; then
771 AC_DEFINE([JEMALLOC_STATS], [ ])
773 AC_SUBST([enable_stats])
775 dnl Do not enable profiling by default.
776 AC_ARG_ENABLE([prof],
777 [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
778 [if test "x$enable_prof" = "xno" ; then
786 if test "x$enable_prof" = "x1" ; then
789 backtrace_method="N/A"
792 AC_ARG_ENABLE([prof-libunwind],
793 [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
794 [if test "x$enable_prof_libunwind" = "xno" ; then
795 enable_prof_libunwind="0"
797 enable_prof_libunwind="1"
800 [enable_prof_libunwind="0"]
802 AC_ARG_WITH([static_libunwind],
803 [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
804 [Path to static libunwind library; use rather than dynamically linking])],
805 if test "x$with_static_libunwind" = "xno" ; then
808 if test ! -f "$with_static_libunwind" ; then
809 AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
811 LUNWIND="$with_static_libunwind"
815 if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
816 AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
817 if test "x$LUNWIND" = "x-lunwind" ; then
818 AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
819 [enable_prof_libunwind="0"])
821 LIBS="$LIBS $LUNWIND"
823 if test "x${enable_prof_libunwind}" = "x1" ; then
824 backtrace_method="libunwind"
825 AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
829 AC_ARG_ENABLE([prof-libgcc],
830 [AS_HELP_STRING([--disable-prof-libgcc],
831 [Do not use libgcc for backtracing])],
832 [if test "x$enable_prof_libgcc" = "xno" ; then
833 enable_prof_libgcc="0"
835 enable_prof_libgcc="1"
838 [enable_prof_libgcc="1"]
840 if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
841 -a "x$GCC" = "xyes" ; then
842 AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
843 AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
844 if test "x${enable_prof_libgcc}" = "x1" ; then
845 backtrace_method="libgcc"
846 AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
849 enable_prof_libgcc="0"
852 AC_ARG_ENABLE([prof-gcc],
853 [AS_HELP_STRING([--disable-prof-gcc],
854 [Do not use gcc intrinsics for backtracing])],
855 [if test "x$enable_prof_gcc" = "xno" ; then
861 [enable_prof_gcc="1"]
863 if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
864 -a "x$GCC" = "xyes" ; then
865 JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
866 backtrace_method="gcc intrinsics"
867 AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
872 if test "x$backtrace_method" = "x" ; then
873 backtrace_method="none (disabling profiling)"
876 AC_MSG_CHECKING([configured backtracing method])
877 AC_MSG_RESULT([$backtrace_method])
878 if test "x$enable_prof" = "x1" ; then
879 if test "x$abi" != "xpecoff"; then
880 dnl Heap profiling uses the log(3) function.
884 AC_DEFINE([JEMALLOC_PROF], [ ])
886 AC_SUBST([enable_prof])
888 dnl Enable thread-specific caching by default.
889 AC_ARG_ENABLE([tcache],
890 [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
891 [if test "x$enable_tcache" = "xno" ; then
899 if test "x$enable_tcache" = "x1" ; then
900 AC_DEFINE([JEMALLOC_TCACHE], [ ])
902 AC_SUBST([enable_tcache])
904 dnl Indicate whether adjacent virtual memory mappings automatically coalesce
905 dnl (and fragment on demand).
906 if test "x${maps_coalesce}" = "x1" ; then
907 AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
910 dnl Enable VM deallocation via munmap() by default.
911 AC_ARG_ENABLE([munmap],
912 [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
913 [if test "x$enable_munmap" = "xno" ; then
919 [enable_munmap="${default_munmap}"]
921 if test "x$enable_munmap" = "x1" ; then
922 AC_DEFINE([JEMALLOC_MUNMAP], [ ])
924 AC_SUBST([enable_munmap])
926 dnl Enable allocation from DSS if supported by the OS.
928 dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
929 AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
930 if test "x$have_sbrk" = "x1" ; then
931 if test "x$sbrk_deprecated" = "x1" ; then
932 AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
939 if test "x$have_dss" = "x1" ; then
940 AC_DEFINE([JEMALLOC_DSS], [ ])
943 dnl Support the junk/zero filling option by default.
944 AC_ARG_ENABLE([fill],
945 [AS_HELP_STRING([--disable-fill],
946 [Disable support for junk/zero filling, quarantine, and redzones])],
947 [if test "x$enable_fill" = "xno" ; then
955 if test "x$enable_fill" = "x1" ; then
956 AC_DEFINE([JEMALLOC_FILL], [ ])
958 AC_SUBST([enable_fill])
960 dnl Disable utrace(2)-based tracing by default.
961 AC_ARG_ENABLE([utrace],
962 [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
963 [if test "x$enable_utrace" = "xno" ; then
971 JE_COMPILABLE([utrace(2)], [
972 #include <sys/types.h>
973 #include <sys/param.h>
974 #include <sys/time.h>
976 #include <sys/ktrace.h>
978 utrace((void *)0, 0);
980 if test "x${je_cv_utrace}" = "xno" ; then
983 if test "x$enable_utrace" = "x1" ; then
984 AC_DEFINE([JEMALLOC_UTRACE], [ ])
986 AC_SUBST([enable_utrace])
988 dnl Support Valgrind by default.
989 AC_ARG_ENABLE([valgrind],
990 [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
991 [if test "x$enable_valgrind" = "xno" ; then
997 [enable_valgrind="1"]
999 if test "x$enable_valgrind" = "x1" ; then
1000 JE_COMPILABLE([valgrind], [
1001 #include <valgrind/valgrind.h>
1002 #include <valgrind/memcheck.h>
1004 #if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
1005 # error "Incompatible Valgrind version"
1007 ], [], [je_cv_valgrind])
1008 if test "x${je_cv_valgrind}" = "xno" ; then
1011 if test "x$enable_valgrind" = "x1" ; then
1012 AC_DEFINE([JEMALLOC_VALGRIND], [ ])
1015 AC_SUBST([enable_valgrind])
1017 dnl Do not support the xmalloc option by default.
1018 AC_ARG_ENABLE([xmalloc],
1019 [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
1020 [if test "x$enable_xmalloc" = "xno" ; then
1026 [enable_xmalloc="0"]
1028 if test "x$enable_xmalloc" = "x1" ; then
1029 AC_DEFINE([JEMALLOC_XMALLOC], [ ])
1031 AC_SUBST([enable_xmalloc])
1033 dnl Support cache-oblivious allocation alignment by default.
1034 AC_ARG_ENABLE([cache-oblivious],
1035 [AS_HELP_STRING([--disable-cache-oblivious],
1036 [Disable support for cache-oblivious allocation alignment])],
1037 [if test "x$enable_cache_oblivious" = "xno" ; then
1038 enable_cache_oblivious="0"
1040 enable_cache_oblivious="1"
1043 [enable_cache_oblivious="1"]
1045 if test "x$enable_cache_oblivious" = "x1" ; then
1046 AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
1048 AC_SUBST([enable_cache_oblivious])
1050 dnl ============================================================================
1051 dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
1052 dnl One of those two functions should (theoretically) exist on all platforms
1053 dnl that jemalloc currently has a chance of functioning on without modification.
1054 dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
1055 dnl ffsl() or __builtin_ffsl() are defined, respectively.
1056 JE_COMPILABLE([a program using __builtin_ffsl], [
1058 #include <strings.h>
1062 int rv = __builtin_ffsl(0x08);
1065 ], [je_cv_gcc_builtin_ffsl])
1066 if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
1067 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
1068 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
1069 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
1071 JE_COMPILABLE([a program using ffsl], [
1073 #include <strings.h>
1077 int rv = ffsl(0x08);
1080 ], [je_cv_function_ffsl])
1081 if test "x${je_cv_function_ffsl}" = "xyes" ; then
1082 AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
1083 AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
1084 AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
1086 AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
1090 AC_ARG_WITH([lg_tiny_min],
1091 [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
1092 [Base 2 log of minimum tiny size class to support])],
1093 [LG_TINY_MIN="$with_lg_tiny_min"],
1095 AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
1097 AC_ARG_WITH([lg_quantum],
1098 [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
1099 [Base 2 log of minimum allocation alignment])],
1100 [LG_QUANTA="$with_lg_quantum"],
1102 if test "x$with_lg_quantum" != "x" ; then
1103 AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
1106 AC_ARG_WITH([lg_page],
1107 [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
1108 [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
1109 if test "x$LG_PAGE" = "xdetect"; then
1110 AC_CACHE_CHECK([LG_PAGE],
1112 AC_RUN_IFELSE([AC_LANG_PROGRAM(
1114 #include <strings.h>
1116 #include <windows.h>
1129 result = si.dwPageSize;
1131 result = sysconf(_SC_PAGESIZE);
1136 result = JEMALLOC_INTERNAL_FFSL(result) - 1;
1138 f = fopen("conftest.out", "w");
1142 fprintf(f, "%d", result);
1147 [je_cv_lg_page=`cat conftest.out`],
1148 [je_cv_lg_page=undefined],
1149 [je_cv_lg_page=12]))
1151 if test "x${je_cv_lg_page}" != "x" ; then
1152 LG_PAGE="${je_cv_lg_page}"
1154 if test "x${LG_PAGE}" != "xundefined" ; then
1155 AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
1157 AC_MSG_ERROR([cannot determine value for LG_PAGE])
1160 AC_ARG_WITH([lg_page_sizes],
1161 [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
1162 [Base 2 logs of system page sizes to support])],
1163 [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
1165 AC_ARG_WITH([lg_size_class_group],
1166 [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
1167 [Base 2 log of size classes per doubling])],
1168 [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
1169 [LG_SIZE_CLASS_GROUP="2"])
1171 dnl ============================================================================
1172 dnl jemalloc configuration.
1175 dnl Set VERSION if source directory is inside a git repository.
1176 if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
1177 dnl Pattern globs aren't powerful enough to match both single- and
1178 dnl double-digit version numbers, so iterate over patterns to support up to
1179 dnl version 99.99.99 without any accidental matches.
1180 rm -f "${objroot}VERSION"
1181 for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
1182 '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
1183 '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
1184 '[0-9][0-9].[0-9][0-9].[0-9]' \
1185 '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
1186 if test ! -e "${objroot}VERSION" ; then
1187 (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
1188 if test $? -eq 0 ; then
1189 mv "${objroot}VERSION.tmp" "${objroot}VERSION"
1195 rm -f "${objroot}VERSION.tmp"
1196 if test ! -e "${objroot}VERSION" ; then
1197 if test ! -e "${srcroot}VERSION" ; then
1199 [Missing VERSION file, and unable to generate it; creating bogus VERSION])
1200 echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
1202 cp ${srcroot}VERSION ${objroot}VERSION
1205 jemalloc_version=`cat "${objroot}VERSION"`
1206 jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
1207 jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
1208 jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
1209 jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
1210 jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
1211 AC_SUBST([jemalloc_version])
1212 AC_SUBST([jemalloc_version_major])
1213 AC_SUBST([jemalloc_version_minor])
1214 AC_SUBST([jemalloc_version_bugfix])
1215 AC_SUBST([jemalloc_version_nrev])
1216 AC_SUBST([jemalloc_version_gid])
1218 dnl ============================================================================
1219 dnl Configure pthreads.
1221 if test "x$abi" != "xpecoff" ; then
1222 AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
1223 dnl Some systems may embed pthreads functionality in libc; check for libpthread
1224 dnl first, but try libc too before failing.
1225 AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
1226 [AC_SEARCH_LIBS([pthread_create], , ,
1227 AC_MSG_ERROR([libpthread is missing]))])
1230 CPPFLAGS="$CPPFLAGS -D_REENTRANT"
1232 dnl Check whether clock_gettime(2) is in libc or librt. This function is only
1233 dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
1234 SAVED_LIBS="${LIBS}"
1236 AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
1237 AC_SUBST([TESTLIBS])
1238 LIBS="${SAVED_LIBS}"
1240 dnl Check if the GNU-specific secure_getenv function exists.
1241 AC_CHECK_FUNC([secure_getenv],
1242 [have_secure_getenv="1"],
1243 [have_secure_getenv="0"]
1245 if test "x$have_secure_getenv" = "x1" ; then
1246 AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
1249 dnl Check if the Solaris/BSD issetugid function exists.
1250 AC_CHECK_FUNC([issetugid],
1251 [have_issetugid="1"],
1252 [have_issetugid="0"]
1254 if test "x$have_issetugid" = "x1" ; then
1255 AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
1258 dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
1259 dnl it rather than pthreads TSD cleanup functions to support cleanup during
1260 dnl thread exit, in order to avoid pthreads library recursion during
1262 AC_CHECK_FUNC([_malloc_thread_cleanup],
1263 [have__malloc_thread_cleanup="1"],
1264 [have__malloc_thread_cleanup="0"]
1266 if test "x$have__malloc_thread_cleanup" = "x1" ; then
1267 AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
1271 dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
1272 dnl so, mutex initialization causes allocation, and we need to implement this
1273 dnl callback function in order to prevent recursive allocation.
1274 AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
1275 [have__pthread_mutex_init_calloc_cb="1"],
1276 [have__pthread_mutex_init_calloc_cb="0"]
1278 if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
1279 AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
1282 dnl Disable lazy locking by default.
1283 AC_ARG_ENABLE([lazy_lock],
1284 [AS_HELP_STRING([--enable-lazy-lock],
1285 [Enable lazy locking (only lock when multi-threaded)])],
1286 [if test "x$enable_lazy_lock" = "xno" ; then
1287 enable_lazy_lock="0"
1289 enable_lazy_lock="1"
1292 [enable_lazy_lock=""]
1294 if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
1295 AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
1296 enable_lazy_lock="1"
1298 if test "x$enable_lazy_lock" = "x1" ; then
1299 if test "x$abi" != "xpecoff" ; then
1300 AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
1301 AC_CHECK_FUNC([dlsym], [],
1302 [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
1303 [AC_MSG_ERROR([libdl is missing])])
1306 AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
1308 enable_lazy_lock="0"
1310 AC_SUBST([enable_lazy_lock])
1312 AC_ARG_ENABLE([tls],
1313 [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
1314 if test "x$enable_tls" = "xno" ; then
1322 if test "x${enable_tls}" = "x" ; then
1323 if test "x${force_tls}" = "x1" ; then
1324 AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
1326 elif test "x${force_tls}" = "x0" ; then
1327 AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
1333 if test "x${enable_tls}" = "x1" ; then
1334 AC_MSG_CHECKING([for TLS])
1335 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1343 AC_MSG_RESULT([yes]),
1349 AC_SUBST([enable_tls])
1350 if test "x${enable_tls}" = "x1" ; then
1351 if test "x${force_tls}" = "x0" ; then
1352 AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
1354 AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
1355 elif test "x${force_tls}" = "x1" ; then
1356 AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
1359 dnl ============================================================================
1360 dnl Check for C11 atomics.
1362 JE_COMPILABLE([C11 atomics], [
1364 #if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
1365 #include <stdatomic.h>
1367 #error Atomics not available
1370 uint64_t *p = (uint64_t *)0;
1372 volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
1373 uint64_t r = atomic_fetch_add(a, x) + x;
1375 ], [je_cv_c11atomics])
1376 if test "x${je_cv_c11atomics}" = "xyes" ; then
1377 AC_DEFINE([JEMALLOC_C11ATOMICS])
1380 dnl ============================================================================
1381 dnl Check for atomic(9) operations as provided on FreeBSD.
1383 JE_COMPILABLE([atomic(9)], [
1384 #include <sys/types.h>
1385 #include <machine/atomic.h>
1386 #include <inttypes.h>
1390 volatile uint32_t *x32p = &x32;
1391 atomic_fetchadd_32(x32p, 1);
1394 unsigned long xlong = 0;
1395 volatile unsigned long *xlongp = &xlong;
1396 atomic_fetchadd_long(xlongp, 1);
1399 if test "x${je_cv_atomic9}" = "xyes" ; then
1400 AC_DEFINE([JEMALLOC_ATOMIC9])
1403 dnl ============================================================================
1404 dnl Check for atomic(3) operations as provided on Darwin.
1406 JE_COMPILABLE([Darwin OSAtomic*()], [
1407 #include <libkern/OSAtomic.h>
1408 #include <inttypes.h>
1412 volatile int32_t *x32p = &x32;
1413 OSAtomicAdd32(1, x32p);
1417 volatile int64_t *x64p = &x64;
1418 OSAtomicAdd64(1, x64p);
1420 ], [je_cv_osatomic])
1421 if test "x${je_cv_osatomic}" = "xyes" ; then
1422 AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
1425 dnl ============================================================================
1426 dnl Check for madvise(2).
1428 JE_COMPILABLE([madvise(2)], [
1429 #include <sys/mman.h>
1432 madvise((void *)0, 0, 0);
1435 if test "x${je_cv_madvise}" = "xyes" ; then
1436 AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
1439 dnl ============================================================================
1440 dnl Check whether __sync_{add,sub}_and_fetch() are available despite
1441 dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
1443 AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
1444 AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
1445 [je_cv_sync_compare_and_swap_$2],
1446 [AC_LINK_IFELSE([AC_LANG_PROGRAM([
1450 #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
1453 __sync_add_and_fetch(&x$1, 42);
1454 __sync_sub_and_fetch(&x$1, 1);
1457 #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
1460 [je_cv_sync_compare_and_swap_$2=yes],
1461 [je_cv_sync_compare_and_swap_$2=no])])
1463 if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
1464 AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
1468 if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
1469 JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
1470 JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
1473 dnl ============================================================================
1474 dnl Check for __builtin_clz() and __builtin_clzl().
1476 AC_CACHE_CHECK([for __builtin_clz],
1477 [je_cv_builtin_clz],
1478 [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
1482 int y = __builtin_clz(x);
1485 unsigned long x = 0;
1486 int y = __builtin_clzl(x);
1489 [je_cv_builtin_clz=yes],
1490 [je_cv_builtin_clz=no])])
1492 if test "x${je_cv_builtin_clz}" = "xyes" ; then
1493 AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
1496 dnl ============================================================================
1497 dnl Check for spinlock(3) operations as provided on Darwin.
1499 JE_COMPILABLE([Darwin OSSpin*()], [
1500 #include <libkern/OSAtomic.h>
1501 #include <inttypes.h>
1503 OSSpinLock lock = 0;
1504 OSSpinLockLock(&lock);
1505 OSSpinLockUnlock(&lock);
1507 if test "x${je_cv_osspin}" = "xyes" ; then
1508 AC_DEFINE([JEMALLOC_OSSPIN], [ ])
1511 dnl ============================================================================
1512 dnl Darwin-related configuration.
1514 AC_ARG_ENABLE([zone-allocator],
1515 [AS_HELP_STRING([--disable-zone-allocator],
1516 [Disable zone allocator for Darwin])],
1517 [if test "x$enable_zone_allocator" = "xno" ; then
1518 enable_zone_allocator="0"
1520 enable_zone_allocator="1"
1523 [if test "x${abi}" = "xmacho"; then
1524 enable_zone_allocator="1"
1528 AC_SUBST([enable_zone_allocator])
1530 if test "x${enable_zone_allocator}" = "x1" ; then
1531 if test "x${abi}" != "xmacho"; then
1532 AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
1534 AC_DEFINE([JEMALLOC_ZONE], [ ])
1536 dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
1537 dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
1538 dnl 10.6, which is the only source-level indication of the change.
1539 AC_MSG_CHECKING([malloc zone version])
1540 AC_DEFUN([JE_ZONE_PROGRAM],
1542 [#include <malloc/malloc.h>],
1543 [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
1546 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
1547 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
1548 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
1549 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
1550 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
1552 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
1553 AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
1555 if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
1556 AC_MSG_RESULT([unsupported])
1557 AC_MSG_ERROR([Unsupported malloc zone version])
1559 if test "${JEMALLOC_ZONE_VERSION}" = 9; then
1560 JEMALLOC_ZONE_VERSION=8
1561 AC_MSG_RESULT([> 8])
1563 AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
1565 AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
1568 dnl ============================================================================
1569 dnl Check for glibc malloc hooks
1571 JE_COMPILABLE([glibc malloc hook], [
1574 extern void (* __free_hook)(void *ptr);
1575 extern void *(* __malloc_hook)(size_t size);
1576 extern void *(* __realloc_hook)(void *ptr, size_t size);
1579 if (__malloc_hook) ptr = __malloc_hook(1);
1580 if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
1581 if (__free_hook && ptr) __free_hook(ptr);
1582 ], [je_cv_glibc_malloc_hook])
1583 if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
1584 AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
1587 JE_COMPILABLE([glibc memalign hook], [
1590 extern void *(* __memalign_hook)(size_t alignment, size_t size);
1593 if (__memalign_hook) ptr = __memalign_hook(16, 7);
1594 ], [je_cv_glibc_memalign_hook])
1595 if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
1596 AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
1599 JE_COMPILABLE([pthreads adaptive mutexes], [
1600 #include <pthread.h>
1602 pthread_mutexattr_t attr;
1603 pthread_mutexattr_init(&attr);
1604 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
1605 pthread_mutexattr_destroy(&attr);
1606 ], [je_cv_pthread_mutex_adaptive_np])
1607 if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
1608 AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
1611 dnl ============================================================================
1612 dnl Check for typedefs, structures, and compiler characteristics.
1615 dnl ============================================================================
1616 dnl Define commands that generate output files.
1618 AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
1619 mkdir -p "${objroot}include/jemalloc/internal"
1620 "${srcdir}/include/jemalloc/internal/private_namespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_namespace.h"
1623 objroot="${objroot}"
1625 AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
1626 mkdir -p "${objroot}include/jemalloc/internal"
1627 "${srcdir}/include/jemalloc/internal/private_unnamespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_unnamespace.h"
1630 objroot="${objroot}"
1632 AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
1633 f="${objroot}include/jemalloc/internal/public_symbols.txt"
1634 mkdir -p "${objroot}include/jemalloc/internal"
1636 for nm in `echo ${mangling_map} |tr ',' ' '` ; do
1637 n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
1638 m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
1639 echo "${n}:${m}" >> "${f}"
1640 dnl Remove name from public_syms so that it isn't redefined later.
1641 public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
1643 for sym in ${public_syms} ; do
1645 m="${JEMALLOC_PREFIX}${sym}"
1646 echo "${n}:${m}" >> "${f}"
1650 objroot="${objroot}"
1651 mangling_map="${mangling_map}"
1652 public_syms="${public_syms}"
1653 JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
1655 AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
1656 mkdir -p "${objroot}include/jemalloc/internal"
1657 "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
1660 objroot="${objroot}"
1662 AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
1663 mkdir -p "${objroot}include/jemalloc/internal"
1664 "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
1667 objroot="${objroot}"
1669 AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
1670 mkdir -p "${objroot}include/jemalloc/internal"
1671 "${SHELL}" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" ${LG_TINY_MIN} "${LG_PAGE_SIZES}" ${LG_SIZE_CLASS_GROUP} > "${objroot}include/jemalloc/internal/size_classes.h"
1675 objroot="${objroot}"
1676 LG_QUANTA="${LG_QUANTA}"
1677 LG_TINY_MIN=${LG_TINY_MIN}
1678 LG_PAGE_SIZES="${LG_PAGE_SIZES}"
1679 LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
1681 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
1682 mkdir -p "${objroot}include/jemalloc"
1683 cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
1686 objroot="${objroot}"
1688 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
1689 mkdir -p "${objroot}include/jemalloc"
1690 "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
1693 objroot="${objroot}"
1695 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
1696 mkdir -p "${objroot}include/jemalloc"
1697 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
1700 objroot="${objroot}"
1702 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
1703 mkdir -p "${objroot}include/jemalloc"
1704 "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
1707 objroot="${objroot}"
1709 AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
1710 mkdir -p "${objroot}include/jemalloc"
1711 "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
1714 objroot="${objroot}"
1715 install_suffix="${install_suffix}"
1718 dnl Process .in files.
1719 AC_SUBST([cfghdrs_in])
1720 AC_SUBST([cfghdrs_out])
1721 AC_CONFIG_HEADERS([$cfghdrs_tup])
1723 dnl ============================================================================
1724 dnl Generate outputs.
1726 AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
1727 AC_SUBST([cfgoutputs_in])
1728 AC_SUBST([cfgoutputs_out])
1731 dnl ============================================================================
1732 dnl Print out the results of configuration.
1733 AC_MSG_RESULT([===============================================================================])
1734 AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
1735 AC_MSG_RESULT([library revision : ${rev}])
1737 AC_MSG_RESULT([CONFIG : ${CONFIG}])
1738 AC_MSG_RESULT([CC : ${CC}])
1739 AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
1740 AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
1741 AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
1742 AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
1743 AC_MSG_RESULT([LIBS : ${LIBS}])
1744 AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
1745 AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
1747 AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
1748 AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
1750 AC_MSG_RESULT([PREFIX : ${PREFIX}])
1751 AC_MSG_RESULT([BINDIR : ${BINDIR}])
1752 AC_MSG_RESULT([DATADIR : ${DATADIR}])
1753 AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
1754 AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
1755 AC_MSG_RESULT([MANDIR : ${MANDIR}])
1757 AC_MSG_RESULT([srcroot : ${srcroot}])
1758 AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
1759 AC_MSG_RESULT([objroot : ${objroot}])
1760 AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
1762 AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
1763 AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
1764 AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
1765 AC_MSG_RESULT([install_suffix : ${install_suffix}])
1766 AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
1767 AC_MSG_RESULT([autogen : ${enable_autogen}])
1768 AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
1769 AC_MSG_RESULT([debug : ${enable_debug}])
1770 AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
1771 AC_MSG_RESULT([stats : ${enable_stats}])
1772 AC_MSG_RESULT([prof : ${enable_prof}])
1773 AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
1774 AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
1775 AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
1776 AC_MSG_RESULT([tcache : ${enable_tcache}])
1777 AC_MSG_RESULT([fill : ${enable_fill}])
1778 AC_MSG_RESULT([utrace : ${enable_utrace}])
1779 AC_MSG_RESULT([valgrind : ${enable_valgrind}])
1780 AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
1781 AC_MSG_RESULT([munmap : ${enable_munmap}])
1782 AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
1783 AC_MSG_RESULT([tls : ${enable_tls}])
1784 AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
1785 AC_MSG_RESULT([===============================================================================])