configure.ac 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745
  1. dnl Process this file with autoconf to produce a configure script.
  2. AC_INIT([Makefile.in])
  3. dnl ============================================================================
  4. dnl Custom macro definitions.
  5. dnl JE_CFLAGS_APPEND(cflag)
  6. AC_DEFUN([JE_CFLAGS_APPEND],
  7. [
  8. AC_MSG_CHECKING([whether compiler supports $1])
  9. TCFLAGS="${CFLAGS}"
  10. if test "x${CFLAGS}" = "x" ; then
  11. CFLAGS="$1"
  12. else
  13. CFLAGS="${CFLAGS} $1"
  14. fi
  15. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  16. [[
  17. ]], [[
  18. return 0;
  19. ]])],
  20. [je_cv_cflags_appended=$1]
  21. AC_MSG_RESULT([yes]),
  22. [je_cv_cflags_appended=]
  23. AC_MSG_RESULT([no])
  24. [CFLAGS="${TCFLAGS}"]
  25. )
  26. ])
  27. dnl JE_COMPILABLE(label, hcode, mcode, rvar)
  28. dnl
  29. dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
  30. dnl cause failure.
  31. AC_DEFUN([JE_COMPILABLE],
  32. [
  33. AC_CACHE_CHECK([whether $1 is compilable],
  34. [$4],
  35. [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
  36. [$3])],
  37. [$4=yes],
  38. [$4=no])])
  39. ])
  40. dnl ============================================================================
  41. CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
  42. AC_SUBST([CONFIG])
  43. dnl Library revision.
  44. rev=2
  45. AC_SUBST([rev])
  46. srcroot=$srcdir
  47. if test "x${srcroot}" = "x." ; then
  48. srcroot=""
  49. else
  50. srcroot="${srcroot}/"
  51. fi
  52. AC_SUBST([srcroot])
  53. abs_srcroot="`cd \"${srcdir}\"; pwd`/"
  54. AC_SUBST([abs_srcroot])
  55. objroot=""
  56. AC_SUBST([objroot])
  57. abs_objroot="`pwd`/"
  58. AC_SUBST([abs_objroot])
  59. dnl Munge install path variables.
  60. if test "x$prefix" = "xNONE" ; then
  61. prefix="/usr/local"
  62. fi
  63. if test "x$exec_prefix" = "xNONE" ; then
  64. exec_prefix=$prefix
  65. fi
  66. PREFIX=$prefix
  67. AC_SUBST([PREFIX])
  68. BINDIR=`eval echo $bindir`
  69. BINDIR=`eval echo $BINDIR`
  70. AC_SUBST([BINDIR])
  71. INCLUDEDIR=`eval echo $includedir`
  72. INCLUDEDIR=`eval echo $INCLUDEDIR`
  73. AC_SUBST([INCLUDEDIR])
  74. LIBDIR=`eval echo $libdir`
  75. LIBDIR=`eval echo $LIBDIR`
  76. AC_SUBST([LIBDIR])
  77. DATADIR=`eval echo $datadir`
  78. DATADIR=`eval echo $DATADIR`
  79. AC_SUBST([DATADIR])
  80. MANDIR=`eval echo $mandir`
  81. MANDIR=`eval echo $MANDIR`
  82. AC_SUBST([MANDIR])
  83. dnl Support for building documentation.
  84. AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
  85. if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
  86. DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
  87. elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
  88. DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
  89. else
  90. dnl Documentation building will fail if this default gets used.
  91. DEFAULT_XSLROOT=""
  92. fi
  93. AC_ARG_WITH([xslroot],
  94. [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
  95. if test "x$with_xslroot" = "xno" ; then
  96. XSLROOT="${DEFAULT_XSLROOT}"
  97. else
  98. XSLROOT="${with_xslroot}"
  99. fi
  100. ],
  101. XSLROOT="${DEFAULT_XSLROOT}"
  102. )
  103. AC_SUBST([XSLROOT])
  104. dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
  105. dnl just prevent autoconf from molesting CFLAGS.
  106. CFLAGS=$CFLAGS
  107. AC_PROG_CC
  108. if test "x$GCC" != "xyes" ; then
  109. AC_CACHE_CHECK([whether compiler is MSVC],
  110. [je_cv_msvc],
  111. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  112. [
  113. #ifndef _MSC_VER
  114. int fail[-1];
  115. #endif
  116. ])],
  117. [je_cv_msvc=yes],
  118. [je_cv_msvc=no])])
  119. fi
  120. if test "x$CFLAGS" = "x" ; then
  121. no_CFLAGS="yes"
  122. if test "x$GCC" = "xyes" ; then
  123. JE_CFLAGS_APPEND([-std=gnu99])
  124. if test "x$je_cv_cflags_appended" = "x-std=gnu99" ; then
  125. AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
  126. fi
  127. JE_CFLAGS_APPEND([-Wall])
  128. JE_CFLAGS_APPEND([-Werror=declaration-after-statement])
  129. JE_CFLAGS_APPEND([-pipe])
  130. JE_CFLAGS_APPEND([-g3])
  131. elif test "x$je_cv_msvc" = "xyes" ; then
  132. CC="$CC -nologo"
  133. JE_CFLAGS_APPEND([-Zi])
  134. JE_CFLAGS_APPEND([-MT])
  135. JE_CFLAGS_APPEND([-W3])
  136. JE_CFLAGS_APPEND([-FS])
  137. CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat"
  138. fi
  139. fi
  140. dnl Append EXTRA_CFLAGS to CFLAGS, if defined.
  141. if test "x$EXTRA_CFLAGS" != "x" ; then
  142. JE_CFLAGS_APPEND([$EXTRA_CFLAGS])
  143. fi
  144. AC_PROG_CPP
  145. AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
  146. if test "x${ac_cv_big_endian}" = "x1" ; then
  147. AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
  148. fi
  149. if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
  150. CPPFLAGS="$CPPFLAGS -I${srcdir}/include/msvc_compat/C99"
  151. fi
  152. AC_CHECK_SIZEOF([void *])
  153. if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
  154. LG_SIZEOF_PTR=3
  155. elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
  156. LG_SIZEOF_PTR=2
  157. else
  158. AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
  159. fi
  160. AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
  161. AC_CHECK_SIZEOF([int])
  162. if test "x${ac_cv_sizeof_int}" = "x8" ; then
  163. LG_SIZEOF_INT=3
  164. elif test "x${ac_cv_sizeof_int}" = "x4" ; then
  165. LG_SIZEOF_INT=2
  166. else
  167. AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
  168. fi
  169. AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
  170. AC_CHECK_SIZEOF([long])
  171. if test "x${ac_cv_sizeof_long}" = "x8" ; then
  172. LG_SIZEOF_LONG=3
  173. elif test "x${ac_cv_sizeof_long}" = "x4" ; then
  174. LG_SIZEOF_LONG=2
  175. else
  176. AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
  177. fi
  178. AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
  179. AC_CHECK_SIZEOF([intmax_t])
  180. if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
  181. LG_SIZEOF_INTMAX_T=4
  182. elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
  183. LG_SIZEOF_INTMAX_T=3
  184. elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
  185. LG_SIZEOF_INTMAX_T=2
  186. else
  187. AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
  188. fi
  189. AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
  190. AC_CANONICAL_HOST
  191. dnl CPU-specific settings.
  192. CPU_SPINWAIT=""
  193. case "${host_cpu}" in
  194. i686|x86_64)
  195. AC_CACHE_VAL([je_cv_pause],
  196. [JE_COMPILABLE([pause instruction], [],
  197. [[__asm__ volatile("pause"); return 0;]],
  198. [je_cv_pause])])
  199. if test "x${je_cv_pause}" = "xyes" ; then
  200. CPU_SPINWAIT='__asm__ volatile("pause")'
  201. fi
  202. ;;
  203. powerpc)
  204. AC_DEFINE_UNQUOTED([HAVE_ALTIVEC], [ ])
  205. ;;
  206. *)
  207. ;;
  208. esac
  209. AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
  210. LD_PRELOAD_VAR="LD_PRELOAD"
  211. so="so"
  212. importlib="${so}"
  213. o="$ac_objext"
  214. a="a"
  215. exe="$ac_exeext"
  216. libprefix="lib"
  217. DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
  218. RPATH='-Wl,-rpath,$(1)'
  219. SOREV="${so}.${rev}"
  220. PIC_CFLAGS='-fPIC -DPIC'
  221. CTARGET='-o $@'
  222. LDTARGET='-o $@'
  223. EXTRA_LDFLAGS=
  224. ARFLAGS='crus'
  225. AROUT=' $@'
  226. CC_MM=1
  227. AN_MAKEVAR([AR], [AC_PROG_AR])
  228. AN_PROGRAM([ar], [AC_PROG_AR])
  229. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
  230. AC_PROG_AR
  231. dnl Platform-specific settings. abi and RPATH can probably be determined
  232. dnl programmatically, but doing so is error-prone, which makes it generally
  233. dnl not worth the trouble.
  234. dnl
  235. dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
  236. dnl definitions need to be seen before any headers are included, which is a pain
  237. dnl to make happen otherwise.
  238. default_munmap="1"
  239. maps_coalesce="1"
  240. case "${host}" in
  241. *-*-darwin* | *-*-ios*)
  242. CFLAGS="$CFLAGS"
  243. abi="macho"
  244. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  245. RPATH=""
  246. LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
  247. so="dylib"
  248. importlib="${so}"
  249. force_tls="0"
  250. DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
  251. SOREV="${rev}.${so}"
  252. sbrk_deprecated="1"
  253. ;;
  254. *-*-freebsd*)
  255. CFLAGS="$CFLAGS"
  256. abi="elf"
  257. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  258. force_lazy_lock="1"
  259. ;;
  260. *-*-dragonfly*)
  261. CFLAGS="$CFLAGS"
  262. abi="elf"
  263. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  264. ;;
  265. *-*-openbsd*)
  266. CFLAGS="$CFLAGS"
  267. abi="elf"
  268. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  269. force_tls="0"
  270. ;;
  271. *-*-bitrig*)
  272. CFLAGS="$CFLAGS"
  273. abi="elf"
  274. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  275. ;;
  276. *-*-linux*)
  277. CFLAGS="$CFLAGS"
  278. CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
  279. abi="elf"
  280. AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
  281. AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
  282. AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
  283. AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
  284. default_munmap="0"
  285. ;;
  286. *-*-netbsd*)
  287. AC_MSG_CHECKING([ABI])
  288. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  289. [[#ifdef __ELF__
  290. /* ELF */
  291. #else
  292. #error aout
  293. #endif
  294. ]])],
  295. [CFLAGS="$CFLAGS"; abi="elf"],
  296. [abi="aout"])
  297. AC_MSG_RESULT([$abi])
  298. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  299. ;;
  300. *-*-solaris2*)
  301. CFLAGS="$CFLAGS"
  302. abi="elf"
  303. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  304. RPATH='-Wl,-R,$(1)'
  305. dnl Solaris needs this for sigwait().
  306. CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
  307. LIBS="$LIBS -lposix4 -lsocket -lnsl"
  308. ;;
  309. *-ibm-aix*)
  310. if "$LG_SIZEOF_PTR" = "8"; then
  311. dnl 64bit AIX
  312. LD_PRELOAD_VAR="LDR_PRELOAD64"
  313. else
  314. dnl 32bit AIX
  315. LD_PRELOAD_VAR="LDR_PRELOAD"
  316. fi
  317. abi="xcoff"
  318. ;;
  319. *-*-mingw* | *-*-cygwin*)
  320. abi="pecoff"
  321. force_tls="0"
  322. force_lazy_lock="1"
  323. maps_coalesce="0"
  324. RPATH=""
  325. so="dll"
  326. if test "x$je_cv_msvc" = "xyes" ; then
  327. importlib="lib"
  328. DSO_LDFLAGS="-LD"
  329. EXTRA_LDFLAGS="-link -DEBUG"
  330. CTARGET='-Fo$@'
  331. LDTARGET='-Fe$@'
  332. AR='lib'
  333. ARFLAGS='-nologo -out:'
  334. AROUT='$@'
  335. CC_MM=
  336. else
  337. importlib="${so}"
  338. DSO_LDFLAGS="-shared"
  339. fi
  340. a="lib"
  341. libprefix=""
  342. SOREV="${so}"
  343. PIC_CFLAGS=""
  344. ;;
  345. *)
  346. AC_MSG_RESULT([Unsupported operating system: ${host}])
  347. abi="elf"
  348. ;;
  349. esac
  350. JEMALLOC_USABLE_SIZE_CONST=const
  351. AC_CHECK_HEADERS([malloc.h], [
  352. AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
  353. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  354. [#include <malloc.h>
  355. #include <stddef.h>
  356. size_t malloc_usable_size(const void *ptr);
  357. ],
  358. [])],[
  359. AC_MSG_RESULT([yes])
  360. ],[
  361. JEMALLOC_USABLE_SIZE_CONST=
  362. AC_MSG_RESULT([no])
  363. ])
  364. ])
  365. AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
  366. AC_SUBST([abi])
  367. AC_SUBST([RPATH])
  368. AC_SUBST([LD_PRELOAD_VAR])
  369. AC_SUBST([so])
  370. AC_SUBST([importlib])
  371. AC_SUBST([o])
  372. AC_SUBST([a])
  373. AC_SUBST([exe])
  374. AC_SUBST([libprefix])
  375. AC_SUBST([DSO_LDFLAGS])
  376. AC_SUBST([EXTRA_LDFLAGS])
  377. AC_SUBST([SOREV])
  378. AC_SUBST([PIC_CFLAGS])
  379. AC_SUBST([CTARGET])
  380. AC_SUBST([LDTARGET])
  381. AC_SUBST([MKLIB])
  382. AC_SUBST([ARFLAGS])
  383. AC_SUBST([AROUT])
  384. AC_SUBST([CC_MM])
  385. JE_COMPILABLE([__attribute__ syntax],
  386. [static __attribute__((unused)) void foo(void){}],
  387. [],
  388. [je_cv_attribute])
  389. if test "x${je_cv_attribute}" = "xyes" ; then
  390. AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
  391. if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
  392. JE_CFLAGS_APPEND([-fvisibility=hidden])
  393. fi
  394. fi
  395. dnl Check for tls_model attribute support (clang 3.0 still lacks support).
  396. SAVED_CFLAGS="${CFLAGS}"
  397. JE_CFLAGS_APPEND([-Werror])
  398. JE_COMPILABLE([tls_model attribute], [],
  399. [static __thread int
  400. __attribute__((tls_model("initial-exec"), unused)) foo;
  401. foo = 0;],
  402. [je_cv_tls_model])
  403. CFLAGS="${SAVED_CFLAGS}"
  404. if test "x${je_cv_tls_model}" = "xyes" ; then
  405. AC_DEFINE([JEMALLOC_TLS_MODEL],
  406. [__attribute__((tls_model("initial-exec")))])
  407. else
  408. AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
  409. fi
  410. dnl Check for alloc_size attribute support.
  411. SAVED_CFLAGS="${CFLAGS}"
  412. JE_CFLAGS_APPEND([-Werror])
  413. JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
  414. [void *foo(size_t size) __attribute__((alloc_size(1)));],
  415. [je_cv_alloc_size])
  416. CFLAGS="${SAVED_CFLAGS}"
  417. if test "x${je_cv_alloc_size}" = "xyes" ; then
  418. AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
  419. fi
  420. dnl Check for format(gnu_printf, ...) attribute support.
  421. SAVED_CFLAGS="${CFLAGS}"
  422. JE_CFLAGS_APPEND([-Werror])
  423. JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
  424. [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
  425. [je_cv_format_gnu_printf])
  426. CFLAGS="${SAVED_CFLAGS}"
  427. if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
  428. AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
  429. fi
  430. dnl Check for format(printf, ...) attribute support.
  431. SAVED_CFLAGS="${CFLAGS}"
  432. JE_CFLAGS_APPEND([-Werror])
  433. JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
  434. [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
  435. [je_cv_format_printf])
  436. CFLAGS="${SAVED_CFLAGS}"
  437. if test "x${je_cv_format_printf}" = "xyes" ; then
  438. AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
  439. fi
  440. dnl Support optional additions to rpath.
  441. AC_ARG_WITH([rpath],
  442. [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
  443. if test "x$with_rpath" = "xno" ; then
  444. RPATH_EXTRA=
  445. else
  446. RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
  447. fi,
  448. RPATH_EXTRA=
  449. )
  450. AC_SUBST([RPATH_EXTRA])
  451. dnl Disable rules that do automatic regeneration of configure output by default.
  452. AC_ARG_ENABLE([autogen],
  453. [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
  454. if test "x$enable_autogen" = "xno" ; then
  455. enable_autogen="0"
  456. else
  457. enable_autogen="1"
  458. fi
  459. ,
  460. enable_autogen="0"
  461. )
  462. AC_SUBST([enable_autogen])
  463. AC_PROG_INSTALL
  464. AC_PROG_RANLIB
  465. AC_PATH_PROG([LD], [ld], [false], [$PATH])
  466. AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
  467. 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"
  468. dnl Check for allocator-related functions that should be wrapped.
  469. AC_CHECK_FUNC([memalign],
  470. [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
  471. public_syms="${public_syms} memalign"])
  472. AC_CHECK_FUNC([valloc],
  473. [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
  474. public_syms="${public_syms} valloc"])
  475. dnl Do not compute test code coverage by default.
  476. GCOV_FLAGS=
  477. AC_ARG_ENABLE([code-coverage],
  478. [AS_HELP_STRING([--enable-code-coverage],
  479. [Enable code coverage])],
  480. [if test "x$enable_code_coverage" = "xno" ; then
  481. enable_code_coverage="0"
  482. else
  483. enable_code_coverage="1"
  484. fi
  485. ],
  486. [enable_code_coverage="0"]
  487. )
  488. if test "x$enable_code_coverage" = "x1" ; then
  489. deoptimize="no"
  490. echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || deoptimize="yes"
  491. if test "x${deoptimize}" = "xyes" ; then
  492. JE_CFLAGS_APPEND([-O0])
  493. fi
  494. JE_CFLAGS_APPEND([-fprofile-arcs -ftest-coverage])
  495. EXTRA_LDFLAGS="$EXTRA_LDFLAGS -fprofile-arcs -ftest-coverage"
  496. AC_DEFINE([JEMALLOC_CODE_COVERAGE], [ ])
  497. fi
  498. AC_SUBST([enable_code_coverage])
  499. dnl Perform no name mangling by default.
  500. AC_ARG_WITH([mangling],
  501. [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
  502. [mangling_map="$with_mangling"], [mangling_map=""])
  503. dnl Do not prefix public APIs by default.
  504. AC_ARG_WITH([jemalloc_prefix],
  505. [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
  506. [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
  507. [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
  508. JEMALLOC_PREFIX=""
  509. else
  510. JEMALLOC_PREFIX="je_"
  511. fi]
  512. )
  513. if test "x$JEMALLOC_PREFIX" != "x" ; then
  514. JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
  515. AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
  516. AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
  517. fi
  518. AC_SUBST([JEMALLOC_CPREFIX])
  519. AC_ARG_WITH([export],
  520. [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
  521. [if test "x$with_export" = "xno"; then
  522. AC_DEFINE([JEMALLOC_EXPORT],[])
  523. fi]
  524. )
  525. dnl Mangle library-private APIs.
  526. AC_ARG_WITH([private_namespace],
  527. [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
  528. [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
  529. [JEMALLOC_PRIVATE_NAMESPACE="je_"]
  530. )
  531. AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
  532. private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
  533. AC_SUBST([private_namespace])
  534. dnl Do not add suffix to installed files by default.
  535. AC_ARG_WITH([install_suffix],
  536. [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
  537. [INSTALL_SUFFIX="$with_install_suffix"],
  538. [INSTALL_SUFFIX=]
  539. )
  540. install_suffix="$INSTALL_SUFFIX"
  541. AC_SUBST([install_suffix])
  542. dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
  543. dnl jemalloc_protos_jet.h easy.
  544. je_="je_"
  545. AC_SUBST([je_])
  546. cfgoutputs_in="Makefile.in"
  547. cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
  548. cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
  549. cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
  550. cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
  551. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
  552. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
  553. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
  554. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_internal.h.in"
  555. cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
  556. cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
  557. cfgoutputs_out="Makefile"
  558. cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
  559. cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
  560. cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
  561. cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
  562. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
  563. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
  564. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
  565. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_internal.h"
  566. cfgoutputs_out="${cfgoutputs_out} test/test.sh"
  567. cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
  568. cfgoutputs_tup="Makefile"
  569. cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
  570. cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
  571. cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
  572. cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
  573. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
  574. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
  575. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
  576. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_internal.h"
  577. cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
  578. cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
  579. cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
  580. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
  581. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
  582. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_unnamespace.sh"
  583. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.txt"
  584. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
  585. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
  586. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
  587. cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
  588. cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
  589. cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
  590. cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
  591. cfghdrs_out="include/jemalloc/jemalloc_defs.h"
  592. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
  593. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_namespace.h"
  594. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_unnamespace.h"
  595. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
  596. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
  597. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
  598. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
  599. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
  600. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
  601. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
  602. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
  603. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
  604. cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
  605. cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
  606. cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
  607. cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
  608. dnl Silence irrelevant compiler warnings by default.
  609. AC_ARG_ENABLE([cc-silence],
  610. [AS_HELP_STRING([--disable-cc-silence],
  611. [Do not silence irrelevant compiler warnings])],
  612. [if test "x$enable_cc_silence" = "xno" ; then
  613. enable_cc_silence="0"
  614. else
  615. enable_cc_silence="1"
  616. fi
  617. ],
  618. [enable_cc_silence="1"]
  619. )
  620. if test "x$enable_cc_silence" = "x1" ; then
  621. AC_DEFINE([JEMALLOC_CC_SILENCE], [ ])
  622. fi
  623. dnl Do not compile with debugging by default.
  624. AC_ARG_ENABLE([debug],
  625. [AS_HELP_STRING([--enable-debug],
  626. [Build debugging code (implies --enable-ivsalloc)])],
  627. [if test "x$enable_debug" = "xno" ; then
  628. enable_debug="0"
  629. else
  630. enable_debug="1"
  631. fi
  632. ],
  633. [enable_debug="0"]
  634. )
  635. if test "x$enable_debug" = "x1" ; then
  636. AC_DEFINE([JEMALLOC_DEBUG], [ ])
  637. fi
  638. if test "x$enable_debug" = "x1" ; then
  639. AC_DEFINE([JEMALLOC_DEBUG], [ ])
  640. enable_ivsalloc="1"
  641. fi
  642. AC_SUBST([enable_debug])
  643. dnl Do not validate pointers by default.
  644. AC_ARG_ENABLE([ivsalloc],
  645. [AS_HELP_STRING([--enable-ivsalloc],
  646. [Validate pointers passed through the public API])],
  647. [if test "x$enable_ivsalloc" = "xno" ; then
  648. enable_ivsalloc="0"
  649. else
  650. enable_ivsalloc="1"
  651. fi
  652. ],
  653. [enable_ivsalloc="0"]
  654. )
  655. if test "x$enable_ivsalloc" = "x1" ; then
  656. AC_DEFINE([JEMALLOC_IVSALLOC], [ ])
  657. fi
  658. dnl Only optimize if not debugging.
  659. if test "x$enable_debug" = "x0" -a "x$no_CFLAGS" = "xyes" ; then
  660. dnl Make sure that an optimization flag was not specified in EXTRA_CFLAGS.
  661. optimize="no"
  662. echo "$CFLAGS $EXTRA_CFLAGS" | grep '\-O' >/dev/null || optimize="yes"
  663. if test "x${optimize}" = "xyes" ; then
  664. if test "x$GCC" = "xyes" ; then
  665. JE_CFLAGS_APPEND([-O3])
  666. JE_CFLAGS_APPEND([-funroll-loops])
  667. elif test "x$je_cv_msvc" = "xyes" ; then
  668. JE_CFLAGS_APPEND([-O2])
  669. else
  670. JE_CFLAGS_APPEND([-O])
  671. fi
  672. fi
  673. fi
  674. dnl Enable statistics calculation by default.
  675. AC_ARG_ENABLE([stats],
  676. [AS_HELP_STRING([--disable-stats],
  677. [Disable statistics calculation/reporting])],
  678. [if test "x$enable_stats" = "xno" ; then
  679. enable_stats="0"
  680. else
  681. enable_stats="1"
  682. fi
  683. ],
  684. [enable_stats="1"]
  685. )
  686. if test "x$enable_stats" = "x1" ; then
  687. AC_DEFINE([JEMALLOC_STATS], [ ])
  688. fi
  689. AC_SUBST([enable_stats])
  690. dnl Do not enable profiling by default.
  691. AC_ARG_ENABLE([prof],
  692. [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
  693. [if test "x$enable_prof" = "xno" ; then
  694. enable_prof="0"
  695. else
  696. enable_prof="1"
  697. fi
  698. ],
  699. [enable_prof="0"]
  700. )
  701. if test "x$enable_prof" = "x1" ; then
  702. backtrace_method=""
  703. else
  704. backtrace_method="N/A"
  705. fi
  706. AC_ARG_ENABLE([prof-libunwind],
  707. [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
  708. [if test "x$enable_prof_libunwind" = "xno" ; then
  709. enable_prof_libunwind="0"
  710. else
  711. enable_prof_libunwind="1"
  712. fi
  713. ],
  714. [enable_prof_libunwind="0"]
  715. )
  716. AC_ARG_WITH([static_libunwind],
  717. [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
  718. [Path to static libunwind library; use rather than dynamically linking])],
  719. if test "x$with_static_libunwind" = "xno" ; then
  720. LUNWIND="-lunwind"
  721. else
  722. if test ! -f "$with_static_libunwind" ; then
  723. AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
  724. fi
  725. LUNWIND="$with_static_libunwind"
  726. fi,
  727. LUNWIND="-lunwind"
  728. )
  729. if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
  730. AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
  731. if test "x$LUNWIND" = "x-lunwind" ; then
  732. AC_CHECK_LIB([unwind], [unw_backtrace], [LIBS="$LIBS $LUNWIND"],
  733. [enable_prof_libunwind="0"])
  734. else
  735. LIBS="$LIBS $LUNWIND"
  736. fi
  737. if test "x${enable_prof_libunwind}" = "x1" ; then
  738. backtrace_method="libunwind"
  739. AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
  740. fi
  741. fi
  742. AC_ARG_ENABLE([prof-libgcc],
  743. [AS_HELP_STRING([--disable-prof-libgcc],
  744. [Do not use libgcc for backtracing])],
  745. [if test "x$enable_prof_libgcc" = "xno" ; then
  746. enable_prof_libgcc="0"
  747. else
  748. enable_prof_libgcc="1"
  749. fi
  750. ],
  751. [enable_prof_libgcc="1"]
  752. )
  753. if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
  754. -a "x$GCC" = "xyes" ; then
  755. AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
  756. AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [LIBS="$LIBS -lgcc"], [enable_prof_libgcc="0"])
  757. if test "x${enable_prof_libgcc}" = "x1" ; then
  758. backtrace_method="libgcc"
  759. AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
  760. fi
  761. else
  762. enable_prof_libgcc="0"
  763. fi
  764. AC_ARG_ENABLE([prof-gcc],
  765. [AS_HELP_STRING([--disable-prof-gcc],
  766. [Do not use gcc intrinsics for backtracing])],
  767. [if test "x$enable_prof_gcc" = "xno" ; then
  768. enable_prof_gcc="0"
  769. else
  770. enable_prof_gcc="1"
  771. fi
  772. ],
  773. [enable_prof_gcc="1"]
  774. )
  775. if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
  776. -a "x$GCC" = "xyes" ; then
  777. JE_CFLAGS_APPEND([-fno-omit-frame-pointer])
  778. backtrace_method="gcc intrinsics"
  779. AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
  780. else
  781. enable_prof_gcc="0"
  782. fi
  783. if test "x$backtrace_method" = "x" ; then
  784. backtrace_method="none (disabling profiling)"
  785. enable_prof="0"
  786. fi
  787. AC_MSG_CHECKING([configured backtracing method])
  788. AC_MSG_RESULT([$backtrace_method])
  789. if test "x$enable_prof" = "x1" ; then
  790. if test "x$abi" != "xpecoff"; then
  791. dnl Heap profiling uses the log(3) function.
  792. LIBS="$LIBS -lm"
  793. fi
  794. AC_DEFINE([JEMALLOC_PROF], [ ])
  795. fi
  796. AC_SUBST([enable_prof])
  797. dnl Enable thread-specific caching by default.
  798. AC_ARG_ENABLE([tcache],
  799. [AS_HELP_STRING([--disable-tcache], [Disable per thread caches])],
  800. [if test "x$enable_tcache" = "xno" ; then
  801. enable_tcache="0"
  802. else
  803. enable_tcache="1"
  804. fi
  805. ],
  806. [enable_tcache="1"]
  807. )
  808. if test "x$enable_tcache" = "x1" ; then
  809. AC_DEFINE([JEMALLOC_TCACHE], [ ])
  810. fi
  811. AC_SUBST([enable_tcache])
  812. dnl Indicate whether adjacent virtual memory mappings automatically coalesce
  813. dnl (and fragment on demand).
  814. if test "x${maps_coalesce}" = "x1" ; then
  815. AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
  816. fi
  817. dnl Enable VM deallocation via munmap() by default.
  818. AC_ARG_ENABLE([munmap],
  819. [AS_HELP_STRING([--disable-munmap], [Disable VM deallocation via munmap(2)])],
  820. [if test "x$enable_munmap" = "xno" ; then
  821. enable_munmap="0"
  822. else
  823. enable_munmap="1"
  824. fi
  825. ],
  826. [enable_munmap="${default_munmap}"]
  827. )
  828. if test "x$enable_munmap" = "x1" ; then
  829. AC_DEFINE([JEMALLOC_MUNMAP], [ ])
  830. fi
  831. AC_SUBST([enable_munmap])
  832. dnl Enable allocation from DSS if supported by the OS.
  833. have_dss="1"
  834. dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
  835. AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
  836. if test "x$have_sbrk" = "x1" ; then
  837. if test "x$sbrk_deprecated" = "x1" ; then
  838. AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
  839. have_dss="0"
  840. fi
  841. else
  842. have_dss="0"
  843. fi
  844. if test "x$have_dss" = "x1" ; then
  845. AC_DEFINE([JEMALLOC_DSS], [ ])
  846. fi
  847. dnl Support the junk/zero filling option by default.
  848. AC_ARG_ENABLE([fill],
  849. [AS_HELP_STRING([--disable-fill],
  850. [Disable support for junk/zero filling, quarantine, and redzones])],
  851. [if test "x$enable_fill" = "xno" ; then
  852. enable_fill="0"
  853. else
  854. enable_fill="1"
  855. fi
  856. ],
  857. [enable_fill="1"]
  858. )
  859. if test "x$enable_fill" = "x1" ; then
  860. AC_DEFINE([JEMALLOC_FILL], [ ])
  861. fi
  862. AC_SUBST([enable_fill])
  863. dnl Disable utrace(2)-based tracing by default.
  864. AC_ARG_ENABLE([utrace],
  865. [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
  866. [if test "x$enable_utrace" = "xno" ; then
  867. enable_utrace="0"
  868. else
  869. enable_utrace="1"
  870. fi
  871. ],
  872. [enable_utrace="0"]
  873. )
  874. JE_COMPILABLE([utrace(2)], [
  875. #include <sys/types.h>
  876. #include <sys/param.h>
  877. #include <sys/time.h>
  878. #include <sys/uio.h>
  879. #include <sys/ktrace.h>
  880. ], [
  881. utrace((void *)0, 0);
  882. ], [je_cv_utrace])
  883. if test "x${je_cv_utrace}" = "xno" ; then
  884. enable_utrace="0"
  885. fi
  886. if test "x$enable_utrace" = "x1" ; then
  887. AC_DEFINE([JEMALLOC_UTRACE], [ ])
  888. fi
  889. AC_SUBST([enable_utrace])
  890. dnl Support Valgrind by default.
  891. AC_ARG_ENABLE([valgrind],
  892. [AS_HELP_STRING([--disable-valgrind], [Disable support for Valgrind])],
  893. [if test "x$enable_valgrind" = "xno" ; then
  894. enable_valgrind="0"
  895. else
  896. enable_valgrind="1"
  897. fi
  898. ],
  899. [enable_valgrind="1"]
  900. )
  901. if test "x$enable_valgrind" = "x1" ; then
  902. JE_COMPILABLE([valgrind], [
  903. #include <valgrind/valgrind.h>
  904. #include <valgrind/memcheck.h>
  905. #if !defined(VALGRIND_RESIZEINPLACE_BLOCK)
  906. # error "Incompatible Valgrind version"
  907. #endif
  908. ], [], [je_cv_valgrind])
  909. if test "x${je_cv_valgrind}" = "xno" ; then
  910. enable_valgrind="0"
  911. fi
  912. if test "x$enable_valgrind" = "x1" ; then
  913. AC_DEFINE([JEMALLOC_VALGRIND], [ ])
  914. fi
  915. fi
  916. AC_SUBST([enable_valgrind])
  917. dnl Do not support the xmalloc option by default.
  918. AC_ARG_ENABLE([xmalloc],
  919. [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
  920. [if test "x$enable_xmalloc" = "xno" ; then
  921. enable_xmalloc="0"
  922. else
  923. enable_xmalloc="1"
  924. fi
  925. ],
  926. [enable_xmalloc="0"]
  927. )
  928. if test "x$enable_xmalloc" = "x1" ; then
  929. AC_DEFINE([JEMALLOC_XMALLOC], [ ])
  930. fi
  931. AC_SUBST([enable_xmalloc])
  932. dnl Support cache-oblivious allocation alignment by default.
  933. AC_ARG_ENABLE([cache-oblivious],
  934. [AS_HELP_STRING([--disable-cache-oblivious],
  935. [Disable support for cache-oblivious allocation alignment])],
  936. [if test "x$enable_cache_oblivious" = "xno" ; then
  937. enable_cache_oblivious="0"
  938. else
  939. enable_cache_oblivious="1"
  940. fi
  941. ],
  942. [enable_cache_oblivious="1"]
  943. )
  944. if test "x$enable_cache_oblivious" = "x1" ; then
  945. AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
  946. fi
  947. AC_SUBST([enable_cache_oblivious])
  948. dnl ============================================================================
  949. dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
  950. dnl One of those two functions should (theoretically) exist on all platforms
  951. dnl that jemalloc currently has a chance of functioning on without modification.
  952. dnl We additionally assume ffs() or __builtin_ffs() are defined if
  953. dnl ffsl() or __builtin_ffsl() are defined, respectively.
  954. JE_COMPILABLE([a program using __builtin_ffsl], [
  955. #include <stdio.h>
  956. #include <strings.h>
  957. #include <string.h>
  958. ], [
  959. {
  960. int rv = __builtin_ffsl(0x08);
  961. printf("%d\n", rv);
  962. }
  963. ], [je_cv_gcc_builtin_ffsl])
  964. if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
  965. AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
  966. AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
  967. else
  968. JE_COMPILABLE([a program using ffsl], [
  969. #include <stdio.h>
  970. #include <strings.h>
  971. #include <string.h>
  972. ], [
  973. {
  974. int rv = ffsl(0x08);
  975. printf("%d\n", rv);
  976. }
  977. ], [je_cv_function_ffsl])
  978. if test "x${je_cv_function_ffsl}" = "xyes" ; then
  979. AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
  980. AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
  981. else
  982. AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
  983. fi
  984. fi
  985. AC_ARG_WITH([lg_tiny_min],
  986. [AS_HELP_STRING([--with-lg-tiny-min=<lg-tiny-min>],
  987. [Base 2 log of minimum tiny size class to support])],
  988. [LG_TINY_MIN="$with_lg_tiny_min"],
  989. [LG_TINY_MIN="3"])
  990. AC_DEFINE_UNQUOTED([LG_TINY_MIN], [$LG_TINY_MIN])
  991. AC_ARG_WITH([lg_quantum],
  992. [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
  993. [Base 2 log of minimum allocation alignment])],
  994. [LG_QUANTA="$with_lg_quantum"],
  995. [LG_QUANTA="3 4"])
  996. if test "x$with_lg_quantum" != "x" ; then
  997. AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
  998. fi
  999. AC_ARG_WITH([lg_page],
  1000. [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
  1001. [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
  1002. if test "x$LG_PAGE" = "xdetect"; then
  1003. AC_CACHE_CHECK([LG_PAGE],
  1004. [je_cv_lg_page],
  1005. AC_RUN_IFELSE([AC_LANG_PROGRAM(
  1006. [[
  1007. #include <strings.h>
  1008. #ifdef _WIN32
  1009. #include <windows.h>
  1010. #else
  1011. #include <unistd.h>
  1012. #endif
  1013. #include <stdio.h>
  1014. ]],
  1015. [[
  1016. int result;
  1017. FILE *f;
  1018. #ifdef _WIN32
  1019. SYSTEM_INFO si;
  1020. GetSystemInfo(&si);
  1021. result = si.dwPageSize;
  1022. #else
  1023. result = sysconf(_SC_PAGESIZE);
  1024. #endif
  1025. if (result == -1) {
  1026. return 1;
  1027. }
  1028. result = JEMALLOC_INTERNAL_FFSL(result) - 1;
  1029. f = fopen("conftest.out", "w");
  1030. if (f == NULL) {
  1031. return 1;
  1032. }
  1033. fprintf(f, "%d\n", result);
  1034. fclose(f);
  1035. return 0;
  1036. ]])],
  1037. [je_cv_lg_page=`cat conftest.out`],
  1038. [je_cv_lg_page=undefined],
  1039. [je_cv_lg_page=12]))
  1040. fi
  1041. if test "x${je_cv_lg_page}" != "x" ; then
  1042. LG_PAGE="${je_cv_lg_page}"
  1043. fi
  1044. if test "x${LG_PAGE}" != "xundefined" ; then
  1045. AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
  1046. else
  1047. AC_MSG_ERROR([cannot determine value for LG_PAGE])
  1048. fi
  1049. AC_ARG_WITH([lg_page_sizes],
  1050. [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
  1051. [Base 2 logs of system page sizes to support])],
  1052. [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
  1053. AC_ARG_WITH([lg_size_class_group],
  1054. [AS_HELP_STRING([--with-lg-size-class-group=<lg-size-class-group>],
  1055. [Base 2 log of size classes per doubling])],
  1056. [LG_SIZE_CLASS_GROUP="$with_lg_size_class_group"],
  1057. [LG_SIZE_CLASS_GROUP="2"])
  1058. dnl ============================================================================
  1059. dnl jemalloc configuration.
  1060. dnl
  1061. dnl Set VERSION if source directory is inside a git repository.
  1062. if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
  1063. dnl Pattern globs aren't powerful enough to match both single- and
  1064. dnl double-digit version numbers, so iterate over patterns to support up to
  1065. dnl version 99.99.99 without any accidental matches.
  1066. rm -f "${objroot}VERSION"
  1067. for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
  1068. '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
  1069. '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
  1070. '[0-9][0-9].[0-9][0-9].[0-9]' \
  1071. '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
  1072. if test ! -e "${objroot}VERSION" ; then
  1073. (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
  1074. if test $? -eq 0 ; then
  1075. mv "${objroot}VERSION.tmp" "${objroot}VERSION"
  1076. break
  1077. fi
  1078. fi
  1079. done
  1080. fi
  1081. rm -f "${objroot}VERSION.tmp"
  1082. if test ! -e "${objroot}VERSION" ; then
  1083. if test ! -e "${srcroot}VERSION" ; then
  1084. AC_MSG_RESULT(
  1085. [Missing VERSION file, and unable to generate it; creating bogus VERSION])
  1086. echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
  1087. else
  1088. cp ${srcroot}VERSION ${objroot}VERSION
  1089. fi
  1090. fi
  1091. jemalloc_version=`cat "${objroot}VERSION"`
  1092. jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
  1093. jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
  1094. jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
  1095. jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
  1096. jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
  1097. AC_SUBST([jemalloc_version])
  1098. AC_SUBST([jemalloc_version_major])
  1099. AC_SUBST([jemalloc_version_minor])
  1100. AC_SUBST([jemalloc_version_bugfix])
  1101. AC_SUBST([jemalloc_version_nrev])
  1102. AC_SUBST([jemalloc_version_gid])
  1103. dnl ============================================================================
  1104. dnl Configure pthreads.
  1105. if test "x$abi" != "xpecoff" ; then
  1106. AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
  1107. dnl Some systems may embed pthreads functionality in libc; check for libpthread
  1108. dnl first, but try libc too before failing.
  1109. AC_CHECK_LIB([pthread], [pthread_create], [LIBS="$LIBS -lpthread"],
  1110. [AC_SEARCH_LIBS([pthread_create], , ,
  1111. AC_MSG_ERROR([libpthread is missing]))])
  1112. fi
  1113. CPPFLAGS="$CPPFLAGS -D_REENTRANT"
  1114. dnl Check whether clock_gettime(2) is in libc or librt. This function is only
  1115. dnl used in test code, so save the result to TESTLIBS to avoid poluting LIBS.
  1116. SAVED_LIBS="${LIBS}"
  1117. LIBS=
  1118. AC_SEARCH_LIBS([clock_gettime], [rt], [TESTLIBS="${LIBS}"])
  1119. AC_SUBST([TESTLIBS])
  1120. LIBS="${SAVED_LIBS}"
  1121. dnl Check if the GNU-specific secure_getenv function exists.
  1122. AC_CHECK_FUNC([secure_getenv],
  1123. [have_secure_getenv="1"],
  1124. [have_secure_getenv="0"]
  1125. )
  1126. if test "x$have_secure_getenv" = "x1" ; then
  1127. AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
  1128. fi
  1129. dnl Check if the Solaris/BSD issetugid function exists.
  1130. AC_CHECK_FUNC([issetugid],
  1131. [have_issetugid="1"],
  1132. [have_issetugid="0"]
  1133. )
  1134. if test "x$have_issetugid" = "x1" ; then
  1135. AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
  1136. fi
  1137. dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
  1138. dnl it rather than pthreads TSD cleanup functions to support cleanup during
  1139. dnl thread exit, in order to avoid pthreads library recursion during
  1140. dnl bootstrapping.
  1141. AC_CHECK_FUNC([_malloc_thread_cleanup],
  1142. [have__malloc_thread_cleanup="1"],
  1143. [have__malloc_thread_cleanup="0"]
  1144. )
  1145. if test "x$have__malloc_thread_cleanup" = "x1" ; then
  1146. AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
  1147. force_tls="1"
  1148. fi
  1149. dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
  1150. dnl so, mutex initialization causes allocation, and we need to implement this
  1151. dnl callback function in order to prevent recursive allocation.
  1152. AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
  1153. [have__pthread_mutex_init_calloc_cb="1"],
  1154. [have__pthread_mutex_init_calloc_cb="0"]
  1155. )
  1156. if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
  1157. AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
  1158. fi
  1159. dnl Disable lazy locking by default.
  1160. AC_ARG_ENABLE([lazy_lock],
  1161. [AS_HELP_STRING([--enable-lazy-lock],
  1162. [Enable lazy locking (only lock when multi-threaded)])],
  1163. [if test "x$enable_lazy_lock" = "xno" ; then
  1164. enable_lazy_lock="0"
  1165. else
  1166. enable_lazy_lock="1"
  1167. fi
  1168. ],
  1169. [enable_lazy_lock=""]
  1170. )
  1171. if test "x$enable_lazy_lock" = "x" -a "x${force_lazy_lock}" = "x1" ; then
  1172. AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
  1173. enable_lazy_lock="1"
  1174. fi
  1175. if test "x$enable_lazy_lock" = "x1" ; then
  1176. if test "x$abi" != "xpecoff" ; then
  1177. AC_CHECK_HEADERS([dlfcn.h], , [AC_MSG_ERROR([dlfcn.h is missing])])
  1178. AC_CHECK_FUNC([dlsym], [],
  1179. [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"],
  1180. [AC_MSG_ERROR([libdl is missing])])
  1181. ])
  1182. fi
  1183. AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
  1184. else
  1185. enable_lazy_lock="0"
  1186. fi
  1187. AC_SUBST([enable_lazy_lock])
  1188. AC_ARG_ENABLE([tls],
  1189. [AS_HELP_STRING([--disable-tls], [Disable thread-local storage (__thread keyword)])],
  1190. if test "x$enable_tls" = "xno" ; then
  1191. enable_tls="0"
  1192. else
  1193. enable_tls="1"
  1194. fi
  1195. ,
  1196. enable_tls=""
  1197. )
  1198. if test "x${enable_tls}" = "x" ; then
  1199. if test "x${force_tls}" = "x1" ; then
  1200. AC_MSG_RESULT([Forcing TLS to avoid allocator/threading bootstrap issues])
  1201. enable_tls="1"
  1202. elif test "x${force_tls}" = "x0" ; then
  1203. AC_MSG_RESULT([Forcing no TLS to avoid allocator/threading bootstrap issues])
  1204. enable_tls="0"
  1205. else
  1206. enable_tls="1"
  1207. fi
  1208. fi
  1209. if test "x${enable_tls}" = "x1" ; then
  1210. AC_MSG_CHECKING([for TLS])
  1211. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  1212. [[
  1213. __thread int x;
  1214. ]], [[
  1215. x = 42;
  1216. return 0;
  1217. ]])],
  1218. AC_MSG_RESULT([yes]),
  1219. AC_MSG_RESULT([no])
  1220. enable_tls="0")
  1221. else
  1222. enable_tls="0"
  1223. fi
  1224. AC_SUBST([enable_tls])
  1225. if test "x${enable_tls}" = "x1" ; then
  1226. if test "x${force_tls}" = "x0" ; then
  1227. AC_MSG_WARN([TLS enabled despite being marked unusable on this platform])
  1228. fi
  1229. AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
  1230. elif test "x${force_tls}" = "x1" ; then
  1231. AC_MSG_WARN([TLS disabled despite being marked critical on this platform])
  1232. fi
  1233. dnl ============================================================================
  1234. dnl Check for C11 atomics.
  1235. JE_COMPILABLE([C11 atomics], [
  1236. #include <stdint.h>
  1237. #if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
  1238. #include <stdatomic.h>
  1239. #else
  1240. #error Atomics not available
  1241. #endif
  1242. ], [
  1243. uint64_t *p = (uint64_t *)0;
  1244. uint64_t x = 1;
  1245. volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
  1246. uint64_t r = atomic_fetch_add(a, x) + x;
  1247. return (r == 0);
  1248. ], [je_cv_c11atomics])
  1249. if test "x${je_cv_c11atomics}" = "xyes" ; then
  1250. AC_DEFINE([JEMALLOC_C11ATOMICS])
  1251. fi
  1252. dnl ============================================================================
  1253. dnl Check for atomic(9) operations as provided on FreeBSD.
  1254. JE_COMPILABLE([atomic(9)], [
  1255. #include <sys/types.h>
  1256. #include <machine/atomic.h>
  1257. #include <inttypes.h>
  1258. ], [
  1259. {
  1260. uint32_t x32 = 0;
  1261. volatile uint32_t *x32p = &x32;
  1262. atomic_fetchadd_32(x32p, 1);
  1263. }
  1264. {
  1265. unsigned long xlong = 0;
  1266. volatile unsigned long *xlongp = &xlong;
  1267. atomic_fetchadd_long(xlongp, 1);
  1268. }
  1269. ], [je_cv_atomic9])
  1270. if test "x${je_cv_atomic9}" = "xyes" ; then
  1271. AC_DEFINE([JEMALLOC_ATOMIC9])
  1272. fi
  1273. dnl ============================================================================
  1274. dnl Check for atomic(3) operations as provided on Darwin.
  1275. JE_COMPILABLE([Darwin OSAtomic*()], [
  1276. #include <libkern/OSAtomic.h>
  1277. #include <inttypes.h>
  1278. ], [
  1279. {
  1280. int32_t x32 = 0;
  1281. volatile int32_t *x32p = &x32;
  1282. OSAtomicAdd32(1, x32p);
  1283. }
  1284. {
  1285. int64_t x64 = 0;
  1286. volatile int64_t *x64p = &x64;
  1287. OSAtomicAdd64(1, x64p);
  1288. }
  1289. ], [je_cv_osatomic])
  1290. if test "x${je_cv_osatomic}" = "xyes" ; then
  1291. AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
  1292. fi
  1293. dnl ============================================================================
  1294. dnl Check for madvise(2).
  1295. JE_COMPILABLE([madvise(2)], [
  1296. #include <sys/mman.h>
  1297. ], [
  1298. {
  1299. madvise((void *)0, 0, 0);
  1300. }
  1301. ], [je_cv_madvise])
  1302. if test "x${je_cv_madvise}" = "xyes" ; then
  1303. AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
  1304. fi
  1305. dnl ============================================================================
  1306. dnl Check whether __sync_{add,sub}_and_fetch() are available despite
  1307. dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
  1308. AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
  1309. AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
  1310. [je_cv_sync_compare_and_swap_$2],
  1311. [AC_LINK_IFELSE([AC_LANG_PROGRAM([
  1312. #include <stdint.h>
  1313. ],
  1314. [
  1315. #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
  1316. {
  1317. uint$1_t x$1 = 0;
  1318. __sync_add_and_fetch(&x$1, 42);
  1319. __sync_sub_and_fetch(&x$1, 1);
  1320. }
  1321. #else
  1322. #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
  1323. #endif
  1324. ])],
  1325. [je_cv_sync_compare_and_swap_$2=yes],
  1326. [je_cv_sync_compare_and_swap_$2=no])])
  1327. if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
  1328. AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
  1329. fi
  1330. ])
  1331. if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
  1332. JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
  1333. JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
  1334. fi
  1335. dnl ============================================================================
  1336. dnl Check for __builtin_clz() and __builtin_clzl().
  1337. AC_CACHE_CHECK([for __builtin_clz],
  1338. [je_cv_builtin_clz],
  1339. [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
  1340. [
  1341. {
  1342. unsigned x = 0;
  1343. int y = __builtin_clz(x);
  1344. }
  1345. {
  1346. unsigned long x = 0;
  1347. int y = __builtin_clzl(x);
  1348. }
  1349. ])],
  1350. [je_cv_builtin_clz=yes],
  1351. [je_cv_builtin_clz=no])])
  1352. if test "x${je_cv_builtin_clz}" = "xyes" ; then
  1353. AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
  1354. fi
  1355. dnl ============================================================================
  1356. dnl Check for spinlock(3) operations as provided on Darwin.
  1357. JE_COMPILABLE([Darwin OSSpin*()], [
  1358. #include <libkern/OSAtomic.h>
  1359. #include <inttypes.h>
  1360. ], [
  1361. OSSpinLock lock = 0;
  1362. OSSpinLockLock(&lock);
  1363. OSSpinLockUnlock(&lock);
  1364. ], [je_cv_osspin])
  1365. if test "x${je_cv_osspin}" = "xyes" ; then
  1366. AC_DEFINE([JEMALLOC_OSSPIN], [ ])
  1367. fi
  1368. dnl ============================================================================
  1369. dnl Darwin-related configuration.
  1370. AC_ARG_ENABLE([zone-allocator],
  1371. [AS_HELP_STRING([--disable-zone-allocator],
  1372. [Disable zone allocator for Darwin])],
  1373. [if test "x$enable_zone_allocator" = "xno" ; then
  1374. enable_zone_allocator="0"
  1375. else
  1376. enable_zone_allocator="1"
  1377. fi
  1378. ],
  1379. [if test "x${abi}" = "xmacho"; then
  1380. enable_zone_allocator="1"
  1381. fi
  1382. ]
  1383. )
  1384. AC_SUBST([enable_zone_allocator])
  1385. if test "x${enable_zone_allocator}" = "x1" ; then
  1386. if test "x${abi}" != "xmacho"; then
  1387. AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
  1388. fi
  1389. AC_DEFINE([JEMALLOC_ZONE], [ ])
  1390. dnl The szone version jumped from 3 to 6 between the OS X 10.5.x and 10.6
  1391. dnl releases. malloc_zone_t and malloc_introspection_t have new fields in
  1392. dnl 10.6, which is the only source-level indication of the change.
  1393. AC_MSG_CHECKING([malloc zone version])
  1394. AC_DEFUN([JE_ZONE_PROGRAM],
  1395. [AC_LANG_PROGRAM(
  1396. [#include <malloc/malloc.h>],
  1397. [static int foo[[sizeof($1) $2 sizeof(void *) * $3 ? 1 : -1]]]
  1398. )])
  1399. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,14)],[JEMALLOC_ZONE_VERSION=3],[
  1400. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,15)],[JEMALLOC_ZONE_VERSION=5],[
  1401. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,16)],[
  1402. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,9)],[JEMALLOC_ZONE_VERSION=6],[
  1403. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_introspection_t,==,13)],[JEMALLOC_ZONE_VERSION=7],[JEMALLOC_ZONE_VERSION=]
  1404. )])],[
  1405. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,==,17)],[JEMALLOC_ZONE_VERSION=8],[
  1406. AC_COMPILE_IFELSE([JE_ZONE_PROGRAM(malloc_zone_t,>,17)],[JEMALLOC_ZONE_VERSION=9],[JEMALLOC_ZONE_VERSION=]
  1407. )])])])])
  1408. if test "x${JEMALLOC_ZONE_VERSION}" = "x"; then
  1409. AC_MSG_RESULT([unsupported])
  1410. AC_MSG_ERROR([Unsupported malloc zone version])
  1411. fi
  1412. if test "${JEMALLOC_ZONE_VERSION}" = 9; then
  1413. JEMALLOC_ZONE_VERSION=8
  1414. AC_MSG_RESULT([> 8])
  1415. else
  1416. AC_MSG_RESULT([$JEMALLOC_ZONE_VERSION])
  1417. fi
  1418. AC_DEFINE_UNQUOTED(JEMALLOC_ZONE_VERSION, [$JEMALLOC_ZONE_VERSION])
  1419. fi
  1420. dnl ============================================================================
  1421. dnl Check for glibc malloc hooks
  1422. JE_COMPILABLE([glibc malloc hook], [
  1423. #include <stddef.h>
  1424. extern void (* __free_hook)(void *ptr);
  1425. extern void *(* __malloc_hook)(size_t size);
  1426. extern void *(* __realloc_hook)(void *ptr, size_t size);
  1427. ], [
  1428. void *ptr = 0L;
  1429. if (__malloc_hook) ptr = __malloc_hook(1);
  1430. if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
  1431. if (__free_hook && ptr) __free_hook(ptr);
  1432. ], [je_cv_glibc_malloc_hook])
  1433. if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
  1434. AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
  1435. fi
  1436. JE_COMPILABLE([glibc memalign hook], [
  1437. #include <stddef.h>
  1438. extern void *(* __memalign_hook)(size_t alignment, size_t size);
  1439. ], [
  1440. void *ptr = 0L;
  1441. if (__memalign_hook) ptr = __memalign_hook(16, 7);
  1442. ], [je_cv_glibc_memalign_hook])
  1443. if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
  1444. AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
  1445. fi
  1446. JE_COMPILABLE([pthreads adaptive mutexes], [
  1447. #include <pthread.h>
  1448. ], [
  1449. pthread_mutexattr_t attr;
  1450. pthread_mutexattr_init(&attr);
  1451. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
  1452. pthread_mutexattr_destroy(&attr);
  1453. ], [je_cv_pthread_mutex_adaptive_np])
  1454. if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
  1455. AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
  1456. fi
  1457. dnl ============================================================================
  1458. dnl Check for typedefs, structures, and compiler characteristics.
  1459. AC_HEADER_STDBOOL
  1460. dnl ============================================================================
  1461. dnl Define commands that generate output files.
  1462. AC_CONFIG_COMMANDS([include/jemalloc/internal/private_namespace.h], [
  1463. mkdir -p "${objroot}include/jemalloc/internal"
  1464. "${srcdir}/include/jemalloc/internal/private_namespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_namespace.h"
  1465. ], [
  1466. srcdir="${srcdir}"
  1467. objroot="${objroot}"
  1468. ])
  1469. AC_CONFIG_COMMANDS([include/jemalloc/internal/private_unnamespace.h], [
  1470. mkdir -p "${objroot}include/jemalloc/internal"
  1471. "${srcdir}/include/jemalloc/internal/private_unnamespace.sh" "${srcdir}/include/jemalloc/internal/private_symbols.txt" > "${objroot}include/jemalloc/internal/private_unnamespace.h"
  1472. ], [
  1473. srcdir="${srcdir}"
  1474. objroot="${objroot}"
  1475. ])
  1476. AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
  1477. f="${objroot}include/jemalloc/internal/public_symbols.txt"
  1478. mkdir -p "${objroot}include/jemalloc/internal"
  1479. cp /dev/null "${f}"
  1480. for nm in `echo ${mangling_map} |tr ',' ' '` ; do
  1481. n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
  1482. m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
  1483. echo "${n}:${m}" >> "${f}"
  1484. dnl Remove name from public_syms so that it isn't redefined later.
  1485. public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
  1486. done
  1487. for sym in ${public_syms} ; do
  1488. n="${sym}"
  1489. m="${JEMALLOC_PREFIX}${sym}"
  1490. echo "${n}:${m}" >> "${f}"
  1491. done
  1492. ], [
  1493. srcdir="${srcdir}"
  1494. objroot="${objroot}"
  1495. mangling_map="${mangling_map}"
  1496. public_syms="${public_syms}"
  1497. JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
  1498. ])
  1499. AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
  1500. mkdir -p "${objroot}include/jemalloc/internal"
  1501. "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
  1502. ], [
  1503. srcdir="${srcdir}"
  1504. objroot="${objroot}"
  1505. ])
  1506. AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
  1507. mkdir -p "${objroot}include/jemalloc/internal"
  1508. "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
  1509. ], [
  1510. srcdir="${srcdir}"
  1511. objroot="${objroot}"
  1512. ])
  1513. AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
  1514. mkdir -p "${objroot}include/jemalloc/internal"
  1515. "${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"
  1516. ], [
  1517. SHELL="${SHELL}"
  1518. srcdir="${srcdir}"
  1519. objroot="${objroot}"
  1520. LG_QUANTA="${LG_QUANTA}"
  1521. LG_TINY_MIN=${LG_TINY_MIN}
  1522. LG_PAGE_SIZES="${LG_PAGE_SIZES}"
  1523. LG_SIZE_CLASS_GROUP=${LG_SIZE_CLASS_GROUP}
  1524. ])
  1525. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
  1526. mkdir -p "${objroot}include/jemalloc"
  1527. cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
  1528. ], [
  1529. srcdir="${srcdir}"
  1530. objroot="${objroot}"
  1531. ])
  1532. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
  1533. mkdir -p "${objroot}include/jemalloc"
  1534. "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
  1535. ], [
  1536. srcdir="${srcdir}"
  1537. objroot="${objroot}"
  1538. ])
  1539. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
  1540. mkdir -p "${objroot}include/jemalloc"
  1541. "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
  1542. ], [
  1543. srcdir="${srcdir}"
  1544. objroot="${objroot}"
  1545. ])
  1546. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
  1547. mkdir -p "${objroot}include/jemalloc"
  1548. "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
  1549. ], [
  1550. srcdir="${srcdir}"
  1551. objroot="${objroot}"
  1552. ])
  1553. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
  1554. mkdir -p "${objroot}include/jemalloc"
  1555. "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
  1556. ], [
  1557. srcdir="${srcdir}"
  1558. objroot="${objroot}"
  1559. install_suffix="${install_suffix}"
  1560. ])
  1561. dnl Process .in files.
  1562. AC_SUBST([cfghdrs_in])
  1563. AC_SUBST([cfghdrs_out])
  1564. AC_CONFIG_HEADERS([$cfghdrs_tup])
  1565. dnl ============================================================================
  1566. dnl Generate outputs.
  1567. AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
  1568. AC_SUBST([cfgoutputs_in])
  1569. AC_SUBST([cfgoutputs_out])
  1570. AC_OUTPUT
  1571. dnl ============================================================================
  1572. dnl Print out the results of configuration.
  1573. AC_MSG_RESULT([===============================================================================])
  1574. AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
  1575. AC_MSG_RESULT([library revision : ${rev}])
  1576. AC_MSG_RESULT([])
  1577. AC_MSG_RESULT([CONFIG : ${CONFIG}])
  1578. AC_MSG_RESULT([CC : ${CC}])
  1579. AC_MSG_RESULT([CFLAGS : ${CFLAGS}])
  1580. AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
  1581. AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
  1582. AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
  1583. AC_MSG_RESULT([LIBS : ${LIBS}])
  1584. AC_MSG_RESULT([TESTLIBS : ${TESTLIBS}])
  1585. AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
  1586. AC_MSG_RESULT([])
  1587. AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
  1588. AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
  1589. AC_MSG_RESULT([])
  1590. AC_MSG_RESULT([PREFIX : ${PREFIX}])
  1591. AC_MSG_RESULT([BINDIR : ${BINDIR}])
  1592. AC_MSG_RESULT([DATADIR : ${DATADIR}])
  1593. AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
  1594. AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
  1595. AC_MSG_RESULT([MANDIR : ${MANDIR}])
  1596. AC_MSG_RESULT([])
  1597. AC_MSG_RESULT([srcroot : ${srcroot}])
  1598. AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
  1599. AC_MSG_RESULT([objroot : ${objroot}])
  1600. AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
  1601. AC_MSG_RESULT([])
  1602. AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
  1603. AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
  1604. AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
  1605. AC_MSG_RESULT([install_suffix : ${install_suffix}])
  1606. AC_MSG_RESULT([autogen : ${enable_autogen}])
  1607. AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
  1608. AC_MSG_RESULT([debug : ${enable_debug}])
  1609. AC_MSG_RESULT([code-coverage : ${enable_code_coverage}])
  1610. AC_MSG_RESULT([stats : ${enable_stats}])
  1611. AC_MSG_RESULT([prof : ${enable_prof}])
  1612. AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
  1613. AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
  1614. AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
  1615. AC_MSG_RESULT([tcache : ${enable_tcache}])
  1616. AC_MSG_RESULT([fill : ${enable_fill}])
  1617. AC_MSG_RESULT([utrace : ${enable_utrace}])
  1618. AC_MSG_RESULT([valgrind : ${enable_valgrind}])
  1619. AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
  1620. AC_MSG_RESULT([munmap : ${enable_munmap}])
  1621. AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
  1622. AC_MSG_RESULT([tls : ${enable_tls}])
  1623. AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
  1624. AC_MSG_RESULT([===============================================================================])