configure.ac 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  1. dnl Process this file with autoconf to produce a configure script.
  2. AC_PREREQ(2.68)
  3. AC_INIT([Makefile.in])
  4. AC_CONFIG_AUX_DIR([build-aux])
  5. dnl ============================================================================
  6. dnl Custom macro definitions.
  7. dnl JE_CONCAT_VVV(r, a, b)
  8. dnl
  9. dnl Set $r to the concatenation of $a and $b, with a space separating them iff
  10. dnl both $a and $b are non-empty.
  11. AC_DEFUN([JE_CONCAT_VVV],
  12. if test "x[$]{$2}" = "x" -o "x[$]{$3}" = "x" ; then
  13. $1="[$]{$2}[$]{$3}"
  14. else
  15. $1="[$]{$2} [$]{$3}"
  16. fi
  17. )
  18. dnl JE_APPEND_VS(a, b)
  19. dnl
  20. dnl Set $a to the concatenation of $a and b, with a space separating them iff
  21. dnl both $a and b are non-empty.
  22. AC_DEFUN([JE_APPEND_VS],
  23. T_APPEND_V=$2
  24. JE_CONCAT_VVV($1, $1, T_APPEND_V)
  25. )
  26. CONFIGURE_CFLAGS=
  27. SPECIFIED_CFLAGS="${CFLAGS}"
  28. dnl JE_CFLAGS_ADD(cflag)
  29. dnl
  30. dnl CFLAGS is the concatenation of CONFIGURE_CFLAGS and SPECIFIED_CFLAGS
  31. dnl (ignoring EXTRA_CFLAGS, which does not impact configure tests. This macro
  32. dnl appends to CONFIGURE_CFLAGS and regenerates CFLAGS.
  33. AC_DEFUN([JE_CFLAGS_ADD],
  34. [
  35. AC_MSG_CHECKING([whether compiler supports $1])
  36. T_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
  37. JE_APPEND_VS(CONFIGURE_CFLAGS, $1)
  38. JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
  39. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  40. [[
  41. ]], [[
  42. return 0;
  43. ]])],
  44. [je_cv_cflags_added=$1]
  45. AC_MSG_RESULT([yes]),
  46. [je_cv_cflags_added=]
  47. AC_MSG_RESULT([no])
  48. [CONFIGURE_CFLAGS="${T_CONFIGURE_CFLAGS}"]
  49. )
  50. JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
  51. ])
  52. dnl JE_CFLAGS_SAVE()
  53. dnl JE_CFLAGS_RESTORE()
  54. dnl
  55. dnl Save/restore CFLAGS. Nesting is not supported.
  56. AC_DEFUN([JE_CFLAGS_SAVE],
  57. SAVED_CONFIGURE_CFLAGS="${CONFIGURE_CFLAGS}"
  58. )
  59. AC_DEFUN([JE_CFLAGS_RESTORE],
  60. CONFIGURE_CFLAGS="${SAVED_CONFIGURE_CFLAGS}"
  61. JE_CONCAT_VVV(CFLAGS, CONFIGURE_CFLAGS, SPECIFIED_CFLAGS)
  62. )
  63. CONFIGURE_CXXFLAGS=
  64. SPECIFIED_CXXFLAGS="${CXXFLAGS}"
  65. dnl JE_CXXFLAGS_ADD(cxxflag)
  66. AC_DEFUN([JE_CXXFLAGS_ADD],
  67. [
  68. AC_MSG_CHECKING([whether compiler supports $1])
  69. T_CONFIGURE_CXXFLAGS="${CONFIGURE_CXXFLAGS}"
  70. JE_APPEND_VS(CONFIGURE_CXXFLAGS, $1)
  71. JE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
  72. AC_LANG_PUSH([C++])
  73. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  74. [[
  75. ]], [[
  76. return 0;
  77. ]])],
  78. [je_cv_cxxflags_added=$1]
  79. AC_MSG_RESULT([yes]),
  80. [je_cv_cxxflags_added=]
  81. AC_MSG_RESULT([no])
  82. [CONFIGURE_CXXFLAGS="${T_CONFIGURE_CXXFLAGS}"]
  83. )
  84. AC_LANG_POP([C++])
  85. JE_CONCAT_VVV(CXXFLAGS, CONFIGURE_CXXFLAGS, SPECIFIED_CXXFLAGS)
  86. ])
  87. dnl JE_COMPILABLE(label, hcode, mcode, rvar)
  88. dnl
  89. dnl Use AC_LINK_IFELSE() rather than AC_COMPILE_IFELSE() so that linker errors
  90. dnl cause failure.
  91. AC_DEFUN([JE_COMPILABLE],
  92. [
  93. AC_CACHE_CHECK([whether $1 is compilable],
  94. [$4],
  95. [AC_LINK_IFELSE([AC_LANG_PROGRAM([$2],
  96. [$3])],
  97. [$4=yes],
  98. [$4=no])])
  99. ])
  100. dnl ============================================================================
  101. CONFIG=`echo ${ac_configure_args} | sed -e 's#'"'"'\([^ ]*\)'"'"'#\1#g'`
  102. AC_SUBST([CONFIG])
  103. dnl Library revision.
  104. rev=2
  105. AC_SUBST([rev])
  106. srcroot=$srcdir
  107. if test "x${srcroot}" = "x." ; then
  108. srcroot=""
  109. else
  110. srcroot="${srcroot}/"
  111. fi
  112. AC_SUBST([srcroot])
  113. abs_srcroot="`cd \"${srcdir}\"; pwd`/"
  114. AC_SUBST([abs_srcroot])
  115. objroot=""
  116. AC_SUBST([objroot])
  117. abs_objroot="`pwd`/"
  118. AC_SUBST([abs_objroot])
  119. dnl Munge install path variables.
  120. if test "x$prefix" = "xNONE" ; then
  121. prefix="/usr/local"
  122. fi
  123. if test "x$exec_prefix" = "xNONE" ; then
  124. exec_prefix=$prefix
  125. fi
  126. PREFIX=$prefix
  127. AC_SUBST([PREFIX])
  128. BINDIR=`eval echo $bindir`
  129. BINDIR=`eval echo $BINDIR`
  130. AC_SUBST([BINDIR])
  131. INCLUDEDIR=`eval echo $includedir`
  132. INCLUDEDIR=`eval echo $INCLUDEDIR`
  133. AC_SUBST([INCLUDEDIR])
  134. LIBDIR=`eval echo $libdir`
  135. LIBDIR=`eval echo $LIBDIR`
  136. AC_SUBST([LIBDIR])
  137. DATADIR=`eval echo $datadir`
  138. DATADIR=`eval echo $DATADIR`
  139. AC_SUBST([DATADIR])
  140. MANDIR=`eval echo $mandir`
  141. MANDIR=`eval echo $MANDIR`
  142. AC_SUBST([MANDIR])
  143. dnl Support for building documentation.
  144. AC_PATH_PROG([XSLTPROC], [xsltproc], [false], [$PATH])
  145. if test -d "/usr/share/xml/docbook/stylesheet/docbook-xsl" ; then
  146. DEFAULT_XSLROOT="/usr/share/xml/docbook/stylesheet/docbook-xsl"
  147. elif test -d "/usr/share/sgml/docbook/xsl-stylesheets" ; then
  148. DEFAULT_XSLROOT="/usr/share/sgml/docbook/xsl-stylesheets"
  149. else
  150. dnl Documentation building will fail if this default gets used.
  151. DEFAULT_XSLROOT=""
  152. fi
  153. AC_ARG_WITH([xslroot],
  154. [AS_HELP_STRING([--with-xslroot=<path>], [XSL stylesheet root path])], [
  155. if test "x$with_xslroot" = "xno" ; then
  156. XSLROOT="${DEFAULT_XSLROOT}"
  157. else
  158. XSLROOT="${with_xslroot}"
  159. fi
  160. ],
  161. XSLROOT="${DEFAULT_XSLROOT}"
  162. )
  163. AC_SUBST([XSLROOT])
  164. dnl If CFLAGS isn't defined, set CFLAGS to something reasonable. Otherwise,
  165. dnl just prevent autoconf from molesting CFLAGS.
  166. CFLAGS=$CFLAGS
  167. AC_PROG_CC
  168. if test "x$GCC" != "xyes" ; then
  169. AC_CACHE_CHECK([whether compiler is MSVC],
  170. [je_cv_msvc],
  171. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  172. [
  173. #ifndef _MSC_VER
  174. int fail[-1];
  175. #endif
  176. ])],
  177. [je_cv_msvc=yes],
  178. [je_cv_msvc=no])])
  179. fi
  180. dnl check if a cray prgenv wrapper compiler is being used
  181. je_cv_cray_prgenv_wrapper=""
  182. if test "x${PE_ENV}" != "x" ; then
  183. case "${CC}" in
  184. CC|cc)
  185. je_cv_cray_prgenv_wrapper="yes"
  186. ;;
  187. *)
  188. ;;
  189. esac
  190. fi
  191. AC_CACHE_CHECK([whether compiler is cray],
  192. [je_cv_cray],
  193. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  194. [
  195. #ifndef _CRAYC
  196. int fail[-1];
  197. #endif
  198. ])],
  199. [je_cv_cray=yes],
  200. [je_cv_cray=no])])
  201. if test "x${je_cv_cray}" = "xyes" ; then
  202. AC_CACHE_CHECK([whether cray compiler version is 8.4],
  203. [je_cv_cray_84],
  204. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  205. [
  206. #if !(_RELEASE_MAJOR == 8 && _RELEASE_MINOR == 4)
  207. int fail[-1];
  208. #endif
  209. ])],
  210. [je_cv_cray_84=yes],
  211. [je_cv_cray_84=no])])
  212. fi
  213. if test "x$GCC" = "xyes" ; then
  214. JE_CFLAGS_ADD([-std=gnu11])
  215. if test "x$je_cv_cflags_added" = "x-std=gnu11" ; then
  216. AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
  217. else
  218. JE_CFLAGS_ADD([-std=gnu99])
  219. if test "x$je_cv_cflags_added" = "x-std=gnu99" ; then
  220. AC_DEFINE_UNQUOTED([JEMALLOC_HAS_RESTRICT])
  221. fi
  222. fi
  223. JE_CFLAGS_ADD([-Wall])
  224. JE_CFLAGS_ADD([-Wshorten-64-to-32])
  225. JE_CFLAGS_ADD([-Wsign-compare])
  226. JE_CFLAGS_ADD([-Wundef])
  227. JE_CFLAGS_ADD([-Wno-format-zero-length])
  228. JE_CFLAGS_ADD([-pipe])
  229. JE_CFLAGS_ADD([-g3])
  230. elif test "x$je_cv_msvc" = "xyes" ; then
  231. CC="$CC -nologo"
  232. JE_CFLAGS_ADD([-Zi])
  233. JE_CFLAGS_ADD([-MT])
  234. JE_CFLAGS_ADD([-W3])
  235. JE_CFLAGS_ADD([-FS])
  236. JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat)
  237. fi
  238. if test "x$je_cv_cray" = "xyes" ; then
  239. dnl cray compiler 8.4 has an inlining bug
  240. if test "x$je_cv_cray_84" = "xyes" ; then
  241. JE_CFLAGS_ADD([-hipa2])
  242. JE_CFLAGS_ADD([-hnognu])
  243. fi
  244. dnl ignore unreachable code warning
  245. JE_CFLAGS_ADD([-hnomessage=128])
  246. dnl ignore redefinition of "malloc", "free", etc warning
  247. JE_CFLAGS_ADD([-hnomessage=1357])
  248. fi
  249. AC_SUBST([CONFIGURE_CFLAGS])
  250. AC_SUBST([SPECIFIED_CFLAGS])
  251. AC_SUBST([EXTRA_CFLAGS])
  252. AC_PROG_CPP
  253. AC_ARG_ENABLE([cxx],
  254. [AS_HELP_STRING([--disable-cxx], [Disable C++ integration])],
  255. if test "x$enable_cxx" = "xno" ; then
  256. enable_cxx="0"
  257. else
  258. enable_cxx="1"
  259. fi
  260. ,
  261. enable_cxx="1"
  262. )
  263. if test "x$enable_cxx" = "x1" ; then
  264. dnl Require at least c++14, which is the first version to support sized
  265. dnl deallocation. C++ support is not compiled otherwise.
  266. m4_include([m4/ax_cxx_compile_stdcxx.m4])
  267. AX_CXX_COMPILE_STDCXX([14], [noext], [optional])
  268. if test "x${HAVE_CXX14}" = "x1" ; then
  269. JE_CXXFLAGS_ADD([-Wall])
  270. JE_CXXFLAGS_ADD([-g3])
  271. SAVED_LIBS="${LIBS}"
  272. JE_APPEND_VS(LIBS, -lstdc++)
  273. JE_COMPILABLE([libstdc++ linkage], [
  274. #include <stdlib.h>
  275. ], [[
  276. int *arr = (int *)malloc(sizeof(int) * 42);
  277. if (arr == NULL)
  278. return 1;
  279. ]], [je_cv_libstdcxx])
  280. if test "x${je_cv_libstdcxx}" = "xno" ; then
  281. LIBS="${SAVED_LIBS}"
  282. fi
  283. else
  284. enable_cxx="0"
  285. fi
  286. fi
  287. AC_SUBST([enable_cxx])
  288. AC_SUBST([CONFIGURE_CXXFLAGS])
  289. AC_SUBST([SPECIFIED_CXXFLAGS])
  290. AC_SUBST([EXTRA_CXXFLAGS])
  291. AC_C_BIGENDIAN([ac_cv_big_endian=1], [ac_cv_big_endian=0])
  292. if test "x${ac_cv_big_endian}" = "x1" ; then
  293. AC_DEFINE_UNQUOTED([JEMALLOC_BIG_ENDIAN], [ ])
  294. fi
  295. if test "x${je_cv_msvc}" = "xyes" -a "x${ac_cv_header_inttypes_h}" = "xno"; then
  296. JE_APPEND_VS(CPPFLAGS, -I${srcdir}/include/msvc_compat/C99)
  297. fi
  298. if test "x${je_cv_msvc}" = "xyes" ; then
  299. LG_SIZEOF_PTR=LG_SIZEOF_PTR_WIN
  300. AC_MSG_RESULT([Using a predefined value for sizeof(void *): 4 for 32-bit, 8 for 64-bit])
  301. else
  302. AC_CHECK_SIZEOF([void *])
  303. if test "x${ac_cv_sizeof_void_p}" = "x8" ; then
  304. LG_SIZEOF_PTR=3
  305. elif test "x${ac_cv_sizeof_void_p}" = "x4" ; then
  306. LG_SIZEOF_PTR=2
  307. else
  308. AC_MSG_ERROR([Unsupported pointer size: ${ac_cv_sizeof_void_p}])
  309. fi
  310. fi
  311. AC_DEFINE_UNQUOTED([LG_SIZEOF_PTR], [$LG_SIZEOF_PTR])
  312. AC_CHECK_SIZEOF([int])
  313. if test "x${ac_cv_sizeof_int}" = "x8" ; then
  314. LG_SIZEOF_INT=3
  315. elif test "x${ac_cv_sizeof_int}" = "x4" ; then
  316. LG_SIZEOF_INT=2
  317. else
  318. AC_MSG_ERROR([Unsupported int size: ${ac_cv_sizeof_int}])
  319. fi
  320. AC_DEFINE_UNQUOTED([LG_SIZEOF_INT], [$LG_SIZEOF_INT])
  321. AC_CHECK_SIZEOF([long])
  322. if test "x${ac_cv_sizeof_long}" = "x8" ; then
  323. LG_SIZEOF_LONG=3
  324. elif test "x${ac_cv_sizeof_long}" = "x4" ; then
  325. LG_SIZEOF_LONG=2
  326. else
  327. AC_MSG_ERROR([Unsupported long size: ${ac_cv_sizeof_long}])
  328. fi
  329. AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG], [$LG_SIZEOF_LONG])
  330. AC_CHECK_SIZEOF([long long])
  331. if test "x${ac_cv_sizeof_long_long}" = "x8" ; then
  332. LG_SIZEOF_LONG_LONG=3
  333. elif test "x${ac_cv_sizeof_long_long}" = "x4" ; then
  334. LG_SIZEOF_LONG_LONG=2
  335. else
  336. AC_MSG_ERROR([Unsupported long long size: ${ac_cv_sizeof_long_long}])
  337. fi
  338. AC_DEFINE_UNQUOTED([LG_SIZEOF_LONG_LONG], [$LG_SIZEOF_LONG_LONG])
  339. AC_CHECK_SIZEOF([intmax_t])
  340. if test "x${ac_cv_sizeof_intmax_t}" = "x16" ; then
  341. LG_SIZEOF_INTMAX_T=4
  342. elif test "x${ac_cv_sizeof_intmax_t}" = "x8" ; then
  343. LG_SIZEOF_INTMAX_T=3
  344. elif test "x${ac_cv_sizeof_intmax_t}" = "x4" ; then
  345. LG_SIZEOF_INTMAX_T=2
  346. else
  347. AC_MSG_ERROR([Unsupported intmax_t size: ${ac_cv_sizeof_intmax_t}])
  348. fi
  349. AC_DEFINE_UNQUOTED([LG_SIZEOF_INTMAX_T], [$LG_SIZEOF_INTMAX_T])
  350. AC_CANONICAL_HOST
  351. dnl CPU-specific settings.
  352. CPU_SPINWAIT=""
  353. case "${host_cpu}" in
  354. i686|x86_64)
  355. HAVE_CPU_SPINWAIT=1
  356. if test "x${je_cv_msvc}" = "xyes" ; then
  357. AC_CACHE_VAL([je_cv_pause_msvc],
  358. [JE_COMPILABLE([pause instruction MSVC], [],
  359. [[_mm_pause(); return 0;]],
  360. [je_cv_pause_msvc])])
  361. if test "x${je_cv_pause_msvc}" = "xyes" ; then
  362. CPU_SPINWAIT='_mm_pause()'
  363. fi
  364. else
  365. AC_CACHE_VAL([je_cv_pause],
  366. [JE_COMPILABLE([pause instruction], [],
  367. [[__asm__ volatile("pause"); return 0;]],
  368. [je_cv_pause])])
  369. if test "x${je_cv_pause}" = "xyes" ; then
  370. CPU_SPINWAIT='__asm__ volatile("pause")'
  371. fi
  372. fi
  373. ;;
  374. *)
  375. HAVE_CPU_SPINWAIT=0
  376. ;;
  377. esac
  378. AC_DEFINE_UNQUOTED([HAVE_CPU_SPINWAIT], [$HAVE_CPU_SPINWAIT])
  379. AC_DEFINE_UNQUOTED([CPU_SPINWAIT], [$CPU_SPINWAIT])
  380. AC_ARG_WITH([lg_vaddr],
  381. [AS_HELP_STRING([--with-lg-vaddr=<lg-vaddr>], [Number of significant virtual address bits])],
  382. [LG_VADDR="$with_lg_vaddr"], [LG_VADDR="detect"])
  383. case "${host_cpu}" in
  384. aarch64)
  385. if test "x$LG_VADDR" = "xdetect"; then
  386. AC_MSG_CHECKING([number of significant virtual address bits])
  387. if test "x${LG_SIZEOF_PTR}" = "x2" ; then
  388. #aarch64 ILP32
  389. LG_VADDR=32
  390. else
  391. #aarch64 LP64
  392. LG_VADDR=48
  393. fi
  394. AC_MSG_RESULT([$LG_VADDR])
  395. fi
  396. ;;
  397. x86_64)
  398. if test "x$LG_VADDR" = "xdetect"; then
  399. AC_CACHE_CHECK([number of significant virtual address bits],
  400. [je_cv_lg_vaddr],
  401. AC_RUN_IFELSE([AC_LANG_PROGRAM(
  402. [[
  403. #include <stdio.h>
  404. #ifdef _WIN32
  405. #include <limits.h>
  406. #include <intrin.h>
  407. typedef unsigned __int32 uint32_t;
  408. #else
  409. #include <stdint.h>
  410. #endif
  411. ]], [[
  412. uint32_t r[[4]];
  413. uint32_t eax_in = 0x80000008U;
  414. #ifdef _WIN32
  415. __cpuid((int *)r, (int)eax_in);
  416. #else
  417. asm volatile ("cpuid"
  418. : "=a" (r[[0]]), "=b" (r[[1]]), "=c" (r[[2]]), "=d" (r[[3]])
  419. : "a" (eax_in), "c" (0)
  420. );
  421. #endif
  422. uint32_t eax_out = r[[0]];
  423. uint32_t vaddr = ((eax_out & 0x0000ff00U) >> 8);
  424. FILE *f = fopen("conftest.out", "w");
  425. if (f == NULL) {
  426. return 1;
  427. }
  428. if (vaddr > (sizeof(void *) << 3)) {
  429. vaddr = sizeof(void *) << 3;
  430. }
  431. fprintf(f, "%u", vaddr);
  432. fclose(f);
  433. return 0;
  434. ]])],
  435. [je_cv_lg_vaddr=`cat conftest.out`],
  436. [je_cv_lg_vaddr=error],
  437. [je_cv_lg_vaddr=57]))
  438. if test "x${je_cv_lg_vaddr}" != "x" ; then
  439. LG_VADDR="${je_cv_lg_vaddr}"
  440. fi
  441. if test "x${LG_VADDR}" != "xerror" ; then
  442. AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
  443. else
  444. AC_MSG_ERROR([cannot determine number of significant virtual address bits])
  445. fi
  446. fi
  447. ;;
  448. *)
  449. if test "x$LG_VADDR" = "xdetect"; then
  450. AC_MSG_CHECKING([number of significant virtual address bits])
  451. if test "x${LG_SIZEOF_PTR}" = "x3" ; then
  452. LG_VADDR=64
  453. elif test "x${LG_SIZEOF_PTR}" = "x2" ; then
  454. LG_VADDR=32
  455. elif test "x${LG_SIZEOF_PTR}" = "xLG_SIZEOF_PTR_WIN" ; then
  456. LG_VADDR="(1U << (LG_SIZEOF_PTR_WIN+3))"
  457. else
  458. AC_MSG_ERROR([Unsupported lg(pointer size): ${LG_SIZEOF_PTR}])
  459. fi
  460. AC_MSG_RESULT([$LG_VADDR])
  461. fi
  462. ;;
  463. esac
  464. AC_DEFINE_UNQUOTED([LG_VADDR], [$LG_VADDR])
  465. LD_PRELOAD_VAR="LD_PRELOAD"
  466. so="so"
  467. importlib="${so}"
  468. o="$ac_objext"
  469. a="a"
  470. exe="$ac_exeext"
  471. libprefix="lib"
  472. link_whole_archive="0"
  473. DSO_LDFLAGS='-shared -Wl,-soname,$(@F)'
  474. RPATH='-Wl,-rpath,$(1)'
  475. SOREV="${so}.${rev}"
  476. PIC_CFLAGS='-fPIC -DPIC'
  477. CTARGET='-o $@'
  478. LDTARGET='-o $@'
  479. TEST_LD_MODE=
  480. EXTRA_LDFLAGS=
  481. ARFLAGS='crus'
  482. AROUT=' $@'
  483. CC_MM=1
  484. if test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
  485. TEST_LD_MODE='-dynamic'
  486. fi
  487. if test "x${je_cv_cray}" = "xyes" ; then
  488. CC_MM=
  489. fi
  490. AN_MAKEVAR([AR], [AC_PROG_AR])
  491. AN_PROGRAM([ar], [AC_PROG_AR])
  492. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
  493. AC_PROG_AR
  494. AN_MAKEVAR([NM], [AC_PROG_NM])
  495. AN_PROGRAM([nm], [AC_PROG_NM])
  496. AC_DEFUN([AC_PROG_NM], [AC_CHECK_TOOL(NM, nm, :)])
  497. AC_PROG_NM
  498. AC_PROG_AWK
  499. dnl Platform-specific settings. abi and RPATH can probably be determined
  500. dnl programmatically, but doing so is error-prone, which makes it generally
  501. dnl not worth the trouble.
  502. dnl
  503. dnl Define cpp macros in CPPFLAGS, rather than doing AC_DEFINE(macro), since the
  504. dnl definitions need to be seen before any headers are included, which is a pain
  505. dnl to make happen otherwise.
  506. default_retain="0"
  507. maps_coalesce="1"
  508. DUMP_SYMS="${NM} -a"
  509. SYM_PREFIX=""
  510. case "${host}" in
  511. *-*-darwin* | *-*-ios*)
  512. abi="macho"
  513. RPATH=""
  514. LD_PRELOAD_VAR="DYLD_INSERT_LIBRARIES"
  515. so="dylib"
  516. importlib="${so}"
  517. force_tls="0"
  518. DSO_LDFLAGS='-shared -Wl,-install_name,$(LIBDIR)/$(@F)'
  519. SOREV="${rev}.${so}"
  520. sbrk_deprecated="1"
  521. SYM_PREFIX="_"
  522. ;;
  523. *-*-freebsd*)
  524. abi="elf"
  525. AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
  526. force_lazy_lock="1"
  527. ;;
  528. *-*-dragonfly*)
  529. abi="elf"
  530. ;;
  531. *-*-openbsd*)
  532. abi="elf"
  533. force_tls="0"
  534. ;;
  535. *-*-bitrig*)
  536. abi="elf"
  537. ;;
  538. *-*-linux-android)
  539. dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
  540. JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
  541. abi="elf"
  542. AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
  543. AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
  544. AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
  545. AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
  546. AC_DEFINE([JEMALLOC_C11_ATOMICS])
  547. force_tls="0"
  548. if test "${LG_SIZEOF_PTR}" = "3"; then
  549. default_retain="1"
  550. fi
  551. ;;
  552. *-*-linux*)
  553. dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
  554. JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
  555. abi="elf"
  556. AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED_ZEROS], [ ])
  557. AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
  558. AC_DEFINE([JEMALLOC_PROC_SYS_VM_OVERCOMMIT_MEMORY], [ ])
  559. AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
  560. AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
  561. if test "${LG_SIZEOF_PTR}" = "3"; then
  562. default_retain="1"
  563. fi
  564. ;;
  565. *-*-kfreebsd*)
  566. dnl syscall(2) and secure_getenv(3) are exposed by _GNU_SOURCE.
  567. JE_APPEND_VS(CPPFLAGS, -D_GNU_SOURCE)
  568. abi="elf"
  569. AC_DEFINE([JEMALLOC_HAS_ALLOCA_H])
  570. AC_DEFINE([JEMALLOC_SYSCTL_VM_OVERCOMMIT], [ ])
  571. AC_DEFINE([JEMALLOC_THREADED_INIT], [ ])
  572. AC_DEFINE([JEMALLOC_USE_CXX_THROW], [ ])
  573. ;;
  574. *-*-netbsd*)
  575. AC_MSG_CHECKING([ABI])
  576. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  577. [[#ifdef __ELF__
  578. /* ELF */
  579. #else
  580. #error aout
  581. #endif
  582. ]])],
  583. [abi="elf"],
  584. [abi="aout"])
  585. AC_MSG_RESULT([$abi])
  586. ;;
  587. *-*-solaris2*)
  588. abi="elf"
  589. RPATH='-Wl,-R,$(1)'
  590. dnl Solaris needs this for sigwait().
  591. JE_APPEND_VS(CPPFLAGS, -D_POSIX_PTHREAD_SEMANTICS)
  592. JE_APPEND_VS(LIBS, -lposix4 -lsocket -lnsl)
  593. ;;
  594. *-ibm-aix*)
  595. if test "${LG_SIZEOF_PTR}" = "3"; then
  596. dnl 64bit AIX
  597. LD_PRELOAD_VAR="LDR_PRELOAD64"
  598. else
  599. dnl 32bit AIX
  600. LD_PRELOAD_VAR="LDR_PRELOAD"
  601. fi
  602. abi="xcoff"
  603. ;;
  604. *-*-mingw* | *-*-cygwin*)
  605. abi="pecoff"
  606. force_tls="0"
  607. maps_coalesce="0"
  608. RPATH=""
  609. so="dll"
  610. if test "x$je_cv_msvc" = "xyes" ; then
  611. importlib="lib"
  612. DSO_LDFLAGS="-LD"
  613. EXTRA_LDFLAGS="-link -DEBUG"
  614. CTARGET='-Fo$@'
  615. LDTARGET='-Fe$@'
  616. AR='lib'
  617. ARFLAGS='-nologo -out:'
  618. AROUT='$@'
  619. CC_MM=
  620. else
  621. importlib="${so}"
  622. DSO_LDFLAGS="-shared"
  623. link_whole_archive="1"
  624. fi
  625. case "${host}" in
  626. *-*-cygwin*)
  627. DUMP_SYMS="dumpbin /SYMBOLS"
  628. ;;
  629. *)
  630. ;;
  631. esac
  632. a="lib"
  633. libprefix=""
  634. SOREV="${so}"
  635. PIC_CFLAGS=""
  636. ;;
  637. *)
  638. AC_MSG_RESULT([Unsupported operating system: ${host}])
  639. abi="elf"
  640. ;;
  641. esac
  642. JEMALLOC_USABLE_SIZE_CONST=const
  643. AC_CHECK_HEADERS([malloc.h], [
  644. AC_MSG_CHECKING([whether malloc_usable_size definition can use const argument])
  645. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  646. [#include <malloc.h>
  647. #include <stddef.h>
  648. size_t malloc_usable_size(const void *ptr);
  649. ],
  650. [])],[
  651. AC_MSG_RESULT([yes])
  652. ],[
  653. JEMALLOC_USABLE_SIZE_CONST=
  654. AC_MSG_RESULT([no])
  655. ])
  656. ])
  657. AC_DEFINE_UNQUOTED([JEMALLOC_USABLE_SIZE_CONST], [$JEMALLOC_USABLE_SIZE_CONST])
  658. AC_SUBST([abi])
  659. AC_SUBST([RPATH])
  660. AC_SUBST([LD_PRELOAD_VAR])
  661. AC_SUBST([so])
  662. AC_SUBST([importlib])
  663. AC_SUBST([o])
  664. AC_SUBST([a])
  665. AC_SUBST([exe])
  666. AC_SUBST([libprefix])
  667. AC_SUBST([link_whole_archive])
  668. AC_SUBST([DSO_LDFLAGS])
  669. AC_SUBST([EXTRA_LDFLAGS])
  670. AC_SUBST([SOREV])
  671. AC_SUBST([PIC_CFLAGS])
  672. AC_SUBST([CTARGET])
  673. AC_SUBST([LDTARGET])
  674. AC_SUBST([TEST_LD_MODE])
  675. AC_SUBST([MKLIB])
  676. AC_SUBST([ARFLAGS])
  677. AC_SUBST([AROUT])
  678. AC_SUBST([DUMP_SYMS])
  679. AC_SUBST([CC_MM])
  680. dnl Determine whether libm must be linked to use e.g. log(3).
  681. AC_SEARCH_LIBS([log], [m], , [AC_MSG_ERROR([Missing math functions])])
  682. if test "x$ac_cv_search_log" != "xnone required" ; then
  683. LM="$ac_cv_search_log"
  684. else
  685. LM=
  686. fi
  687. AC_SUBST(LM)
  688. JE_COMPILABLE([__attribute__ syntax],
  689. [static __attribute__((unused)) void foo(void){}],
  690. [],
  691. [je_cv_attribute])
  692. if test "x${je_cv_attribute}" = "xyes" ; then
  693. AC_DEFINE([JEMALLOC_HAVE_ATTR], [ ])
  694. if test "x${GCC}" = "xyes" -a "x${abi}" = "xelf"; then
  695. JE_CFLAGS_ADD([-fvisibility=hidden])
  696. JE_CXXFLAGS_ADD([-fvisibility=hidden])
  697. fi
  698. fi
  699. dnl Check for tls_model attribute support (clang 3.0 still lacks support).
  700. JE_CFLAGS_SAVE()
  701. JE_CFLAGS_ADD([-Werror])
  702. JE_CFLAGS_ADD([-herror_on_warning])
  703. JE_COMPILABLE([tls_model attribute], [],
  704. [static __thread int
  705. __attribute__((tls_model("initial-exec"), unused)) foo;
  706. foo = 0;],
  707. [je_cv_tls_model])
  708. JE_CFLAGS_RESTORE()
  709. dnl (Setting of JEMALLOC_TLS_MODEL is done later, after we've checked for
  710. dnl --disable-initial-exec-tls)
  711. dnl Check for alloc_size attribute support.
  712. JE_CFLAGS_SAVE()
  713. JE_CFLAGS_ADD([-Werror])
  714. JE_CFLAGS_ADD([-herror_on_warning])
  715. JE_COMPILABLE([alloc_size attribute], [#include <stdlib.h>],
  716. [void *foo(size_t size) __attribute__((alloc_size(1)));],
  717. [je_cv_alloc_size])
  718. JE_CFLAGS_RESTORE()
  719. if test "x${je_cv_alloc_size}" = "xyes" ; then
  720. AC_DEFINE([JEMALLOC_HAVE_ATTR_ALLOC_SIZE], [ ])
  721. fi
  722. dnl Check for format(gnu_printf, ...) attribute support.
  723. JE_CFLAGS_SAVE()
  724. JE_CFLAGS_ADD([-Werror])
  725. JE_CFLAGS_ADD([-herror_on_warning])
  726. JE_COMPILABLE([format(gnu_printf, ...) attribute], [#include <stdlib.h>],
  727. [void *foo(const char *format, ...) __attribute__((format(gnu_printf, 1, 2)));],
  728. [je_cv_format_gnu_printf])
  729. JE_CFLAGS_RESTORE()
  730. if test "x${je_cv_format_gnu_printf}" = "xyes" ; then
  731. AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_GNU_PRINTF], [ ])
  732. fi
  733. dnl Check for format(printf, ...) attribute support.
  734. JE_CFLAGS_SAVE()
  735. JE_CFLAGS_ADD([-Werror])
  736. JE_CFLAGS_ADD([-herror_on_warning])
  737. JE_COMPILABLE([format(printf, ...) attribute], [#include <stdlib.h>],
  738. [void *foo(const char *format, ...) __attribute__((format(printf, 1, 2)));],
  739. [je_cv_format_printf])
  740. JE_CFLAGS_RESTORE()
  741. if test "x${je_cv_format_printf}" = "xyes" ; then
  742. AC_DEFINE([JEMALLOC_HAVE_ATTR_FORMAT_PRINTF], [ ])
  743. fi
  744. dnl Support optional additions to rpath.
  745. AC_ARG_WITH([rpath],
  746. [AS_HELP_STRING([--with-rpath=<rpath>], [Colon-separated rpath (ELF systems only)])],
  747. if test "x$with_rpath" = "xno" ; then
  748. RPATH_EXTRA=
  749. else
  750. RPATH_EXTRA="`echo $with_rpath | tr \":\" \" \"`"
  751. fi,
  752. RPATH_EXTRA=
  753. )
  754. AC_SUBST([RPATH_EXTRA])
  755. dnl Disable rules that do automatic regeneration of configure output by default.
  756. AC_ARG_ENABLE([autogen],
  757. [AS_HELP_STRING([--enable-autogen], [Automatically regenerate configure output])],
  758. if test "x$enable_autogen" = "xno" ; then
  759. enable_autogen="0"
  760. else
  761. enable_autogen="1"
  762. fi
  763. ,
  764. enable_autogen="0"
  765. )
  766. AC_SUBST([enable_autogen])
  767. AC_PROG_INSTALL
  768. AC_PROG_RANLIB
  769. AC_PATH_PROG([LD], [ld], [false], [$PATH])
  770. AC_PATH_PROG([AUTOCONF], [autoconf], [false], [$PATH])
  771. dnl Perform no name mangling by default.
  772. AC_ARG_WITH([mangling],
  773. [AS_HELP_STRING([--with-mangling=<map>], [Mangle symbols in <map>])],
  774. [mangling_map="$with_mangling"], [mangling_map=""])
  775. dnl Do not prefix public APIs by default.
  776. AC_ARG_WITH([jemalloc_prefix],
  777. [AS_HELP_STRING([--with-jemalloc-prefix=<prefix>], [Prefix to prepend to all public APIs])],
  778. [JEMALLOC_PREFIX="$with_jemalloc_prefix"],
  779. [if test "x$abi" != "xmacho" -a "x$abi" != "xpecoff"; then
  780. JEMALLOC_PREFIX=""
  781. else
  782. JEMALLOC_PREFIX="je_"
  783. fi]
  784. )
  785. if test "x$JEMALLOC_PREFIX" = "x" ; then
  786. AC_DEFINE([JEMALLOC_IS_MALLOC])
  787. else
  788. JEMALLOC_CPREFIX=`echo ${JEMALLOC_PREFIX} | tr "a-z" "A-Z"`
  789. AC_DEFINE_UNQUOTED([JEMALLOC_PREFIX], ["$JEMALLOC_PREFIX"])
  790. AC_DEFINE_UNQUOTED([JEMALLOC_CPREFIX], ["$JEMALLOC_CPREFIX"])
  791. fi
  792. AC_SUBST([JEMALLOC_PREFIX])
  793. AC_SUBST([JEMALLOC_CPREFIX])
  794. AC_ARG_WITH([export],
  795. [AS_HELP_STRING([--without-export], [disable exporting jemalloc public APIs])],
  796. [if test "x$with_export" = "xno"; then
  797. AC_DEFINE([JEMALLOC_EXPORT],[])
  798. fi]
  799. )
  800. public_syms="aligned_alloc calloc dallocx free mallctl mallctlbymib mallctlnametomib malloc malloc_conf malloc_message malloc_stats_print malloc_usable_size mallocx nallocx posix_memalign rallocx realloc sallocx sdallocx xallocx"
  801. dnl Check for additional platform-specific public API functions.
  802. AC_CHECK_FUNC([memalign],
  803. [AC_DEFINE([JEMALLOC_OVERRIDE_MEMALIGN], [ ])
  804. public_syms="${public_syms} memalign"])
  805. AC_CHECK_FUNC([valloc],
  806. [AC_DEFINE([JEMALLOC_OVERRIDE_VALLOC], [ ])
  807. public_syms="${public_syms} valloc"])
  808. dnl Check for allocator-related functions that should be wrapped.
  809. wrap_syms=
  810. if test "x${JEMALLOC_PREFIX}" = "x" ; then
  811. AC_CHECK_FUNC([__libc_calloc],
  812. [AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_CALLOC], [ ])
  813. wrap_syms="${wrap_syms} __libc_calloc"])
  814. AC_CHECK_FUNC([__libc_free],
  815. [AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_FREE], [ ])
  816. wrap_syms="${wrap_syms} __libc_free"])
  817. AC_CHECK_FUNC([__libc_malloc],
  818. [AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MALLOC], [ ])
  819. wrap_syms="${wrap_syms} __libc_malloc"])
  820. AC_CHECK_FUNC([__libc_memalign],
  821. [AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_MEMALIGN], [ ])
  822. wrap_syms="${wrap_syms} __libc_memalign"])
  823. AC_CHECK_FUNC([__libc_realloc],
  824. [AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_REALLOC], [ ])
  825. wrap_syms="${wrap_syms} __libc_realloc"])
  826. AC_CHECK_FUNC([__libc_valloc],
  827. [AC_DEFINE([JEMALLOC_OVERRIDE___LIBC_VALLOC], [ ])
  828. wrap_syms="${wrap_syms} __libc_valloc"])
  829. AC_CHECK_FUNC([__posix_memalign],
  830. [AC_DEFINE([JEMALLOC_OVERRIDE___POSIX_MEMALIGN], [ ])
  831. wrap_syms="${wrap_syms} __posix_memalign"])
  832. fi
  833. case "${host}" in
  834. *-*-mingw* | *-*-cygwin*)
  835. wrap_syms="${wrap_syms} tls_callback"
  836. ;;
  837. *)
  838. ;;
  839. esac
  840. dnl Mangle library-private APIs.
  841. AC_ARG_WITH([private_namespace],
  842. [AS_HELP_STRING([--with-private-namespace=<prefix>], [Prefix to prepend to all library-private APIs])],
  843. [JEMALLOC_PRIVATE_NAMESPACE="${with_private_namespace}je_"],
  844. [JEMALLOC_PRIVATE_NAMESPACE="je_"]
  845. )
  846. AC_DEFINE_UNQUOTED([JEMALLOC_PRIVATE_NAMESPACE], [$JEMALLOC_PRIVATE_NAMESPACE])
  847. private_namespace="$JEMALLOC_PRIVATE_NAMESPACE"
  848. AC_SUBST([private_namespace])
  849. dnl Do not add suffix to installed files by default.
  850. AC_ARG_WITH([install_suffix],
  851. [AS_HELP_STRING([--with-install-suffix=<suffix>], [Suffix to append to all installed files])],
  852. [INSTALL_SUFFIX="$with_install_suffix"],
  853. [INSTALL_SUFFIX=]
  854. )
  855. install_suffix="$INSTALL_SUFFIX"
  856. AC_SUBST([install_suffix])
  857. dnl Specify default malloc_conf.
  858. AC_ARG_WITH([malloc_conf],
  859. [AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
  860. [JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
  861. [JEMALLOC_CONFIG_MALLOC_CONF=""]
  862. )
  863. config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
  864. AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
  865. dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
  866. dnl jemalloc_protos_jet.h easy.
  867. je_="je_"
  868. AC_SUBST([je_])
  869. cfgoutputs_in="Makefile.in"
  870. cfgoutputs_in="${cfgoutputs_in} jemalloc.pc.in"
  871. cfgoutputs_in="${cfgoutputs_in} doc/html.xsl.in"
  872. cfgoutputs_in="${cfgoutputs_in} doc/manpages.xsl.in"
  873. cfgoutputs_in="${cfgoutputs_in} doc/jemalloc.xml.in"
  874. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_macros.h.in"
  875. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_protos.h.in"
  876. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/jemalloc_typedefs.h.in"
  877. cfgoutputs_in="${cfgoutputs_in} include/jemalloc/internal/jemalloc_preamble.h.in"
  878. cfgoutputs_in="${cfgoutputs_in} test/test.sh.in"
  879. cfgoutputs_in="${cfgoutputs_in} test/include/test/jemalloc_test.h.in"
  880. cfgoutputs_out="Makefile"
  881. cfgoutputs_out="${cfgoutputs_out} jemalloc.pc"
  882. cfgoutputs_out="${cfgoutputs_out} doc/html.xsl"
  883. cfgoutputs_out="${cfgoutputs_out} doc/manpages.xsl"
  884. cfgoutputs_out="${cfgoutputs_out} doc/jemalloc.xml"
  885. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_macros.h"
  886. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_protos.h"
  887. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/jemalloc_typedefs.h"
  888. cfgoutputs_out="${cfgoutputs_out} include/jemalloc/internal/jemalloc_preamble.h"
  889. cfgoutputs_out="${cfgoutputs_out} test/test.sh"
  890. cfgoutputs_out="${cfgoutputs_out} test/include/test/jemalloc_test.h"
  891. cfgoutputs_tup="Makefile"
  892. cfgoutputs_tup="${cfgoutputs_tup} jemalloc.pc:jemalloc.pc.in"
  893. cfgoutputs_tup="${cfgoutputs_tup} doc/html.xsl:doc/html.xsl.in"
  894. cfgoutputs_tup="${cfgoutputs_tup} doc/manpages.xsl:doc/manpages.xsl.in"
  895. cfgoutputs_tup="${cfgoutputs_tup} doc/jemalloc.xml:doc/jemalloc.xml.in"
  896. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_macros.h:include/jemalloc/jemalloc_macros.h.in"
  897. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_protos.h:include/jemalloc/jemalloc_protos.h.in"
  898. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/jemalloc_typedefs.h:include/jemalloc/jemalloc_typedefs.h.in"
  899. cfgoutputs_tup="${cfgoutputs_tup} include/jemalloc/internal/jemalloc_preamble.h"
  900. cfgoutputs_tup="${cfgoutputs_tup} test/test.sh:test/test.sh.in"
  901. cfgoutputs_tup="${cfgoutputs_tup} test/include/test/jemalloc_test.h:test/include/test/jemalloc_test.h.in"
  902. cfghdrs_in="include/jemalloc/jemalloc_defs.h.in"
  903. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/jemalloc_internal_defs.h.in"
  904. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_symbols.sh"
  905. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/private_namespace.sh"
  906. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_namespace.sh"
  907. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/public_unnamespace.sh"
  908. cfghdrs_in="${cfghdrs_in} include/jemalloc/internal/size_classes.sh"
  909. cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_rename.sh"
  910. cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc_mangle.sh"
  911. cfghdrs_in="${cfghdrs_in} include/jemalloc/jemalloc.sh"
  912. cfghdrs_in="${cfghdrs_in} test/include/test/jemalloc_test_defs.h.in"
  913. cfghdrs_out="include/jemalloc/jemalloc_defs.h"
  914. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc${install_suffix}.h"
  915. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols.awk"
  916. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/private_symbols_jet.awk"
  917. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_symbols.txt"
  918. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_namespace.h"
  919. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/public_unnamespace.h"
  920. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/size_classes.h"
  921. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_protos_jet.h"
  922. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_rename.h"
  923. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle.h"
  924. cfghdrs_out="${cfghdrs_out} include/jemalloc/jemalloc_mangle_jet.h"
  925. cfghdrs_out="${cfghdrs_out} include/jemalloc/internal/jemalloc_internal_defs.h"
  926. cfghdrs_out="${cfghdrs_out} test/include/test/jemalloc_test_defs.h"
  927. cfghdrs_tup="include/jemalloc/jemalloc_defs.h:include/jemalloc/jemalloc_defs.h.in"
  928. cfghdrs_tup="${cfghdrs_tup} include/jemalloc/internal/jemalloc_internal_defs.h:include/jemalloc/internal/jemalloc_internal_defs.h.in"
  929. cfghdrs_tup="${cfghdrs_tup} test/include/test/jemalloc_test_defs.h:test/include/test/jemalloc_test_defs.h.in"
  930. dnl Do not compile with debugging by default.
  931. AC_ARG_ENABLE([debug],
  932. [AS_HELP_STRING([--enable-debug],
  933. [Build debugging code])],
  934. [if test "x$enable_debug" = "xno" ; then
  935. enable_debug="0"
  936. else
  937. enable_debug="1"
  938. fi
  939. ],
  940. [enable_debug="0"]
  941. )
  942. if test "x$enable_debug" = "x1" ; then
  943. AC_DEFINE([JEMALLOC_DEBUG], [ ])
  944. fi
  945. if test "x$enable_debug" = "x1" ; then
  946. AC_DEFINE([JEMALLOC_DEBUG], [ ])
  947. fi
  948. AC_SUBST([enable_debug])
  949. dnl Only optimize if not debugging.
  950. if test "x$enable_debug" = "x0" ; then
  951. if test "x$GCC" = "xyes" ; then
  952. JE_CFLAGS_ADD([-O3])
  953. JE_CXXFLAGS_ADD([-O3])
  954. JE_CFLAGS_ADD([-funroll-loops])
  955. elif test "x$je_cv_msvc" = "xyes" ; then
  956. JE_CFLAGS_ADD([-O2])
  957. JE_CXXFLAGS_ADD([-O2])
  958. else
  959. JE_CFLAGS_ADD([-O])
  960. JE_CXXFLAGS_ADD([-O])
  961. fi
  962. fi
  963. dnl Enable statistics calculation by default.
  964. AC_ARG_ENABLE([stats],
  965. [AS_HELP_STRING([--disable-stats],
  966. [Disable statistics calculation/reporting])],
  967. [if test "x$enable_stats" = "xno" ; then
  968. enable_stats="0"
  969. else
  970. enable_stats="1"
  971. fi
  972. ],
  973. [enable_stats="1"]
  974. )
  975. if test "x$enable_stats" = "x1" ; then
  976. AC_DEFINE([JEMALLOC_STATS], [ ])
  977. fi
  978. AC_SUBST([enable_stats])
  979. dnl Do not enable profiling by default.
  980. AC_ARG_ENABLE([prof],
  981. [AS_HELP_STRING([--enable-prof], [Enable allocation profiling])],
  982. [if test "x$enable_prof" = "xno" ; then
  983. enable_prof="0"
  984. else
  985. enable_prof="1"
  986. fi
  987. ],
  988. [enable_prof="0"]
  989. )
  990. if test "x$enable_prof" = "x1" ; then
  991. backtrace_method=""
  992. else
  993. backtrace_method="N/A"
  994. fi
  995. AC_ARG_ENABLE([prof-libunwind],
  996. [AS_HELP_STRING([--enable-prof-libunwind], [Use libunwind for backtracing])],
  997. [if test "x$enable_prof_libunwind" = "xno" ; then
  998. enable_prof_libunwind="0"
  999. else
  1000. enable_prof_libunwind="1"
  1001. fi
  1002. ],
  1003. [enable_prof_libunwind="0"]
  1004. )
  1005. AC_ARG_WITH([static_libunwind],
  1006. [AS_HELP_STRING([--with-static-libunwind=<libunwind.a>],
  1007. [Path to static libunwind library; use rather than dynamically linking])],
  1008. if test "x$with_static_libunwind" = "xno" ; then
  1009. LUNWIND="-lunwind"
  1010. else
  1011. if test ! -f "$with_static_libunwind" ; then
  1012. AC_MSG_ERROR([Static libunwind not found: $with_static_libunwind])
  1013. fi
  1014. LUNWIND="$with_static_libunwind"
  1015. fi,
  1016. LUNWIND="-lunwind"
  1017. )
  1018. if test "x$backtrace_method" = "x" -a "x$enable_prof_libunwind" = "x1" ; then
  1019. AC_CHECK_HEADERS([libunwind.h], , [enable_prof_libunwind="0"])
  1020. if test "x$LUNWIND" = "x-lunwind" ; then
  1021. AC_CHECK_LIB([unwind], [unw_backtrace], [JE_APPEND_VS(LIBS, $LUNWIND)],
  1022. [enable_prof_libunwind="0"])
  1023. else
  1024. JE_APPEND_VS(LIBS, $LUNWIND)
  1025. fi
  1026. if test "x${enable_prof_libunwind}" = "x1" ; then
  1027. backtrace_method="libunwind"
  1028. AC_DEFINE([JEMALLOC_PROF_LIBUNWIND], [ ])
  1029. fi
  1030. fi
  1031. AC_ARG_ENABLE([prof-libgcc],
  1032. [AS_HELP_STRING([--disable-prof-libgcc],
  1033. [Do not use libgcc for backtracing])],
  1034. [if test "x$enable_prof_libgcc" = "xno" ; then
  1035. enable_prof_libgcc="0"
  1036. else
  1037. enable_prof_libgcc="1"
  1038. fi
  1039. ],
  1040. [enable_prof_libgcc="1"]
  1041. )
  1042. if test "x$backtrace_method" = "x" -a "x$enable_prof_libgcc" = "x1" \
  1043. -a "x$GCC" = "xyes" ; then
  1044. AC_CHECK_HEADERS([unwind.h], , [enable_prof_libgcc="0"])
  1045. if test "x${enable_prof_libgcc}" = "x1" ; then
  1046. AC_CHECK_LIB([gcc], [_Unwind_Backtrace], [JE_APPEND_VS(LIBS, -lgcc)], [enable_prof_libgcc="0"])
  1047. fi
  1048. if test "x${enable_prof_libgcc}" = "x1" ; then
  1049. backtrace_method="libgcc"
  1050. AC_DEFINE([JEMALLOC_PROF_LIBGCC], [ ])
  1051. fi
  1052. else
  1053. enable_prof_libgcc="0"
  1054. fi
  1055. AC_ARG_ENABLE([prof-gcc],
  1056. [AS_HELP_STRING([--disable-prof-gcc],
  1057. [Do not use gcc intrinsics for backtracing])],
  1058. [if test "x$enable_prof_gcc" = "xno" ; then
  1059. enable_prof_gcc="0"
  1060. else
  1061. enable_prof_gcc="1"
  1062. fi
  1063. ],
  1064. [enable_prof_gcc="1"]
  1065. )
  1066. if test "x$backtrace_method" = "x" -a "x$enable_prof_gcc" = "x1" \
  1067. -a "x$GCC" = "xyes" ; then
  1068. JE_CFLAGS_ADD([-fno-omit-frame-pointer])
  1069. backtrace_method="gcc intrinsics"
  1070. AC_DEFINE([JEMALLOC_PROF_GCC], [ ])
  1071. else
  1072. enable_prof_gcc="0"
  1073. fi
  1074. if test "x$backtrace_method" = "x" ; then
  1075. backtrace_method="none (disabling profiling)"
  1076. enable_prof="0"
  1077. fi
  1078. AC_MSG_CHECKING([configured backtracing method])
  1079. AC_MSG_RESULT([$backtrace_method])
  1080. if test "x$enable_prof" = "x1" ; then
  1081. dnl Heap profiling uses the log(3) function.
  1082. JE_APPEND_VS(LIBS, $LM)
  1083. AC_DEFINE([JEMALLOC_PROF], [ ])
  1084. fi
  1085. AC_SUBST([enable_prof])
  1086. dnl Indicate whether adjacent virtual memory mappings automatically coalesce
  1087. dnl (and fragment on demand).
  1088. if test "x${maps_coalesce}" = "x1" ; then
  1089. AC_DEFINE([JEMALLOC_MAPS_COALESCE], [ ])
  1090. fi
  1091. dnl Indicate whether to retain memory (rather than using munmap()) by default.
  1092. if test "x$default_retain" = "x1" ; then
  1093. AC_DEFINE([JEMALLOC_RETAIN], [ ])
  1094. fi
  1095. dnl Enable allocation from DSS if supported by the OS.
  1096. have_dss="1"
  1097. dnl Check whether the BSD/SUSv1 sbrk() exists. If not, disable DSS support.
  1098. AC_CHECK_FUNC([sbrk], [have_sbrk="1"], [have_sbrk="0"])
  1099. if test "x$have_sbrk" = "x1" ; then
  1100. if test "x$sbrk_deprecated" = "x1" ; then
  1101. AC_MSG_RESULT([Disabling dss allocation because sbrk is deprecated])
  1102. have_dss="0"
  1103. fi
  1104. else
  1105. have_dss="0"
  1106. fi
  1107. if test "x$have_dss" = "x1" ; then
  1108. AC_DEFINE([JEMALLOC_DSS], [ ])
  1109. fi
  1110. dnl Support the junk/zero filling option by default.
  1111. AC_ARG_ENABLE([fill],
  1112. [AS_HELP_STRING([--disable-fill], [Disable support for junk/zero filling])],
  1113. [if test "x$enable_fill" = "xno" ; then
  1114. enable_fill="0"
  1115. else
  1116. enable_fill="1"
  1117. fi
  1118. ],
  1119. [enable_fill="1"]
  1120. )
  1121. if test "x$enable_fill" = "x1" ; then
  1122. AC_DEFINE([JEMALLOC_FILL], [ ])
  1123. fi
  1124. AC_SUBST([enable_fill])
  1125. dnl Disable utrace(2)-based tracing by default.
  1126. AC_ARG_ENABLE([utrace],
  1127. [AS_HELP_STRING([--enable-utrace], [Enable utrace(2)-based tracing])],
  1128. [if test "x$enable_utrace" = "xno" ; then
  1129. enable_utrace="0"
  1130. else
  1131. enable_utrace="1"
  1132. fi
  1133. ],
  1134. [enable_utrace="0"]
  1135. )
  1136. JE_COMPILABLE([utrace(2)], [
  1137. #include <sys/types.h>
  1138. #include <sys/param.h>
  1139. #include <sys/time.h>
  1140. #include <sys/uio.h>
  1141. #include <sys/ktrace.h>
  1142. ], [
  1143. utrace((void *)0, 0);
  1144. ], [je_cv_utrace])
  1145. if test "x${je_cv_utrace}" = "xno" ; then
  1146. enable_utrace="0"
  1147. fi
  1148. if test "x$enable_utrace" = "x1" ; then
  1149. AC_DEFINE([JEMALLOC_UTRACE], [ ])
  1150. fi
  1151. AC_SUBST([enable_utrace])
  1152. dnl Do not support the xmalloc option by default.
  1153. AC_ARG_ENABLE([xmalloc],
  1154. [AS_HELP_STRING([--enable-xmalloc], [Support xmalloc option])],
  1155. [if test "x$enable_xmalloc" = "xno" ; then
  1156. enable_xmalloc="0"
  1157. else
  1158. enable_xmalloc="1"
  1159. fi
  1160. ],
  1161. [enable_xmalloc="0"]
  1162. )
  1163. if test "x$enable_xmalloc" = "x1" ; then
  1164. AC_DEFINE([JEMALLOC_XMALLOC], [ ])
  1165. fi
  1166. AC_SUBST([enable_xmalloc])
  1167. dnl Support cache-oblivious allocation alignment by default.
  1168. AC_ARG_ENABLE([cache-oblivious],
  1169. [AS_HELP_STRING([--disable-cache-oblivious],
  1170. [Disable support for cache-oblivious allocation alignment])],
  1171. [if test "x$enable_cache_oblivious" = "xno" ; then
  1172. enable_cache_oblivious="0"
  1173. else
  1174. enable_cache_oblivious="1"
  1175. fi
  1176. ],
  1177. [enable_cache_oblivious="1"]
  1178. )
  1179. if test "x$enable_cache_oblivious" = "x1" ; then
  1180. AC_DEFINE([JEMALLOC_CACHE_OBLIVIOUS], [ ])
  1181. fi
  1182. AC_SUBST([enable_cache_oblivious])
  1183. dnl Do not log by default.
  1184. AC_ARG_ENABLE([log],
  1185. [AS_HELP_STRING([--enable-log], [Support debug logging])],
  1186. [if test "x$enable_log" = "xno" ; then
  1187. enable_log="0"
  1188. else
  1189. enable_log="1"
  1190. fi
  1191. ],
  1192. [enable_log="0"]
  1193. )
  1194. if test "x$enable_log" = "x1" ; then
  1195. AC_DEFINE([JEMALLOC_LOG], [ ])
  1196. fi
  1197. AC_SUBST([enable_log])
  1198. JE_COMPILABLE([a program using __builtin_unreachable], [
  1199. void foo (void) {
  1200. __builtin_unreachable();
  1201. }
  1202. ], [
  1203. {
  1204. foo();
  1205. }
  1206. ], [je_cv_gcc_builtin_unreachable])
  1207. if test "x${je_cv_gcc_builtin_unreachable}" = "xyes" ; then
  1208. AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [__builtin_unreachable])
  1209. else
  1210. AC_DEFINE([JEMALLOC_INTERNAL_UNREACHABLE], [abort])
  1211. fi
  1212. dnl ============================================================================
  1213. dnl Check for __builtin_ffsl(), then ffsl(3), and fail if neither are found.
  1214. dnl One of those two functions should (theoretically) exist on all platforms
  1215. dnl that jemalloc currently has a chance of functioning on without modification.
  1216. dnl We additionally assume ffs[ll]() or __builtin_ffs[ll]() are defined if
  1217. dnl ffsl() or __builtin_ffsl() are defined, respectively.
  1218. JE_COMPILABLE([a program using __builtin_ffsl], [
  1219. #include <stdio.h>
  1220. #include <strings.h>
  1221. #include <string.h>
  1222. ], [
  1223. {
  1224. int rv = __builtin_ffsl(0x08);
  1225. printf("%d\n", rv);
  1226. }
  1227. ], [je_cv_gcc_builtin_ffsl])
  1228. if test "x${je_cv_gcc_builtin_ffsl}" = "xyes" ; then
  1229. AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [__builtin_ffsll])
  1230. AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [__builtin_ffsl])
  1231. AC_DEFINE([JEMALLOC_INTERNAL_FFS], [__builtin_ffs])
  1232. else
  1233. JE_COMPILABLE([a program using ffsl], [
  1234. #include <stdio.h>
  1235. #include <strings.h>
  1236. #include <string.h>
  1237. ], [
  1238. {
  1239. int rv = ffsl(0x08);
  1240. printf("%d\n", rv);
  1241. }
  1242. ], [je_cv_function_ffsl])
  1243. if test "x${je_cv_function_ffsl}" = "xyes" ; then
  1244. AC_DEFINE([JEMALLOC_INTERNAL_FFSLL], [ffsll])
  1245. AC_DEFINE([JEMALLOC_INTERNAL_FFSL], [ffsl])
  1246. AC_DEFINE([JEMALLOC_INTERNAL_FFS], [ffs])
  1247. else
  1248. AC_MSG_ERROR([Cannot build without ffsl(3) or __builtin_ffsl()])
  1249. fi
  1250. fi
  1251. AC_ARG_WITH([lg_quantum],
  1252. [AS_HELP_STRING([--with-lg-quantum=<lg-quantum>],
  1253. [Base 2 log of minimum allocation alignment])],
  1254. [LG_QUANTA="$with_lg_quantum"],
  1255. [LG_QUANTA="3 4"])
  1256. if test "x$with_lg_quantum" != "x" ; then
  1257. AC_DEFINE_UNQUOTED([LG_QUANTUM], [$with_lg_quantum])
  1258. fi
  1259. AC_ARG_WITH([lg_page],
  1260. [AS_HELP_STRING([--with-lg-page=<lg-page>], [Base 2 log of system page size])],
  1261. [LG_PAGE="$with_lg_page"], [LG_PAGE="detect"])
  1262. if test "x$LG_PAGE" = "xdetect"; then
  1263. AC_CACHE_CHECK([LG_PAGE],
  1264. [je_cv_lg_page],
  1265. AC_RUN_IFELSE([AC_LANG_PROGRAM(
  1266. [[
  1267. #include <strings.h>
  1268. #ifdef _WIN32
  1269. #include <windows.h>
  1270. #else
  1271. #include <unistd.h>
  1272. #endif
  1273. #include <stdio.h>
  1274. ]],
  1275. [[
  1276. int result;
  1277. FILE *f;
  1278. #ifdef _WIN32
  1279. SYSTEM_INFO si;
  1280. GetSystemInfo(&si);
  1281. result = si.dwPageSize;
  1282. #else
  1283. result = sysconf(_SC_PAGESIZE);
  1284. #endif
  1285. if (result == -1) {
  1286. return 1;
  1287. }
  1288. result = JEMALLOC_INTERNAL_FFSL(result) - 1;
  1289. f = fopen("conftest.out", "w");
  1290. if (f == NULL) {
  1291. return 1;
  1292. }
  1293. fprintf(f, "%d", result);
  1294. fclose(f);
  1295. return 0;
  1296. ]])],
  1297. [je_cv_lg_page=`cat conftest.out`],
  1298. [je_cv_lg_page=undefined],
  1299. [je_cv_lg_page=12]))
  1300. fi
  1301. if test "x${je_cv_lg_page}" != "x" ; then
  1302. LG_PAGE="${je_cv_lg_page}"
  1303. fi
  1304. if test "x${LG_PAGE}" != "xundefined" ; then
  1305. AC_DEFINE_UNQUOTED([LG_PAGE], [$LG_PAGE])
  1306. else
  1307. AC_MSG_ERROR([cannot determine value for LG_PAGE])
  1308. fi
  1309. AC_ARG_WITH([lg_hugepage],
  1310. [AS_HELP_STRING([--with-lg-hugepage=<lg-hugepage>],
  1311. [Base 2 log of system huge page size])],
  1312. [je_cv_lg_hugepage="${with_lg_hugepage}"],
  1313. [je_cv_lg_hugepage=""])
  1314. if test "x${je_cv_lg_hugepage}" = "x" ; then
  1315. dnl Look in /proc/meminfo (Linux-specific) for information on the default huge
  1316. dnl page size, if any. The relevant line looks like:
  1317. dnl
  1318. dnl Hugepagesize: 2048 kB
  1319. if test -e "/proc/meminfo" ; then
  1320. hpsk=[`cat /proc/meminfo 2>/dev/null | \
  1321. grep -e '^Hugepagesize:[[:space:]]\+[0-9]\+[[:space:]]kB$' | \
  1322. awk '{print $2}'`]
  1323. if test "x${hpsk}" != "x" ; then
  1324. je_cv_lg_hugepage=10
  1325. while test "${hpsk}" -gt 1 ; do
  1326. hpsk="$((hpsk / 2))"
  1327. je_cv_lg_hugepage="$((je_cv_lg_hugepage + 1))"
  1328. done
  1329. fi
  1330. fi
  1331. dnl Set default if unable to automatically configure.
  1332. if test "x${je_cv_lg_hugepage}" = "x" ; then
  1333. je_cv_lg_hugepage=21
  1334. fi
  1335. fi
  1336. if test "x${LG_PAGE}" != "xundefined" -a \
  1337. "${je_cv_lg_hugepage}" -lt "${LG_PAGE}" ; then
  1338. AC_MSG_ERROR([Huge page size (2^${je_cv_lg_hugepage}) must be at least page size (2^${LG_PAGE})])
  1339. fi
  1340. AC_DEFINE_UNQUOTED([LG_HUGEPAGE], [${je_cv_lg_hugepage}])
  1341. AC_ARG_WITH([lg_page_sizes],
  1342. [AS_HELP_STRING([--with-lg-page-sizes=<lg-page-sizes>],
  1343. [Base 2 logs of system page sizes to support])],
  1344. [LG_PAGE_SIZES="$with_lg_page_sizes"], [LG_PAGE_SIZES="$LG_PAGE"])
  1345. dnl ============================================================================
  1346. dnl jemalloc configuration.
  1347. dnl
  1348. AC_ARG_WITH([version],
  1349. [AS_HELP_STRING([--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid>],
  1350. [Version string])],
  1351. [
  1352. echo "${with_version}" | grep ['^[0-9]\+\.[0-9]\+\.[0-9]\+-[0-9]\+-g[0-9a-f]\+$'] 2>&1 1>/dev/null
  1353. if test $? -eq 0 ; then
  1354. echo "$with_version" > "${objroot}VERSION"
  1355. else
  1356. echo "${with_version}" | grep ['^VERSION$'] 2>&1 1>/dev/null
  1357. if test $? -ne 0 ; then
  1358. AC_MSG_ERROR([${with_version} does not match <major>.<minor>.<bugfix>-<nrev>-g<gid> or VERSION])
  1359. fi
  1360. fi
  1361. ], [
  1362. dnl Set VERSION if source directory is inside a git repository.
  1363. if test "x`test ! \"${srcroot}\" && cd \"${srcroot}\"; git rev-parse --is-inside-work-tree 2>/dev/null`" = "xtrue" ; then
  1364. dnl Pattern globs aren't powerful enough to match both single- and
  1365. dnl double-digit version numbers, so iterate over patterns to support up
  1366. dnl to version 99.99.99 without any accidental matches.
  1367. for pattern in ['[0-9].[0-9].[0-9]' '[0-9].[0-9].[0-9][0-9]' \
  1368. '[0-9].[0-9][0-9].[0-9]' '[0-9].[0-9][0-9].[0-9][0-9]' \
  1369. '[0-9][0-9].[0-9].[0-9]' '[0-9][0-9].[0-9].[0-9][0-9]' \
  1370. '[0-9][0-9].[0-9][0-9].[0-9]' \
  1371. '[0-9][0-9].[0-9][0-9].[0-9][0-9]']; do
  1372. (test ! "${srcroot}" && cd "${srcroot}"; git describe --long --abbrev=40 --match="${pattern}") > "${objroot}VERSION.tmp" 2>/dev/null
  1373. if test $? -eq 0 ; then
  1374. mv "${objroot}VERSION.tmp" "${objroot}VERSION"
  1375. break
  1376. fi
  1377. done
  1378. fi
  1379. rm -f "${objroot}VERSION.tmp"
  1380. ])
  1381. if test ! -e "${objroot}VERSION" ; then
  1382. if test ! -e "${srcroot}VERSION" ; then
  1383. AC_MSG_RESULT(
  1384. [Missing VERSION file, and unable to generate it; creating bogus VERSION])
  1385. echo "0.0.0-0-g0000000000000000000000000000000000000000" > "${objroot}VERSION"
  1386. else
  1387. cp ${srcroot}VERSION ${objroot}VERSION
  1388. fi
  1389. fi
  1390. jemalloc_version=`cat "${objroot}VERSION"`
  1391. jemalloc_version_major=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]1}'`
  1392. jemalloc_version_minor=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]2}'`
  1393. jemalloc_version_bugfix=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]3}'`
  1394. jemalloc_version_nrev=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]4}'`
  1395. jemalloc_version_gid=`echo ${jemalloc_version} | tr ".g-" " " | awk '{print [$]5}'`
  1396. AC_SUBST([jemalloc_version])
  1397. AC_SUBST([jemalloc_version_major])
  1398. AC_SUBST([jemalloc_version_minor])
  1399. AC_SUBST([jemalloc_version_bugfix])
  1400. AC_SUBST([jemalloc_version_nrev])
  1401. AC_SUBST([jemalloc_version_gid])
  1402. dnl ============================================================================
  1403. dnl Configure pthreads.
  1404. if test "x$abi" != "xpecoff" ; then
  1405. AC_DEFINE([JEMALLOC_HAVE_PTHREAD], [ ])
  1406. AC_CHECK_HEADERS([pthread.h], , [AC_MSG_ERROR([pthread.h is missing])])
  1407. dnl Some systems may embed pthreads functionality in libc; check for libpthread
  1408. dnl first, but try libc too before failing.
  1409. AC_CHECK_LIB([pthread], [pthread_create], [JE_APPEND_VS(LIBS, -lpthread)],
  1410. [AC_SEARCH_LIBS([pthread_create], , ,
  1411. AC_MSG_ERROR([libpthread is missing]))])
  1412. wrap_syms="${wrap_syms} pthread_create"
  1413. have_pthread="1"
  1414. dnl Check if we have dlsym support.
  1415. have_dlsym="1"
  1416. AC_CHECK_HEADERS([dlfcn.h],
  1417. AC_CHECK_FUNC([dlsym], [],
  1418. [AC_CHECK_LIB([dl], [dlsym], [LIBS="$LIBS -ldl"], [have_dlsym="0"])]),
  1419. [have_dlsym="0"])
  1420. if test "x$have_dlsym" = "x1" ; then
  1421. AC_DEFINE([JEMALLOC_HAVE_DLSYM], [ ])
  1422. fi
  1423. JE_COMPILABLE([pthread_atfork(3)], [
  1424. #include <pthread.h>
  1425. ], [
  1426. pthread_atfork((void *)0, (void *)0, (void *)0);
  1427. ], [je_cv_pthread_atfork])
  1428. if test "x${je_cv_pthread_atfork}" = "xyes" ; then
  1429. AC_DEFINE([JEMALLOC_HAVE_PTHREAD_ATFORK], [ ])
  1430. fi
  1431. dnl Check if pthread_setname_np is available with the expected API.
  1432. JE_COMPILABLE([pthread_setname_np(3)], [
  1433. #include <pthread.h>
  1434. ], [
  1435. pthread_setname_np(pthread_self(), "setname_test");
  1436. ], [je_cv_pthread_setname_np])
  1437. if test "x${je_cv_pthread_setname_np}" = "xyes" ; then
  1438. AC_DEFINE([JEMALLOC_HAVE_PTHREAD_SETNAME_NP], [ ])
  1439. fi
  1440. fi
  1441. JE_APPEND_VS(CPPFLAGS, -D_REENTRANT)
  1442. dnl Check whether clock_gettime(2) is in libc or librt.
  1443. AC_SEARCH_LIBS([clock_gettime], [rt])
  1444. dnl Cray wrapper compiler often adds `-lrt` when using `-static`. Check with
  1445. dnl `-dynamic` as well in case a user tries to dynamically link in jemalloc
  1446. if test "x$je_cv_cray_prgenv_wrapper" = "xyes" ; then
  1447. if test "$ac_cv_search_clock_gettime" != "-lrt"; then
  1448. JE_CFLAGS_SAVE()
  1449. unset ac_cv_search_clock_gettime
  1450. JE_CFLAGS_ADD([-dynamic])
  1451. AC_SEARCH_LIBS([clock_gettime], [rt])
  1452. JE_CFLAGS_RESTORE()
  1453. fi
  1454. fi
  1455. dnl check for CLOCK_MONOTONIC_COARSE (Linux-specific).
  1456. JE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC_COARSE, ...)], [
  1457. #include <time.h>
  1458. ], [
  1459. struct timespec ts;
  1460. clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
  1461. ], [je_cv_clock_monotonic_coarse])
  1462. if test "x${je_cv_clock_monotonic_coarse}" = "xyes" ; then
  1463. AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC_COARSE])
  1464. fi
  1465. dnl check for CLOCK_MONOTONIC.
  1466. JE_COMPILABLE([clock_gettime(CLOCK_MONOTONIC, ...)], [
  1467. #include <unistd.h>
  1468. #include <time.h>
  1469. ], [
  1470. struct timespec ts;
  1471. clock_gettime(CLOCK_MONOTONIC, &ts);
  1472. #if !defined(_POSIX_MONOTONIC_CLOCK) || _POSIX_MONOTONIC_CLOCK < 0
  1473. # error _POSIX_MONOTONIC_CLOCK missing/invalid
  1474. #endif
  1475. ], [je_cv_clock_monotonic])
  1476. if test "x${je_cv_clock_monotonic}" = "xyes" ; then
  1477. AC_DEFINE([JEMALLOC_HAVE_CLOCK_MONOTONIC])
  1478. fi
  1479. dnl Check for mach_absolute_time().
  1480. JE_COMPILABLE([mach_absolute_time()], [
  1481. #include <mach/mach_time.h>
  1482. ], [
  1483. mach_absolute_time();
  1484. ], [je_cv_mach_absolute_time])
  1485. if test "x${je_cv_mach_absolute_time}" = "xyes" ; then
  1486. AC_DEFINE([JEMALLOC_HAVE_MACH_ABSOLUTE_TIME])
  1487. fi
  1488. dnl Use syscall(2) (if available) by default.
  1489. AC_ARG_ENABLE([syscall],
  1490. [AS_HELP_STRING([--disable-syscall], [Disable use of syscall(2)])],
  1491. [if test "x$enable_syscall" = "xno" ; then
  1492. enable_syscall="0"
  1493. else
  1494. enable_syscall="1"
  1495. fi
  1496. ],
  1497. [enable_syscall="1"]
  1498. )
  1499. if test "x$enable_syscall" = "x1" ; then
  1500. dnl Check if syscall(2) is usable. Treat warnings as errors, so that e.g. OS
  1501. dnl X 10.12's deprecation warning prevents use.
  1502. JE_CFLAGS_SAVE()
  1503. JE_CFLAGS_ADD([-Werror])
  1504. JE_COMPILABLE([syscall(2)], [
  1505. #include <sys/syscall.h>
  1506. #include <unistd.h>
  1507. ], [
  1508. syscall(SYS_write, 2, "hello", 5);
  1509. ],
  1510. [je_cv_syscall])
  1511. JE_CFLAGS_RESTORE()
  1512. if test "x$je_cv_syscall" = "xyes" ; then
  1513. AC_DEFINE([JEMALLOC_USE_SYSCALL], [ ])
  1514. fi
  1515. fi
  1516. dnl Check if the GNU-specific secure_getenv function exists.
  1517. AC_CHECK_FUNC([secure_getenv],
  1518. [have_secure_getenv="1"],
  1519. [have_secure_getenv="0"]
  1520. )
  1521. if test "x$have_secure_getenv" = "x1" ; then
  1522. AC_DEFINE([JEMALLOC_HAVE_SECURE_GETENV], [ ])
  1523. fi
  1524. dnl Check if the GNU-specific sched_getcpu function exists.
  1525. AC_CHECK_FUNC([sched_getcpu],
  1526. [have_sched_getcpu="1"],
  1527. [have_sched_getcpu="0"]
  1528. )
  1529. if test "x$have_sched_getcpu" = "x1" ; then
  1530. AC_DEFINE([JEMALLOC_HAVE_SCHED_GETCPU], [ ])
  1531. fi
  1532. dnl Check if the GNU-specific sched_setaffinity function exists.
  1533. AC_CHECK_FUNC([sched_setaffinity],
  1534. [have_sched_setaffinity="1"],
  1535. [have_sched_setaffinity="0"]
  1536. )
  1537. if test "x$have_sched_setaffinity" = "x1" ; then
  1538. AC_DEFINE([JEMALLOC_HAVE_SCHED_SETAFFINITY], [ ])
  1539. fi
  1540. dnl Check if the Solaris/BSD issetugid function exists.
  1541. AC_CHECK_FUNC([issetugid],
  1542. [have_issetugid="1"],
  1543. [have_issetugid="0"]
  1544. )
  1545. if test "x$have_issetugid" = "x1" ; then
  1546. AC_DEFINE([JEMALLOC_HAVE_ISSETUGID], [ ])
  1547. fi
  1548. dnl Check whether the BSD-specific _malloc_thread_cleanup() exists. If so, use
  1549. dnl it rather than pthreads TSD cleanup functions to support cleanup during
  1550. dnl thread exit, in order to avoid pthreads library recursion during
  1551. dnl bootstrapping.
  1552. AC_CHECK_FUNC([_malloc_thread_cleanup],
  1553. [have__malloc_thread_cleanup="1"],
  1554. [have__malloc_thread_cleanup="0"]
  1555. )
  1556. if test "x$have__malloc_thread_cleanup" = "x1" ; then
  1557. AC_DEFINE([JEMALLOC_MALLOC_THREAD_CLEANUP], [ ])
  1558. wrap_syms="${wrap_syms} _malloc_thread_cleanup"
  1559. force_tls="1"
  1560. fi
  1561. dnl Check whether the BSD-specific _pthread_mutex_init_calloc_cb() exists. If
  1562. dnl so, mutex initialization causes allocation, and we need to implement this
  1563. dnl callback function in order to prevent recursive allocation.
  1564. AC_CHECK_FUNC([_pthread_mutex_init_calloc_cb],
  1565. [have__pthread_mutex_init_calloc_cb="1"],
  1566. [have__pthread_mutex_init_calloc_cb="0"]
  1567. )
  1568. if test "x$have__pthread_mutex_init_calloc_cb" = "x1" ; then
  1569. AC_DEFINE([JEMALLOC_MUTEX_INIT_CB])
  1570. wrap_syms="${wrap_syms} _malloc_prefork _malloc_postfork"
  1571. fi
  1572. dnl Disable lazy locking by default.
  1573. AC_ARG_ENABLE([lazy_lock],
  1574. [AS_HELP_STRING([--enable-lazy-lock],
  1575. [Enable lazy locking (only lock when multi-threaded)])],
  1576. [if test "x$enable_lazy_lock" = "xno" ; then
  1577. enable_lazy_lock="0"
  1578. else
  1579. enable_lazy_lock="1"
  1580. fi
  1581. ],
  1582. [enable_lazy_lock=""]
  1583. )
  1584. if test "x${enable_lazy_lock}" = "x" ; then
  1585. if test "x${force_lazy_lock}" = "x1" ; then
  1586. AC_MSG_RESULT([Forcing lazy-lock to avoid allocator/threading bootstrap issues])
  1587. enable_lazy_lock="1"
  1588. else
  1589. enable_lazy_lock="0"
  1590. fi
  1591. fi
  1592. if test "x${enable_lazy_lock}" = "x1" -a "x${abi}" = "xpecoff" ; then
  1593. AC_MSG_RESULT([Forcing no lazy-lock because thread creation monitoring is unimplemented])
  1594. enable_lazy_lock="0"
  1595. fi
  1596. if test "x$enable_lazy_lock" = "x1" ; then
  1597. if test "x$have_dlsym" = "x1" ; then
  1598. AC_DEFINE([JEMALLOC_LAZY_LOCK], [ ])
  1599. else
  1600. AC_MSG_ERROR([Missing dlsym support: lazy-lock cannot be enabled.])
  1601. fi
  1602. fi
  1603. AC_SUBST([enable_lazy_lock])
  1604. dnl Automatically configure TLS.
  1605. if test "x${force_tls}" = "x1" ; then
  1606. enable_tls="1"
  1607. elif test "x${force_tls}" = "x0" ; then
  1608. enable_tls="0"
  1609. else
  1610. enable_tls="1"
  1611. fi
  1612. if test "x${enable_tls}" = "x1" ; then
  1613. AC_MSG_CHECKING([for TLS])
  1614. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  1615. [[
  1616. __thread int x;
  1617. ]], [[
  1618. x = 42;
  1619. return 0;
  1620. ]])],
  1621. AC_MSG_RESULT([yes]),
  1622. AC_MSG_RESULT([no])
  1623. enable_tls="0")
  1624. else
  1625. enable_tls="0"
  1626. fi
  1627. AC_SUBST([enable_tls])
  1628. if test "x${enable_tls}" = "x1" ; then
  1629. AC_DEFINE_UNQUOTED([JEMALLOC_TLS], [ ])
  1630. fi
  1631. dnl ============================================================================
  1632. dnl Check for C11 atomics.
  1633. JE_COMPILABLE([C11 atomics], [
  1634. #include <stdint.h>
  1635. #if (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
  1636. #include <stdatomic.h>
  1637. #else
  1638. #error Atomics not available
  1639. #endif
  1640. ], [
  1641. uint64_t *p = (uint64_t *)0;
  1642. uint64_t x = 1;
  1643. volatile atomic_uint_least64_t *a = (volatile atomic_uint_least64_t *)p;
  1644. uint64_t r = atomic_fetch_add(a, x) + x;
  1645. return r == 0;
  1646. ], [je_cv_c11_atomics])
  1647. if test "x${je_cv_c11_atomics}" = "xyes" ; then
  1648. AC_DEFINE([JEMALLOC_C11_ATOMICS])
  1649. fi
  1650. dnl ============================================================================
  1651. dnl Check for GCC-style __atomic atomics.
  1652. JE_COMPILABLE([GCC __atomic atomics], [
  1653. ], [
  1654. int x = 0;
  1655. int val = 1;
  1656. int y = __atomic_fetch_add(&x, val, __ATOMIC_RELAXED);
  1657. int after_add = x;
  1658. return after_add == 1;
  1659. ], [je_cv_gcc_atomic_atomics])
  1660. if test "x${je_cv_gcc_atomic_atomics}" = "xyes" ; then
  1661. AC_DEFINE([JEMALLOC_GCC_ATOMIC_ATOMICS])
  1662. fi
  1663. dnl ============================================================================
  1664. dnl Check for GCC-style __sync atomics.
  1665. JE_COMPILABLE([GCC __sync atomics], [
  1666. ], [
  1667. int x = 0;
  1668. int before_add = __sync_fetch_and_add(&x, 1);
  1669. int after_add = x;
  1670. return (before_add == 0) && (after_add == 1);
  1671. ], [je_cv_gcc_sync_atomics])
  1672. if test "x${je_cv_gcc_sync_atomics}" = "xyes" ; then
  1673. AC_DEFINE([JEMALLOC_GCC_SYNC_ATOMICS])
  1674. fi
  1675. dnl ============================================================================
  1676. dnl Check for atomic(3) operations as provided on Darwin.
  1677. dnl We need this not for the atomic operations (which are provided above), but
  1678. dnl rather for the OSSpinLock type it exposes.
  1679. JE_COMPILABLE([Darwin OSAtomic*()], [
  1680. #include <libkern/OSAtomic.h>
  1681. #include <inttypes.h>
  1682. ], [
  1683. {
  1684. int32_t x32 = 0;
  1685. volatile int32_t *x32p = &x32;
  1686. OSAtomicAdd32(1, x32p);
  1687. }
  1688. {
  1689. int64_t x64 = 0;
  1690. volatile int64_t *x64p = &x64;
  1691. OSAtomicAdd64(1, x64p);
  1692. }
  1693. ], [je_cv_osatomic])
  1694. if test "x${je_cv_osatomic}" = "xyes" ; then
  1695. AC_DEFINE([JEMALLOC_OSATOMIC], [ ])
  1696. fi
  1697. dnl ============================================================================
  1698. dnl Check for madvise(2).
  1699. JE_COMPILABLE([madvise(2)], [
  1700. #include <sys/mman.h>
  1701. ], [
  1702. madvise((void *)0, 0, 0);
  1703. ], [je_cv_madvise])
  1704. if test "x${je_cv_madvise}" = "xyes" ; then
  1705. AC_DEFINE([JEMALLOC_HAVE_MADVISE], [ ])
  1706. dnl Check for madvise(..., MADV_FREE).
  1707. JE_COMPILABLE([madvise(..., MADV_FREE)], [
  1708. #include <sys/mman.h>
  1709. ], [
  1710. madvise((void *)0, 0, MADV_FREE);
  1711. ], [je_cv_madv_free])
  1712. if test "x${je_cv_madv_free}" = "xyes" ; then
  1713. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  1714. elif test "x${je_cv_madvise}" = "xyes" ; then
  1715. case "${host_cpu}" in i686|x86_64)
  1716. case "${host}" in *-*-linux*)
  1717. AC_DEFINE([JEMALLOC_PURGE_MADVISE_FREE], [ ])
  1718. AC_DEFINE([JEMALLOC_DEFINE_MADVISE_FREE], [ ])
  1719. ;;
  1720. esac
  1721. ;;
  1722. esac
  1723. fi
  1724. dnl Check for madvise(..., MADV_DONTNEED).
  1725. JE_COMPILABLE([madvise(..., MADV_DONTNEED)], [
  1726. #include <sys/mman.h>
  1727. ], [
  1728. madvise((void *)0, 0, MADV_DONTNEED);
  1729. ], [je_cv_madv_dontneed])
  1730. if test "x${je_cv_madv_dontneed}" = "xyes" ; then
  1731. AC_DEFINE([JEMALLOC_PURGE_MADVISE_DONTNEED], [ ])
  1732. fi
  1733. dnl Check for madvise(..., MADV_DO[NT]DUMP).
  1734. JE_COMPILABLE([madvise(..., MADV_DO[[NT]]DUMP)], [
  1735. #include <sys/mman.h>
  1736. ], [
  1737. madvise((void *)0, 0, MADV_DONTDUMP);
  1738. madvise((void *)0, 0, MADV_DODUMP);
  1739. ], [je_cv_madv_dontdump])
  1740. if test "x${je_cv_madv_dontdump}" = "xyes" ; then
  1741. AC_DEFINE([JEMALLOC_MADVISE_DONTDUMP], [ ])
  1742. fi
  1743. dnl Check for madvise(..., MADV_[NO]HUGEPAGE).
  1744. JE_COMPILABLE([madvise(..., MADV_[[NO]]HUGEPAGE)], [
  1745. #include <sys/mman.h>
  1746. ], [
  1747. madvise((void *)0, 0, MADV_HUGEPAGE);
  1748. madvise((void *)0, 0, MADV_NOHUGEPAGE);
  1749. ], [je_cv_thp])
  1750. case "${host_cpu}" in
  1751. arm*)
  1752. ;;
  1753. *)
  1754. if test "x${je_cv_thp}" = "xyes" ; then
  1755. AC_DEFINE([JEMALLOC_HAVE_MADVISE_HUGE], [ ])
  1756. fi
  1757. ;;
  1758. esac
  1759. fi
  1760. dnl ============================================================================
  1761. dnl Check whether __sync_{add,sub}_and_fetch() are available despite
  1762. dnl __GCC_HAVE_SYNC_COMPARE_AND_SWAP_n macros being undefined.
  1763. AC_DEFUN([JE_SYNC_COMPARE_AND_SWAP_CHECK],[
  1764. AC_CACHE_CHECK([whether to force $1-bit __sync_{add,sub}_and_fetch()],
  1765. [je_cv_sync_compare_and_swap_$2],
  1766. [AC_LINK_IFELSE([AC_LANG_PROGRAM([
  1767. #include <stdint.h>
  1768. ],
  1769. [
  1770. #ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2
  1771. {
  1772. uint$1_t x$1 = 0;
  1773. __sync_add_and_fetch(&x$1, 42);
  1774. __sync_sub_and_fetch(&x$1, 1);
  1775. }
  1776. #else
  1777. #error __GCC_HAVE_SYNC_COMPARE_AND_SWAP_$2 is defined, no need to force
  1778. #endif
  1779. ])],
  1780. [je_cv_sync_compare_and_swap_$2=yes],
  1781. [je_cv_sync_compare_and_swap_$2=no])])
  1782. if test "x${je_cv_sync_compare_and_swap_$2}" = "xyes" ; then
  1783. AC_DEFINE([JE_FORCE_SYNC_COMPARE_AND_SWAP_$2], [ ])
  1784. fi
  1785. ])
  1786. if test "x${je_cv_atomic9}" != "xyes" -a "x${je_cv_osatomic}" != "xyes" ; then
  1787. JE_SYNC_COMPARE_AND_SWAP_CHECK(32, 4)
  1788. JE_SYNC_COMPARE_AND_SWAP_CHECK(64, 8)
  1789. fi
  1790. dnl ============================================================================
  1791. dnl Check for __builtin_clz() and __builtin_clzl().
  1792. AC_CACHE_CHECK([for __builtin_clz],
  1793. [je_cv_builtin_clz],
  1794. [AC_LINK_IFELSE([AC_LANG_PROGRAM([],
  1795. [
  1796. {
  1797. unsigned x = 0;
  1798. int y = __builtin_clz(x);
  1799. }
  1800. {
  1801. unsigned long x = 0;
  1802. int y = __builtin_clzl(x);
  1803. }
  1804. ])],
  1805. [je_cv_builtin_clz=yes],
  1806. [je_cv_builtin_clz=no])])
  1807. if test "x${je_cv_builtin_clz}" = "xyes" ; then
  1808. AC_DEFINE([JEMALLOC_HAVE_BUILTIN_CLZ], [ ])
  1809. fi
  1810. dnl ============================================================================
  1811. dnl Check for os_unfair_lock operations as provided on Darwin.
  1812. JE_COMPILABLE([Darwin os_unfair_lock_*()], [
  1813. #include <os/lock.h>
  1814. #include <AvailabilityMacros.h>
  1815. ], [
  1816. #if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
  1817. #error "os_unfair_lock is not supported"
  1818. #else
  1819. os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
  1820. os_unfair_lock_lock(&lock);
  1821. os_unfair_lock_unlock(&lock);
  1822. #endif
  1823. ], [je_cv_os_unfair_lock])
  1824. if test "x${je_cv_os_unfair_lock}" = "xyes" ; then
  1825. AC_DEFINE([JEMALLOC_OS_UNFAIR_LOCK], [ ])
  1826. fi
  1827. dnl ============================================================================
  1828. dnl Check for spinlock(3) operations as provided on Darwin.
  1829. JE_COMPILABLE([Darwin OSSpin*()], [
  1830. #include <libkern/OSAtomic.h>
  1831. #include <inttypes.h>
  1832. ], [
  1833. OSSpinLock lock = 0;
  1834. OSSpinLockLock(&lock);
  1835. OSSpinLockUnlock(&lock);
  1836. ], [je_cv_osspin])
  1837. if test "x${je_cv_osspin}" = "xyes" ; then
  1838. AC_DEFINE([JEMALLOC_OSSPIN], [ ])
  1839. fi
  1840. dnl ============================================================================
  1841. dnl Darwin-related configuration.
  1842. AC_ARG_ENABLE([zone-allocator],
  1843. [AS_HELP_STRING([--disable-zone-allocator],
  1844. [Disable zone allocator for Darwin])],
  1845. [if test "x$enable_zone_allocator" = "xno" ; then
  1846. enable_zone_allocator="0"
  1847. else
  1848. enable_zone_allocator="1"
  1849. fi
  1850. ],
  1851. [if test "x${abi}" = "xmacho"; then
  1852. enable_zone_allocator="1"
  1853. fi
  1854. ]
  1855. )
  1856. AC_SUBST([enable_zone_allocator])
  1857. if test "x${enable_zone_allocator}" = "x1" ; then
  1858. if test "x${abi}" != "xmacho"; then
  1859. AC_MSG_ERROR([--enable-zone-allocator is only supported on Darwin])
  1860. fi
  1861. AC_DEFINE([JEMALLOC_ZONE], [ ])
  1862. fi
  1863. dnl ============================================================================
  1864. dnl Use initial-exec TLS by default.
  1865. AC_ARG_ENABLE([initial-exec-tls],
  1866. [AS_HELP_STRING([--disable-initial-exec-tls],
  1867. [Disable the initial-exec tls model])],
  1868. [if test "x$enable_initial_exec_tls" = "xno" ; then
  1869. enable_initial_exec_tls="0"
  1870. else
  1871. enable_initial_exec_tls="1"
  1872. fi
  1873. ],
  1874. [enable_initial_exec_tls="1"]
  1875. )
  1876. AC_SUBST([enable_initial_exec_tls])
  1877. if test "x${je_cv_tls_model}" = "xyes" -a \
  1878. "x${enable_initial_exec_tls}" = "x1" ; then
  1879. AC_DEFINE([JEMALLOC_TLS_MODEL],
  1880. [__attribute__((tls_model("initial-exec")))])
  1881. else
  1882. AC_DEFINE([JEMALLOC_TLS_MODEL], [ ])
  1883. fi
  1884. dnl ============================================================================
  1885. dnl Enable background threads if possible.
  1886. if test "x${have_pthread}" = "x1" -a "x${have_dlsym}" = "x1" \
  1887. -a "x${je_cv_os_unfair_lock}" != "xyes" \
  1888. -a "x${je_cv_osspin}" != "xyes" ; then
  1889. AC_DEFINE([JEMALLOC_BACKGROUND_THREAD])
  1890. fi
  1891. dnl ============================================================================
  1892. dnl Check for glibc malloc hooks
  1893. JE_COMPILABLE([glibc malloc hook], [
  1894. #include <stddef.h>
  1895. extern void (* __free_hook)(void *ptr);
  1896. extern void *(* __malloc_hook)(size_t size);
  1897. extern void *(* __realloc_hook)(void *ptr, size_t size);
  1898. ], [
  1899. void *ptr = 0L;
  1900. if (__malloc_hook) ptr = __malloc_hook(1);
  1901. if (__realloc_hook) ptr = __realloc_hook(ptr, 2);
  1902. if (__free_hook && ptr) __free_hook(ptr);
  1903. ], [je_cv_glibc_malloc_hook])
  1904. if test "x${je_cv_glibc_malloc_hook}" = "xyes" ; then
  1905. if test "x${JEMALLOC_PREFIX}" = "x" ; then
  1906. AC_DEFINE([JEMALLOC_GLIBC_MALLOC_HOOK], [ ])
  1907. wrap_syms="${wrap_syms} __free_hook __malloc_hook __realloc_hook"
  1908. fi
  1909. fi
  1910. JE_COMPILABLE([glibc memalign hook], [
  1911. #include <stddef.h>
  1912. extern void *(* __memalign_hook)(size_t alignment, size_t size);
  1913. ], [
  1914. void *ptr = 0L;
  1915. if (__memalign_hook) ptr = __memalign_hook(16, 7);
  1916. ], [je_cv_glibc_memalign_hook])
  1917. if test "x${je_cv_glibc_memalign_hook}" = "xyes" ; then
  1918. if test "x${JEMALLOC_PREFIX}" = "x" ; then
  1919. AC_DEFINE([JEMALLOC_GLIBC_MEMALIGN_HOOK], [ ])
  1920. wrap_syms="${wrap_syms} __memalign_hook"
  1921. fi
  1922. fi
  1923. JE_COMPILABLE([pthreads adaptive mutexes], [
  1924. #include <pthread.h>
  1925. ], [
  1926. pthread_mutexattr_t attr;
  1927. pthread_mutexattr_init(&attr);
  1928. pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
  1929. pthread_mutexattr_destroy(&attr);
  1930. ], [je_cv_pthread_mutex_adaptive_np])
  1931. if test "x${je_cv_pthread_mutex_adaptive_np}" = "xyes" ; then
  1932. AC_DEFINE([JEMALLOC_HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], [ ])
  1933. fi
  1934. JE_CFLAGS_SAVE()
  1935. JE_CFLAGS_ADD([-D_GNU_SOURCE])
  1936. JE_CFLAGS_ADD([-Werror])
  1937. JE_CFLAGS_ADD([-herror_on_warning])
  1938. JE_COMPILABLE([strerror_r returns char with gnu source], [
  1939. #include <errno.h>
  1940. #include <stdio.h>
  1941. #include <stdlib.h>
  1942. #include <string.h>
  1943. ], [
  1944. char *buffer = (char *) malloc(100);
  1945. char *error = strerror_r(EINVAL, buffer, 100);
  1946. printf("%s\n", error);
  1947. ], [je_cv_strerror_r_returns_char_with_gnu_source])
  1948. JE_CFLAGS_RESTORE()
  1949. if test "x${je_cv_strerror_r_returns_char_with_gnu_source}" = "xyes" ; then
  1950. AC_DEFINE([JEMALLOC_STRERROR_R_RETURNS_CHAR_WITH_GNU_SOURCE], [ ])
  1951. fi
  1952. dnl ============================================================================
  1953. dnl Check for typedefs, structures, and compiler characteristics.
  1954. AC_HEADER_STDBOOL
  1955. dnl ============================================================================
  1956. dnl Define commands that generate output files.
  1957. AC_CONFIG_COMMANDS([include/jemalloc/internal/public_symbols.txt], [
  1958. f="${objroot}include/jemalloc/internal/public_symbols.txt"
  1959. mkdir -p "${objroot}include/jemalloc/internal"
  1960. cp /dev/null "${f}"
  1961. for nm in `echo ${mangling_map} |tr ',' ' '` ; do
  1962. n=`echo ${nm} |tr ':' ' ' |awk '{print $[]1}'`
  1963. m=`echo ${nm} |tr ':' ' ' |awk '{print $[]2}'`
  1964. echo "${n}:${m}" >> "${f}"
  1965. dnl Remove name from public_syms so that it isn't redefined later.
  1966. public_syms=`for sym in ${public_syms}; do echo "${sym}"; done |grep -v "^${n}\$" |tr '\n' ' '`
  1967. done
  1968. for sym in ${public_syms} ; do
  1969. n="${sym}"
  1970. m="${JEMALLOC_PREFIX}${sym}"
  1971. echo "${n}:${m}" >> "${f}"
  1972. done
  1973. ], [
  1974. srcdir="${srcdir}"
  1975. objroot="${objroot}"
  1976. mangling_map="${mangling_map}"
  1977. public_syms="${public_syms}"
  1978. JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
  1979. ])
  1980. AC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols.awk], [
  1981. f="${objroot}include/jemalloc/internal/private_symbols.awk"
  1982. mkdir -p "${objroot}include/jemalloc/internal"
  1983. export_syms=`for sym in ${public_syms}; do echo "${JEMALLOC_PREFIX}${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
  1984. "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols.awk"
  1985. ], [
  1986. srcdir="${srcdir}"
  1987. objroot="${objroot}"
  1988. public_syms="${public_syms}"
  1989. wrap_syms="${wrap_syms}"
  1990. SYM_PREFIX="${SYM_PREFIX}"
  1991. JEMALLOC_PREFIX="${JEMALLOC_PREFIX}"
  1992. ])
  1993. AC_CONFIG_COMMANDS([include/jemalloc/internal/private_symbols_jet.awk], [
  1994. f="${objroot}include/jemalloc/internal/private_symbols_jet.awk"
  1995. mkdir -p "${objroot}include/jemalloc/internal"
  1996. export_syms=`for sym in ${public_syms}; do echo "jet_${sym}"; done; for sym in ${wrap_syms}; do echo "${sym}"; done;`
  1997. "${srcdir}/include/jemalloc/internal/private_symbols.sh" "${SYM_PREFIX}" ${export_syms} > "${objroot}include/jemalloc/internal/private_symbols_jet.awk"
  1998. ], [
  1999. srcdir="${srcdir}"
  2000. objroot="${objroot}"
  2001. public_syms="${public_syms}"
  2002. wrap_syms="${wrap_syms}"
  2003. SYM_PREFIX="${SYM_PREFIX}"
  2004. ])
  2005. AC_CONFIG_COMMANDS([include/jemalloc/internal/public_namespace.h], [
  2006. mkdir -p "${objroot}include/jemalloc/internal"
  2007. "${srcdir}/include/jemalloc/internal/public_namespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_namespace.h"
  2008. ], [
  2009. srcdir="${srcdir}"
  2010. objroot="${objroot}"
  2011. ])
  2012. AC_CONFIG_COMMANDS([include/jemalloc/internal/public_unnamespace.h], [
  2013. mkdir -p "${objroot}include/jemalloc/internal"
  2014. "${srcdir}/include/jemalloc/internal/public_unnamespace.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/internal/public_unnamespace.h"
  2015. ], [
  2016. srcdir="${srcdir}"
  2017. objroot="${objroot}"
  2018. ])
  2019. AC_CONFIG_COMMANDS([include/jemalloc/internal/size_classes.h], [
  2020. mkdir -p "${objroot}include/jemalloc/internal"
  2021. "${SHELL}" "${srcdir}/include/jemalloc/internal/size_classes.sh" "${LG_QUANTA}" 3 "${LG_PAGE_SIZES}" 2 > "${objroot}include/jemalloc/internal/size_classes.h"
  2022. ], [
  2023. SHELL="${SHELL}"
  2024. srcdir="${srcdir}"
  2025. objroot="${objroot}"
  2026. LG_QUANTA="${LG_QUANTA}"
  2027. LG_PAGE_SIZES="${LG_PAGE_SIZES}"
  2028. ])
  2029. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_protos_jet.h], [
  2030. mkdir -p "${objroot}include/jemalloc"
  2031. cat "${srcdir}/include/jemalloc/jemalloc_protos.h.in" | sed -e 's/@je_@/jet_/g' > "${objroot}include/jemalloc/jemalloc_protos_jet.h"
  2032. ], [
  2033. srcdir="${srcdir}"
  2034. objroot="${objroot}"
  2035. ])
  2036. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_rename.h], [
  2037. mkdir -p "${objroot}include/jemalloc"
  2038. "${srcdir}/include/jemalloc/jemalloc_rename.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" > "${objroot}include/jemalloc/jemalloc_rename.h"
  2039. ], [
  2040. srcdir="${srcdir}"
  2041. objroot="${objroot}"
  2042. ])
  2043. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle.h], [
  2044. mkdir -p "${objroot}include/jemalloc"
  2045. "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" je_ > "${objroot}include/jemalloc/jemalloc_mangle.h"
  2046. ], [
  2047. srcdir="${srcdir}"
  2048. objroot="${objroot}"
  2049. ])
  2050. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc_mangle_jet.h], [
  2051. mkdir -p "${objroot}include/jemalloc"
  2052. "${srcdir}/include/jemalloc/jemalloc_mangle.sh" "${objroot}include/jemalloc/internal/public_symbols.txt" jet_ > "${objroot}include/jemalloc/jemalloc_mangle_jet.h"
  2053. ], [
  2054. srcdir="${srcdir}"
  2055. objroot="${objroot}"
  2056. ])
  2057. AC_CONFIG_COMMANDS([include/jemalloc/jemalloc.h], [
  2058. mkdir -p "${objroot}include/jemalloc"
  2059. "${srcdir}/include/jemalloc/jemalloc.sh" "${objroot}" > "${objroot}include/jemalloc/jemalloc${install_suffix}.h"
  2060. ], [
  2061. srcdir="${srcdir}"
  2062. objroot="${objroot}"
  2063. install_suffix="${install_suffix}"
  2064. ])
  2065. dnl Process .in files.
  2066. AC_SUBST([cfghdrs_in])
  2067. AC_SUBST([cfghdrs_out])
  2068. AC_CONFIG_HEADERS([$cfghdrs_tup])
  2069. dnl ============================================================================
  2070. dnl Generate outputs.
  2071. AC_CONFIG_FILES([$cfgoutputs_tup config.stamp bin/jemalloc-config bin/jemalloc.sh bin/jeprof])
  2072. AC_SUBST([cfgoutputs_in])
  2073. AC_SUBST([cfgoutputs_out])
  2074. AC_OUTPUT
  2075. dnl ============================================================================
  2076. dnl Print out the results of configuration.
  2077. AC_MSG_RESULT([===============================================================================])
  2078. AC_MSG_RESULT([jemalloc version : ${jemalloc_version}])
  2079. AC_MSG_RESULT([library revision : ${rev}])
  2080. AC_MSG_RESULT([])
  2081. AC_MSG_RESULT([CONFIG : ${CONFIG}])
  2082. AC_MSG_RESULT([CC : ${CC}])
  2083. AC_MSG_RESULT([CONFIGURE_CFLAGS : ${CONFIGURE_CFLAGS}])
  2084. AC_MSG_RESULT([SPECIFIED_CFLAGS : ${SPECIFIED_CFLAGS}])
  2085. AC_MSG_RESULT([EXTRA_CFLAGS : ${EXTRA_CFLAGS}])
  2086. AC_MSG_RESULT([CPPFLAGS : ${CPPFLAGS}])
  2087. AC_MSG_RESULT([CXX : ${CXX}])
  2088. AC_MSG_RESULT([CONFIGURE_CXXFLAGS : ${CONFIGURE_CXXFLAGS}])
  2089. AC_MSG_RESULT([SPECIFIED_CXXFLAGS : ${SPECIFIED_CXXFLAGS}])
  2090. AC_MSG_RESULT([EXTRA_CXXFLAGS : ${EXTRA_CXXFLAGS}])
  2091. AC_MSG_RESULT([LDFLAGS : ${LDFLAGS}])
  2092. AC_MSG_RESULT([EXTRA_LDFLAGS : ${EXTRA_LDFLAGS}])
  2093. AC_MSG_RESULT([DSO_LDFLAGS : ${DSO_LDFLAGS}])
  2094. AC_MSG_RESULT([LIBS : ${LIBS}])
  2095. AC_MSG_RESULT([RPATH_EXTRA : ${RPATH_EXTRA}])
  2096. AC_MSG_RESULT([])
  2097. AC_MSG_RESULT([XSLTPROC : ${XSLTPROC}])
  2098. AC_MSG_RESULT([XSLROOT : ${XSLROOT}])
  2099. AC_MSG_RESULT([])
  2100. AC_MSG_RESULT([PREFIX : ${PREFIX}])
  2101. AC_MSG_RESULT([BINDIR : ${BINDIR}])
  2102. AC_MSG_RESULT([DATADIR : ${DATADIR}])
  2103. AC_MSG_RESULT([INCLUDEDIR : ${INCLUDEDIR}])
  2104. AC_MSG_RESULT([LIBDIR : ${LIBDIR}])
  2105. AC_MSG_RESULT([MANDIR : ${MANDIR}])
  2106. AC_MSG_RESULT([])
  2107. AC_MSG_RESULT([srcroot : ${srcroot}])
  2108. AC_MSG_RESULT([abs_srcroot : ${abs_srcroot}])
  2109. AC_MSG_RESULT([objroot : ${objroot}])
  2110. AC_MSG_RESULT([abs_objroot : ${abs_objroot}])
  2111. AC_MSG_RESULT([])
  2112. AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
  2113. AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
  2114. AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
  2115. AC_MSG_RESULT([install_suffix : ${install_suffix}])
  2116. AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
  2117. AC_MSG_RESULT([autogen : ${enable_autogen}])
  2118. AC_MSG_RESULT([debug : ${enable_debug}])
  2119. AC_MSG_RESULT([stats : ${enable_stats}])
  2120. AC_MSG_RESULT([prof : ${enable_prof}])
  2121. AC_MSG_RESULT([prof-libunwind : ${enable_prof_libunwind}])
  2122. AC_MSG_RESULT([prof-libgcc : ${enable_prof_libgcc}])
  2123. AC_MSG_RESULT([prof-gcc : ${enable_prof_gcc}])
  2124. AC_MSG_RESULT([fill : ${enable_fill}])
  2125. AC_MSG_RESULT([utrace : ${enable_utrace}])
  2126. AC_MSG_RESULT([xmalloc : ${enable_xmalloc}])
  2127. AC_MSG_RESULT([log : ${enable_log}])
  2128. AC_MSG_RESULT([lazy_lock : ${enable_lazy_lock}])
  2129. AC_MSG_RESULT([cache-oblivious : ${enable_cache_oblivious}])
  2130. AC_MSG_RESULT([cxx : ${enable_cxx}])
  2131. AC_MSG_RESULT([===============================================================================])