configure.ac 82 KB

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