configure.ac 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783
  1. dnl Copyright (c) 2001-2004, Roger Dingledine
  2. dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
  3. dnl Copyright (c) 2007-2019, The Tor Project, Inc.
  4. dnl See LICENSE for licensing information
  5. AC_PREREQ([2.63])
  6. AC_INIT([tor],[0.4.7.16-dev])
  7. AC_CONFIG_SRCDIR([src/app/main/tor_main.c])
  8. AC_CONFIG_MACRO_DIR([m4])
  9. configure_flags="$*"
  10. AC_DEFINE_UNQUOTED([CONFIG_FLAGS], ["$configure_flags"], [Flags passed to configure])
  11. # DO NOT EDIT THIS DEFINITION BY HAND UNLESS YOU KNOW WHAT YOU'RE DOING.
  12. #
  13. # The update_versions.py script updates this definition when the
  14. # version number changes. Tor uses it to make sure that it
  15. # only shuts down for missing "required protocols" when those protocols
  16. # are listed as required by a consensus after this date.
  17. AC_DEFINE(APPROX_RELEASE_DATE, ["2023-11-03"], # for 0.4.7.16-dev
  18. [Approximate date when this software was released. (Updated when the version changes.)])
  19. # "foreign" means we don't follow GNU package layout standards
  20. # "1.11" means we require automake version 1.11 or newer
  21. # "subdir-objects" means put .o files in the same directory as the .c files
  22. AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
  23. tor_ac_n_warnings=0
  24. tor_incr_n_warnings() {
  25. tor_ac_n_warnings=`expr $tor_ac_n_warnings + 1`
  26. }
  27. m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
  28. AC_CONFIG_HEADERS([orconfig.h])
  29. AC_USE_SYSTEM_EXTENSIONS
  30. AC_CANONICAL_HOST
  31. PKG_PROG_PKG_CONFIG
  32. if test "x$PKG_CONFIG" = "x" ; then
  33. pkg_config_user_action="install pkg-config, and check the PKG_CONFIG_PATH environment variable"
  34. AC_MSG_NOTICE([Some libraries need pkg-config, including systemd, nss, lzma, zstd, and custom mallocs.])
  35. AC_MSG_NOTICE([To use those libraries, $pkg_config_user_action.])
  36. else
  37. pkg_config_user_action="check the PKG_CONFIG_PATH environment variable"
  38. fi
  39. if test "x$PKG_CONFIG_PATH" = "x" && test "x$prefix" != "xNONE" && test "$host" != "$build"; then
  40. export PKG_CONFIG_PATH=$prefix/lib/pkgconfig
  41. AC_MSG_NOTICE([set PKG_CONFIG_PATH=$PKG_CONFIG_PATH to support cross-compiling])
  42. fi
  43. AC_ARG_ENABLE(openbsd-malloc,
  44. AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only. Deprecated: see --with-malloc]))
  45. AC_ARG_ENABLE(static-openssl,
  46. AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
  47. AC_ARG_ENABLE(static-libevent,
  48. AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
  49. AC_ARG_ENABLE(static-zlib,
  50. AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
  51. AC_ARG_ENABLE(static-tor,
  52. AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
  53. AC_ARG_ENABLE(unittests,
  54. AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
  55. AC_ARG_ENABLE(coverage,
  56. AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
  57. AC_ARG_ENABLE(asserts-in-tests,
  58. AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
  59. AC_ARG_ENABLE(system-torrc,
  60. AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
  61. AC_ARG_ENABLE(libfuzzer,
  62. AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
  63. AC_ARG_ENABLE(oss-fuzz,
  64. AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
  65. AC_ARG_ENABLE(memory-sentinels,
  66. AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
  67. AC_ARG_ENABLE(restart-debugging,
  68. AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
  69. AC_ARG_ENABLE(zstd-advanced-apis,
  70. AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
  71. AC_ARG_ENABLE(nss,
  72. AS_HELP_STRING(--enable-nss, [Use Mozilla's NSS TLS library. (EXPERIMENTAL)]))
  73. AC_ARG_ENABLE(pic,
  74. AS_HELP_STRING(--enable-pic, [Build Tor's binaries as position-independent code, suitable to link as a library.]))
  75. AC_ARG_ENABLE(missing-doc-warnings,
  76. AS_HELP_STRING(--enable-missing-doc-warnings, [Tell doxygen to warn about missing documentation. Makes doxygen warnings nonfatal.]))
  77. if test "$enable_missing_doc_warnings" = "yes"; then
  78. DOXYGEN_FATAL_WARNINGS=NO
  79. DOXYGEN_WARN_ON_MISSING=YES
  80. elif test "$enable_fatal_warnings" = "yes"; then
  81. # Fatal warnings from doxygen are nice, but not if we're warning about
  82. # missing documentation.
  83. DOXYGEN_FATAL_WARNINGS=YES
  84. DOXYGEN_WARN_ON_MISSING=NO
  85. else
  86. DOXYGEN_FATAL_WARNINGS=NO
  87. DOXYGEN_WARN_ON_MISSING=NO
  88. fi
  89. AC_SUBST(DOXYGEN_FATAL_WARNINGS)
  90. AC_SUBST(DOXYGEN_WARN_ON_MISSING)
  91. if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
  92. AC_MSG_ERROR([Can't disable assertions outside of coverage build])
  93. fi
  94. AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
  95. AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
  96. AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
  97. AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
  98. AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
  99. AM_CONDITIONAL(USE_NSS, test "x$enable_nss" = "xyes")
  100. AM_CONDITIONAL(USE_OPENSSL, test "x$enable_nss" != "xyes")
  101. if test "x$enable_coverage" = "xyes"; then
  102. AC_DEFINE(ENABLE_COVERAGE, 1,
  103. [Defined if coverage support is enabled for the unit tests])
  104. fi
  105. if test "x$enable_nss" = "xyes"; then
  106. AC_DEFINE(ENABLE_NSS, 1,
  107. [Defined if we're building with NSS.])
  108. else
  109. AC_DEFINE(ENABLE_OPENSSL, 1,
  110. [Defined if we're building with OpenSSL or LibreSSL])
  111. fi
  112. if test "$enable_static_tor" = "yes"; then
  113. enable_static_libevent="yes";
  114. enable_static_openssl="yes";
  115. enable_static_zlib="yes";
  116. TOR_STATIC_LDFLAGS="-static"
  117. fi
  118. AC_SUBST(TOR_STATIC_LDFLAGS)
  119. if test "$enable_system_torrc" = "no"; then
  120. AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
  121. [Defined if we're not going to look for a torrc in SYSCONF])
  122. fi
  123. if test "$enable_memory_sentinels" = "no"; then
  124. AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
  125. [Defined if we're turning off memory safety code to look for bugs])
  126. fi
  127. AC_ARG_ENABLE(manpage,
  128. AS_HELP_STRING(--disable-manpage, [Disable manpage generation.]))
  129. AC_ARG_ENABLE(html-manual,
  130. AS_HELP_STRING(--disable-html-manual, [Disable HTML documentation.]))
  131. AC_ARG_ENABLE(asciidoc,
  132. AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
  133. [case "${enableval}" in
  134. "yes") asciidoc=true ;;
  135. "no") asciidoc=false ;;
  136. *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
  137. esac], [asciidoc=true])
  138. # systemd notify support
  139. AC_ARG_ENABLE(systemd,
  140. AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
  141. [case "${enableval}" in
  142. "yes") systemd=true ;;
  143. "no") systemd=false ;;
  144. * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
  145. esac], [systemd=auto])
  146. if test "$enable_restart_debugging" = "yes"; then
  147. AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
  148. [Defined if we're building with support for in-process restart debugging.])
  149. fi
  150. if test "$enable_zstd_advanced_apis" != "no"; then
  151. AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
  152. [Defined if we're going to try to use zstd's "static-only" APIs.])
  153. fi
  154. # systemd support
  155. if test "x$enable_systemd" = "xno"; then
  156. have_systemd=no;
  157. else
  158. PKG_CHECK_MODULES(SYSTEMD,
  159. [libsystemd-daemon],
  160. have_systemd=yes,
  161. have_systemd=no)
  162. if test "x$have_systemd" = "xno"; then
  163. AC_MSG_NOTICE([Okay, checking for systemd a different way...])
  164. PKG_CHECK_MODULES(SYSTEMD,
  165. [libsystemd],
  166. have_systemd=yes,
  167. have_systemd=no)
  168. fi
  169. fi
  170. if test "x$have_systemd" = "xyes"; then
  171. AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
  172. TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
  173. TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
  174. PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
  175. [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or greater])], [])
  176. fi
  177. AC_SUBST(TOR_SYSTEMD_CFLAGS)
  178. AC_SUBST(TOR_SYSTEMD_LIBS)
  179. if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
  180. AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found, $pkg_config_user_action, or set SYSTEMD_CFLAGS and SYSTEMD_LIBS.])
  181. fi
  182. case "$host" in
  183. *-*-solaris* )
  184. AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
  185. ;;
  186. esac
  187. AC_ARG_ENABLE(gcc-warnings,
  188. AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
  189. AC_ARG_ENABLE(fatal-warnings,
  190. AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
  191. AC_ARG_ENABLE(gcc-warnings-advisory,
  192. AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
  193. dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
  194. AC_ARG_ENABLE(gcc-hardening,
  195. AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
  196. dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
  197. AC_ARG_ENABLE(expensive-hardening,
  198. AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
  199. AC_ARG_ENABLE(fragile-hardening,
  200. AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
  201. if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
  202. fragile_hardening="yes"
  203. AC_DEFINE(ENABLE_FRAGILE_HARDENING, 1, [Defined if we're building with additional, fragile and expensive compiler hardening])
  204. AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
  205. fi
  206. AC_ARG_ENABLE(all-bugs-are-fatal,
  207. AS_HELP_STRING(--enable-all-bugs-are-fatal, [force all soft asserts in Tor codebase (tor_assert_nonfatal(), BUG(), etc.) to act as hard asserts (tor_assert() and equivalents); makes Tor fragile; only recommended for dev builds]))
  208. if test "x$enable_all_bugs_are_fatal" = "xyes"; then
  209. AC_DEFINE(ALL_BUGS_ARE_FATAL, 1, [All assert failures are fatal])
  210. fi
  211. dnl Linker hardening options
  212. dnl Currently these options are ELF specific - you can't use this with MacOSX
  213. AC_ARG_ENABLE(linker-hardening,
  214. AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
  215. AC_ARG_ENABLE(local-appdata,
  216. AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
  217. if test "$enable_local_appdata" = "yes"; then
  218. AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
  219. [Defined if we default to host local appdata paths on Windows])
  220. fi
  221. AC_ARG_ENABLE(tool-name-check,
  222. AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
  223. AC_ARG_ENABLE(seccomp,
  224. AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
  225. AC_ARG_ENABLE(libscrypt,
  226. AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
  227. dnl --- Tracing Options. ---
  228. TOR_TRACE_LIBS=
  229. dnl LTTng instrumentation option.
  230. AC_ARG_ENABLE(tracing-instrumentation-lttng,
  231. AS_HELP_STRING([--enable-tracing-instrumentation-lttng],
  232. [build with LTTng-UST instrumentation]))
  233. AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LTTNG],
  234. [test "x$enable_tracing_instrumentation_lttng" = "xyes"])
  235. if test "x$enable_tracing_instrumentation_lttng" = "xyes"; then
  236. AC_CHECK_HEADERS([lttng/tracepoint.h], [],
  237. [AC_MSG_ERROR([LTTng instrumentation headers not found.
  238. On Debian, apt install liblttng-ust-dev"])], [])
  239. AC_DEFINE([USE_TRACING_INSTRUMENTATION_LTTNG], [1], [Using LTTng instrumentation])
  240. TOR_TRACE_LIBS="-llttng-ust -ldl"
  241. have_tracing=1
  242. fi
  243. dnl USDT instrumentation option.
  244. AC_ARG_ENABLE(tracing-instrumentation-usdt,
  245. AS_HELP_STRING([--enable-tracing-instrumentation-usdt],
  246. [build with tracing USDT instrumentation]))
  247. AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_USDT],
  248. [test "x$enable_tracing_instrumentation_usdt" = "xyes"])
  249. if test "x$enable_tracing_instrumentation_usdt" = "xyes"; then
  250. AC_CHECK_HEADERS([sys/sdt.h], [],
  251. [AC_MSG_ERROR([USDT instrumentation requires sys/sdt.h header.
  252. On Debian, apt install systemtap-sdt-dev])], [])
  253. AC_MSG_CHECKING([STAP_PROBEV()])
  254. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  255. #define SDT_USE_VARIADIC
  256. #include <sys/sdt.h>
  257. void test(void)
  258. {
  259. STAP_PROBEV(p, n, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
  260. }
  261. ]])], [
  262. AC_MSG_RESULT([yes])
  263. dnl LTTng generates USDT probes if the UST library was built with
  264. dnl --with-sdt. There is unfortunately no way to check that so we always
  265. dnl build the USDT probes even though LTTng instrumentation was requested.
  266. AC_DEFINE([USE_TRACING_INSTRUMENTATION_USDT], [1], [Using USDT instrumentation])
  267. have_tracing=1
  268. ], [
  269. AC_MSG_RESULT([no])
  270. AC_MSG_ERROR([USDT tracing support requires STAP_PROBEV()])
  271. ])
  272. fi
  273. dnl Tracepoints event to debug logs.
  274. AC_ARG_ENABLE(tracing-instrumentation-log-debug,
  275. AS_HELP_STRING([--enable-tracing-instrumentation-log-debug],
  276. [build with tracing event to debug log]),
  277. AC_DEFINE([USE_TRACING_INSTRUMENTATION_LOG_DEBUG], [1],
  278. [Tracepoints to log debug]), [])
  279. AM_CONDITIONAL([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
  280. [test "x$enable_tracing_instrumentation_log_debug" = "xyes"])
  281. if test "x$enable_tracing_instrumentation_log_debug" = "xyes"; then
  282. have_tracing=1
  283. fi
  284. dnl Define that tracing is supported if any instrumentation is used.
  285. AM_COND_IF([USE_TRACING_INSTRUMENTATION_LOG_DEBUG],
  286. AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
  287. AM_COND_IF([USE_TRACING_INSTRUMENTATION_USDT],
  288. AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
  289. AM_COND_IF([USE_TRACING_INSTRUMENTATION_LTTNG],
  290. AC_DEFINE([HAVE_TRACING], [1], [Compiled with tracing support]))
  291. AM_CONDITIONAL([USE_TRACING], [test "x$have_tracing" = x1 ])
  292. dnl Finally, define the trace libs.
  293. AC_SUBST([TOR_TRACE_LIBS])
  294. dnl -- End Tracing Options. --
  295. dnl Enable Android only features.
  296. AC_ARG_ENABLE(android,
  297. AS_HELP_STRING(--enable-android, [build with Android features enabled]))
  298. AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
  299. if test "x$enable_android" = "xyes"; then
  300. AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
  301. fi
  302. dnl ---
  303. dnl Tor modules options. These options are namespaced with --disable-module-XXX
  304. dnl ---
  305. dnl All our modules.
  306. m4_define(MODULES, relay dirauth dircache)
  307. # Some modules are only disabled through another option. For those, we don't
  308. # want to print the help in the summary at the end of the configure. Any entry
  309. # in the following set will not print the "--disable-module-NAME" command in
  310. # the summary.
  311. m4_set_add_all([MODULES_WITH_NO_OPTIONS], [dircache])
  312. dnl Relay module.
  313. AC_ARG_ENABLE([module-relay],
  314. AS_HELP_STRING([--disable-module-relay],
  315. [Build tor without the Relay modules: tor can not run as a relay, bridge, or authority. Implies --disable-module-dirauth]))
  316. AM_CONDITIONAL(BUILD_MODULE_RELAY, [test "x$enable_module_relay" != "xno"])
  317. AM_COND_IF(BUILD_MODULE_RELAY,
  318. AC_DEFINE([HAVE_MODULE_RELAY], [1],
  319. [Compile with Relay feature support]))
  320. dnl Dircache module. (This cannot be enabled or disabled independently of
  321. dnl the relay module. It is not listed by --list-modules for this reason.)
  322. AM_CONDITIONAL(BUILD_MODULE_DIRCACHE,
  323. [test "x$enable_module_relay" != "xno"])
  324. AM_COND_IF(BUILD_MODULE_DIRCACHE,
  325. AC_DEFINE([HAVE_MODULE_DIRCACHE], [1],
  326. [Compile with directory cache support]))
  327. dnl Directory Authority module.
  328. AC_ARG_ENABLE([module-dirauth],
  329. AS_HELP_STRING([--disable-module-dirauth],
  330. [Build tor without the Directory Authority module: tor can not run as a directory authority or bridge authority]))
  331. AM_CONDITIONAL(BUILD_MODULE_DIRAUTH,[test "x$enable_module_dirauth" != "xno" && test "x$enable_module_relay" != "xno"])
  332. AM_COND_IF(BUILD_MODULE_DIRAUTH,
  333. AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
  334. [Compile with Directory Authority feature support]))
  335. dnl Helper variables.
  336. TOR_MODULES_ALL_ENABLED=
  337. AC_DEFUN([ADD_MODULE], [
  338. MODULE=m4_toupper($1)
  339. TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
  340. ])
  341. m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
  342. AC_SUBST(TOR_MODULES_ALL_ENABLED)
  343. dnl check for the correct "ar" when cross-compiling.
  344. dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
  345. dnl so kludge up a replacement for the case where it isn't there yet.)
  346. m4_ifdef([AM_PROG_AR],
  347. [AM_PROG_AR],
  348. [AN_MAKEVAR([AR], [AC_PROG_AR])
  349. AN_PROGRAM([ar], [AC_PROG_AR])
  350. AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
  351. AC_PROG_AR])
  352. dnl Check whether the above macro has settled for a simply named tool even
  353. dnl though we're cross compiling. We must do this before running AC_PROG_CC,
  354. dnl because that will find any cc on the system, not only the cross-compiler,
  355. dnl and then verify that a binary built with this compiler runs on the
  356. dnl build system. It will then come to the false conclusion that we're not
  357. dnl cross-compiling.
  358. if test "x$enable_tool_name_check" != "xno"; then
  359. if test "x$ac_tool_warned" = "xyes"; then
  360. AC_MSG_ERROR([We are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
  361. elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
  362. AC_MSG_ERROR([We think we are cross compiling but could not find a properly named toolchain. Do you have your cross-compiling toolchain in PATH? (You can --disable-tool-name-check to ignore this.)])
  363. fi
  364. fi
  365. AC_PROG_CC
  366. AC_PROG_CPP
  367. AC_PROG_MAKE_SET
  368. AC_PROG_RANLIB
  369. AC_PROG_SED
  370. AX_COMPILER_VERSION
  371. AX_COMPILER_VENDOR
  372. AC_DEFINE_UNQUOTED([COMPILER_VERSION],["$ax_cv_c_compiler_version"], [Compiler version])
  373. AC_DEFINE_UNQUOTED([COMPILER_VENDOR],["$ax_cv_c_compiler_vendor"], [Compiler vendor])
  374. AS_CASE($ax_cv_c_compiler_vendor,
  375. [gnu], AC_DEFINE([COMPILER],["GCC"],[Compiler name]),
  376. AC_DEFINE([COMPILER],[],[Compiler name])
  377. )
  378. AC_ARG_VAR([PERL], [path to Perl binary])
  379. AC_CHECK_PROGS([PERL], [perl])
  380. AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
  381. dnl check for asciidoc and a2x
  382. AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
  383. AC_PATH_PROGS([A2X], [a2x a2x.py], none)
  384. AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
  385. AM_CONDITIONAL(BUILD_MANPAGE, [test "x$enable_manpage" != "xno"])
  386. AM_CONDITIONAL(BUILD_HTML_DOCS, [test "x$enable_html_manual" != "xno"])
  387. AM_PROG_CC_C_O
  388. dnl Before autoconf 2.70, AC_PROG_CC_C99 is supposedly necessary for some
  389. dnl compilers if you want C99 support. Starting with 2.70, it is obsolete and
  390. dnl forbidden.
  391. m4_version_prereq([2.70], [:], [AC_PROG_CC_C99])
  392. AC_CACHE_CHECK([for Python 3], [tor_cv_PYTHON],
  393. [AC_PATH_PROGS_FEATURE_CHECK([PYTHON], [ \
  394. python3 \
  395. python3.8 python3.7 python3.6 python3.5 python3.4 \
  396. python ],
  397. [["$ac_path_PYTHON" -c 'import sys; sys.exit(sys.version_info[0]<3)' && tor_cv_PYTHON="$ac_path_PYTHON" ac_path_PYTHON_found=:]] )])
  398. AC_SUBST([PYTHON], [$tor_cv_PYTHON])
  399. PYTHON="$tor_cv_PYTHON"
  400. if test "x$PYTHON" = "x"; then
  401. tor_incr_n_warnings
  402. AC_MSG_WARN([Python 3 unavailable; some tests will not be run.])
  403. fi
  404. AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
  405. ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
  406. AC_C_FLEXIBLE_ARRAY_MEMBER
  407. ], [
  408. dnl Maybe we've got an old autoconf...
  409. AC_CACHE_CHECK([for flexible array members],
  410. tor_cv_c_flexarray,
  411. [AC_COMPILE_IFELSE(
  412. AC_LANG_PROGRAM([
  413. struct abc { int a; char b[]; };
  414. ], [
  415. struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
  416. def->b[0] = 33;
  417. ]),
  418. [tor_cv_c_flexarray=yes],
  419. [tor_cv_c_flexarray=no])])
  420. if test "$tor_cv_flexarray" = "yes"; then
  421. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  422. else
  423. AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
  424. fi
  425. ])
  426. AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
  427. tor_cv_c_c99_decl,
  428. [AC_COMPILE_IFELSE(
  429. [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
  430. [tor_cv_c_c99_decl=yes],
  431. [tor_cv_c_c99_decl=no] )])
  432. if test "$tor_cv_c_c99_decl" != "yes"; then
  433. AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
  434. fi
  435. AC_CACHE_CHECK([for working C99 designated initializers],
  436. tor_cv_c_c99_designated_init,
  437. [AC_COMPILE_IFELSE(
  438. [AC_LANG_PROGRAM([struct s { int a; int b; };],
  439. [[ struct s ss = { .b = 5, .a = 6 }; ]])],
  440. [tor_cv_c_c99_designated_init=yes],
  441. [tor_cv_c_c99_designated_init=no] )])
  442. if test "$tor_cv_c_c99_designated_init" != "yes"; then
  443. AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
  444. fi
  445. saved_CFLAGS="$CFLAGS"
  446. CFLAGS="$CFLAGS -Werror"
  447. AC_CACHE_CHECK([for __attribute__((fallthrough))],
  448. tor_cv_c_attr_fallthrough,
  449. [AC_COMPILE_IFELSE(
  450. [AC_LANG_PROGRAM([extern int x; void fn(void) ;],
  451. [[ switch (x) { case 1: fn(); __attribute__((fallthrough));
  452. case 2: fn(); break; } ]])],
  453. [tor_cv_c_attr_fallthrough=yes],
  454. [tor_cv_c_attr_fallthrough=no] )])
  455. CFLAGS="$saved_CFLAGS"
  456. if test "$tor_cv_c_attr_fallthrough" = "yes"; then
  457. AC_DEFINE(HAVE_ATTR_FALLTHROUGH, [1], [defined if we have the fallthrough attribute.])
  458. fi
  459. TORUSER=_tor
  460. AC_ARG_WITH(tor-user,
  461. AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
  462. [
  463. TORUSER=$withval
  464. ]
  465. )
  466. AC_SUBST(TORUSER)
  467. TORGROUP=_tor
  468. AC_ARG_WITH(tor-group,
  469. AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
  470. [
  471. TORGROUP=$withval
  472. ]
  473. )
  474. AC_SUBST(TORGROUP)
  475. dnl If _WIN32 is defined and non-zero, we are building for win32
  476. AC_MSG_CHECKING([for win32])
  477. AC_RUN_IFELSE([AC_LANG_SOURCE([
  478. int main(int c, char **v) {
  479. #ifdef _WIN32
  480. #if _WIN32
  481. return 0;
  482. #else
  483. return 1;
  484. #endif
  485. #else
  486. return 2;
  487. #endif
  488. }])],
  489. bwin32=true; AC_MSG_RESULT([yes]),
  490. bwin32=false; AC_MSG_RESULT([no]),
  491. bwin32=cross; AC_MSG_RESULT([cross])
  492. )
  493. if test "$bwin32" = "cross"; then
  494. AC_MSG_CHECKING([for win32 (cross)])
  495. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  496. #ifdef _WIN32
  497. int main(int c, char **v) {return 0;}
  498. #else
  499. #error
  500. int main(int c, char **v) {return x(y);}
  501. #endif
  502. ])],
  503. bwin32=true; AC_MSG_RESULT([yes]),
  504. bwin32=false; AC_MSG_RESULT([no]))
  505. fi
  506. AH_BOTTOM([
  507. #ifdef _WIN32
  508. /* Defined to access windows functions and definitions for >=WinVista */
  509. # ifndef WINVER
  510. # define WINVER 0x0600
  511. # endif
  512. /* Defined to access _other_ windows functions and definitions for >=WinVista */
  513. # ifndef _WIN32_WINNT
  514. # define _WIN32_WINNT 0x0600
  515. # endif
  516. /* Defined to avoid including some windows headers as part of Windows.h */
  517. # ifndef WIN32_LEAN_AND_MEAN
  518. # define WIN32_LEAN_AND_MEAN 1
  519. # endif
  520. #endif
  521. ])
  522. AM_CONDITIONAL(WIN32, test "x$bwin32" = "xtrue")
  523. AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
  524. AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
  525. dnl Enable C99 when compiling with MIPSpro
  526. AC_MSG_CHECKING([for MIPSpro compiler])
  527. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
  528. #if (defined(__sgi) && defined(_COMPILER_VERSION))
  529. #error
  530. return x(y);
  531. #endif
  532. ])],
  533. bmipspro=false; AC_MSG_RESULT(no),
  534. bmipspro=true; AC_MSG_RESULT(yes))
  535. if test "$bmipspro" = "true"; then
  536. CFLAGS="$CFLAGS -c99"
  537. fi
  538. AC_C_BIGENDIAN
  539. AC_SEARCH_LIBS(socket, [socket network])
  540. AC_SEARCH_LIBS(gethostbyname, [nsl])
  541. AC_SEARCH_LIBS(dlopen, [dl])
  542. AC_SEARCH_LIBS(inet_aton, [resolv])
  543. AC_SEARCH_LIBS(backtrace, [execinfo])
  544. saved_LIBS="$LIBS"
  545. AC_SEARCH_LIBS([clock_gettime], [rt])
  546. if test "$LIBS" != "$saved_LIBS"; then
  547. # Looks like we need -lrt for clock_gettime().
  548. have_rt=yes
  549. fi
  550. if test "$bwin32" = "false"; then
  551. AC_SEARCH_LIBS(pthread_create, [pthread])
  552. AC_SEARCH_LIBS(pthread_detach, [pthread])
  553. fi
  554. AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
  555. AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
  556. AC_CHECK_FUNCS(
  557. _NSGetEnviron \
  558. RtlSecureZeroMemory \
  559. SecureZeroMemory \
  560. accept4 \
  561. backtrace \
  562. backtrace_symbols_fd \
  563. eventfd \
  564. explicit_bzero \
  565. timingsafe_memcmp \
  566. flock \
  567. fsync \
  568. ftime \
  569. get_current_dir_name \
  570. getaddrinfo \
  571. getdelim \
  572. getifaddrs \
  573. getline \
  574. getrlimit \
  575. gettimeofday \
  576. gmtime_r \
  577. gnu_get_libc_version \
  578. inet_aton \
  579. ioctl \
  580. issetugid \
  581. llround \
  582. localtime_r \
  583. lround \
  584. madvise \
  585. memmem \
  586. memset_s \
  587. minherit \
  588. mmap \
  589. pipe \
  590. pipe2 \
  591. prctl \
  592. readpassphrase \
  593. rint \
  594. sigaction \
  595. snprintf \
  596. socketpair \
  597. statvfs \
  598. strncasecmp \
  599. strcasecmp \
  600. strlcat \
  601. strlcpy \
  602. strnlen \
  603. strptime \
  604. strtok_r \
  605. strtoull \
  606. sysconf \
  607. sysctl \
  608. timegm \
  609. truncate \
  610. uname \
  611. usleep \
  612. vasprintf \
  613. _vscprintf \
  614. vsnprintf
  615. )
  616. # Apple messed up when they added some functions: they
  617. # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
  618. # checks.
  619. # We should only probe for these functions if we are sure that we
  620. # are not targeting OS X 10.9 or earlier.
  621. AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
  622. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  623. #ifdef __APPLE__
  624. # include <AvailabilityMacros.h>
  625. # ifndef MAC_OS_X_VERSION_10_10
  626. # define MAC_OS_X_VERSION_10_10 101000
  627. # endif
  628. # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
  629. # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
  630. # error "Running on Mac OS X 10.9 or earlier"
  631. # endif
  632. # endif
  633. #endif
  634. ]], [[]])],
  635. [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
  636. [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
  637. if test "$on_macos_pre_10_10" = "no"; then
  638. AC_CHECK_FUNCS(
  639. mach_approximate_time \
  640. )
  641. fi
  642. # We should only probe for these functions if we are sure that we
  643. # are not targeting OSX 10.11 or earlier.
  644. AC_MSG_CHECKING([for a pre-Sierra OSX build target])
  645. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  646. #ifdef __APPLE__
  647. # include <AvailabilityMacros.h>
  648. # ifndef MAC_OS_X_VERSION_10_12
  649. # define MAC_OS_X_VERSION_10_12 101200
  650. # endif
  651. # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
  652. # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
  653. # error "Running on Mac OSX 10.11 or earlier"
  654. # endif
  655. # endif
  656. #endif
  657. ]], [[]])],
  658. [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
  659. [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
  660. if test "$on_macos_pre_10_12" = "no"; then
  661. AC_CHECK_FUNCS(
  662. clock_gettime \
  663. getentropy \
  664. )
  665. fi
  666. if test "$bwin32" != "true"; then
  667. AC_CHECK_HEADERS(pthread.h)
  668. AC_CHECK_FUNCS(pthread_create)
  669. AC_CHECK_FUNCS(pthread_condattr_setclock)
  670. fi
  671. if test "$bwin32" = "true"; then
  672. AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
  673. #include <windows.h>
  674. #include <conio.h>
  675. #include <wchar.h>
  676. ])
  677. fi
  678. AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
  679. test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
  680. AC_CHECK_FUNCS(glob)
  681. AC_MSG_CHECKING([whether free(NULL) works])
  682. AC_RUN_IFELSE([AC_LANG_PROGRAM([
  683. #include <stdlib.h>
  684. ], [
  685. char *p = NULL;
  686. free(p);
  687. ])],
  688. [free_null_ok=true; AC_MSG_RESULT(yes)],
  689. [free_null_ok=false; AC_MSG_RESULT(no)],
  690. [free_null_ok=cross; AC_MSG_RESULT(cross)])
  691. if test "$free_null_ok" = "false"; then
  692. AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
  693. fi
  694. dnl ------------------------------------------------------
  695. dnl Where do you live, libevent? And how do we call you?
  696. if test "$bwin32" = "true"; then
  697. TOR_LIB_WS32=-lws2_32
  698. TOR_LIB_IPHLPAPI=-liphlpapi
  699. TOR_LIB_SHLWAPI=-lshlwapi
  700. TOR_LIB_GDI=-lgdi32
  701. TOR_LIB_USERENV=-luserenv
  702. TOR_LIB_BCRYPT=-lbcrypt
  703. TOR_LIB_CRYPT32=-lcrypt32
  704. else
  705. TOR_LIB_WS32=
  706. TOR_LIB_GDI=
  707. TOR_LIB_USERENV=
  708. fi
  709. AC_SUBST(TOR_LIB_WS32)
  710. AC_SUBST(TOR_LIB_GDI)
  711. AC_SUBST(TOR_LIB_IPHLPAPI)
  712. AC_SUBST(TOR_LIB_BCRYPT)
  713. AC_SUBST(TOR_LIB_CRYPT32)
  714. AC_SUBST(TOR_LIB_SHLWAPI)
  715. AC_SUBST(TOR_LIB_USERENV)
  716. tor_libevent_pkg_redhat="libevent"
  717. tor_libevent_pkg_debian="libevent-dev"
  718. tor_libevent_devpkg_redhat="libevent-devel"
  719. tor_libevent_devpkg_debian="libevent-dev"
  720. dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
  721. dnl linking for static builds.
  722. STATIC_LIBEVENT_FLAGS=""
  723. if test "$enable_static_libevent" = "yes"; then
  724. if test "$have_rt" = "yes"; then
  725. STATIC_LIBEVENT_FLAGS=" -lrt "
  726. fi
  727. fi
  728. TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_IPHLPAPI $TOR_LIB_BCRYPT $TOR_LIB_WS32], [
  729. #ifdef _WIN32
  730. #include <winsock2.h>
  731. #endif
  732. #include <sys/time.h>
  733. #include <sys/types.h>
  734. #include <event2/event.h>], [
  735. #ifdef _WIN32
  736. #include <winsock2.h>
  737. #endif
  738. struct event_base;
  739. struct event_base *event_base_new(void);
  740. void event_base_free(struct event_base *);],
  741. [
  742. #ifdef _WIN32
  743. {WSADATA d; WSAStartup(0x101,&d); }
  744. #endif
  745. event_base_free(event_base_new());
  746. ], [--with-libevent-dir], [/opt/libevent])
  747. dnl Determine the incantation needed to link libevent.
  748. save_LIBS="$LIBS"
  749. save_LDFLAGS="$LDFLAGS"
  750. save_CPPFLAGS="$CPPFLAGS"
  751. LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
  752. LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
  753. CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
  754. AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
  755. if test "$enable_static_libevent" = "yes"; then
  756. if test "$tor_cv_library_libevent_dir" = "(system)"; then
  757. AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
  758. else
  759. TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
  760. fi
  761. else
  762. if test "x$ac_cv_header_event2_event_h" = "xyes"; then
  763. AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
  764. AC_SEARCH_LIBS(evdns_base_new, [event event_extra], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for evdns_base_new"))
  765. if test "$ac_cv_search_event_new" != "none required"; then
  766. TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
  767. fi
  768. if test "$ac_cv_search_evdns_base_new" != "none required"; then
  769. TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
  770. fi
  771. else
  772. AC_MSG_ERROR("libevent2 is required but the headers could not be found")
  773. fi
  774. fi
  775. dnl Now check for particular libevent functions.
  776. AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
  777. evutil_secure_rng_add_bytes \
  778. evdns_base_get_nameserver_addr \
  779. ])
  780. LIBS="$save_LIBS"
  781. LDFLAGS="$save_LDFLAGS"
  782. CPPFLAGS="$save_CPPFLAGS"
  783. dnl Check that libevent is at least at version 2.0.10, the first stable
  784. dnl release of its series
  785. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
  786. AC_MSG_CHECKING([whether Libevent is new enough])
  787. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  788. #include <event2/event.h>
  789. #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
  790. #error
  791. int x = y(zz);
  792. #else
  793. int x = 1;
  794. #endif
  795. ])], [ AC_MSG_RESULT([yes]) ],
  796. [ AC_MSG_RESULT([no])
  797. AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
  798. LIBS="$save_LIBS"
  799. LDFLAGS="$save_LDFLAGS"
  800. CPPFLAGS="$save_CPPFLAGS"
  801. AC_SUBST(TOR_LIBEVENT_LIBS)
  802. dnl ------------------------------------------------------
  803. dnl Where do you live, libm?
  804. dnl On some platforms (Haiku/BeOS) the math library is
  805. dnl part of libroot. In which case don't link against lm
  806. TOR_LIB_MATH=""
  807. save_LIBS="$LIBS"
  808. AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
  809. if test "$ac_cv_search_pow" != "none required"; then
  810. TOR_LIB_MATH="$ac_cv_search_pow"
  811. fi
  812. LIBS="$save_LIBS"
  813. AC_SUBST(TOR_LIB_MATH)
  814. dnl ------------------------------------------------------
  815. dnl Hello, NSS. You're new around here.
  816. if test "x$enable_nss" = "xyes"; then
  817. PKG_CHECK_MODULES(NSS,
  818. [nss],
  819. [have_nss=yes],
  820. [have_nss=no; AC_MSG_ERROR([You asked for NSS but I can't find it, $pkg_config_user_action, or set NSS_CFLAGS and NSS_LIBS.])])
  821. AC_SUBST(NSS_CFLAGS)
  822. AC_SUBST(NSS_LIBS)
  823. fi
  824. dnl ------------------------------------------------------
  825. dnl Where do you live, openssl? And how do we call you?
  826. if test "x$enable_nss" != "xyes"; then
  827. tor_openssl_pkg_redhat="openssl"
  828. tor_openssl_pkg_debian="libssl-dev"
  829. tor_openssl_devpkg_redhat="openssl-devel"
  830. tor_openssl_devpkg_debian="libssl-dev"
  831. ALT_openssl_WITHVAL=""
  832. AC_ARG_WITH(ssl-dir,
  833. AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
  834. [
  835. if test "x$withval" != "xno" && test "x$withval" != "x"; then
  836. ALT_openssl_WITHVAL="$withval"
  837. fi
  838. ])
  839. AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
  840. TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32 $TOR_LIB_CRYPT32],
  841. [#include <openssl/ssl.h>
  842. char *getenv(const char *);],
  843. [struct ssl_cipher_st;
  844. unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
  845. char *getenv(const char *);],
  846. dnl This funny-looking test program calls getenv, so that the compiler
  847. dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
  848. dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
  849. dnl We look for SSL_cipher_get_id() because it is present in
  850. dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
  851. dnl depends on it.
  852. [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
  853. [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
  854. if test "$enable_static_openssl" = "yes"; then
  855. if test "$tor_cv_library_openssl_dir" = "(system)"; then
  856. AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
  857. else
  858. TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a $TOR_LIB_WS32 $TOR_LIB_CRYPT32 $TOR_LIB_BCRYPT"
  859. fi
  860. else
  861. TOR_OPENSSL_LIBS="-lssl -lcrypto"
  862. fi
  863. AC_SUBST(TOR_OPENSSL_LIBS)
  864. dnl Now validate openssl, and check for particular openssl functions.
  865. save_LIBS="$LIBS"
  866. save_LDFLAGS="$LDFLAGS"
  867. save_CPPFLAGS="$CPPFLAGS"
  868. LIBS="$TOR_OPENSSL_LIBS $LIBS"
  869. LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
  870. CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
  871. dnl Tor currently uses a number of APIs that are deprecated in OpenSSL 3.0.0
  872. dnl and later. We want to migrate away from them, but that will be a lot of
  873. dnl work. (See ticket tor#40166.) For now, we disable the deprecation
  874. dnl warnings.
  875. AC_MSG_CHECKING([for OpenSSL >= 3.0.0])
  876. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  877. #include <openssl/opensslv.h>
  878. #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x30000000L
  879. #error "you_have_version_3"
  880. #endif
  881. ]], [[]])],
  882. [ AC_MSG_RESULT([no]) ],
  883. [ AC_MSG_RESULT([yes]);
  884. AC_DEFINE(OPENSSL_SUPPRESS_DEPRECATED, 1, [disable openssl deprecated-function warnings]) ])
  885. AC_MSG_CHECKING([for OpenSSL < 1.0.1])
  886. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  887. #include <openssl/opensslv.h>
  888. #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
  889. #error "too old"
  890. #endif
  891. ]], [[]])],
  892. [ AC_MSG_RESULT([no]) ],
  893. [ AC_MSG_ERROR([OpenSSL is too old. We require 1.0.1 or later. You can specify a path to a newer one with --with-openssl-dir.]) ])
  894. AC_MSG_CHECKING([whether LibreSSL TLS 1.3 APIs are busted])
  895. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  896. #include <openssl/opensslv.h>
  897. #if defined(LIBRESSL_VERSION_NUMBER) && \
  898. LIBRESSL_VERSION_NUMBER >= 0x3020100fL && \
  899. LIBRESSL_VERSION_NUMBER < 0x3040100fL
  900. #error "oh no"
  901. #endif
  902. ]], [[]])],
  903. [ AC_MSG_RESULT([no]) ],
  904. [ AC_MSG_ERROR([This version of LibreSSL won't work with Tor. Please upgrade to LibreSSL 3.4.1 or later. (Or downgrade to 3.2.0 if you really must.)]) ])
  905. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  906. #include <openssl/opensslv.h>
  907. #include <openssl/evp.h>
  908. #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
  909. #error "no ECC"
  910. #endif
  911. #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
  912. #error "curves unavailable"
  913. #endif
  914. ]], [[]])],
  915. [ : ],
  916. [ AC_MSG_ERROR([OpenSSL is built without full ECC support, including curves P256 and P224. You can specify a path to one with ECC support with --with-openssl-dir.]) ])
  917. dnl Let's see if we have a version mismatch between includes and libs.
  918. AC_MSG_CHECKING([for significant mismatch between openssl headers and libraries])
  919. ac_retval=foo
  920. AC_RUN_IFELSE([AC_LANG_SOURCE([AC_LANG_PROGRAM([[
  921. #include <openssl/opensslv.h>
  922. #include <openssl/crypto.h>
  923. ]], [[
  924. /* Include major, minor, and fix, but not patch or status. */
  925. unsigned long mask = 0xfffff000;
  926. unsigned long linking = OpenSSL_version_num() & mask;
  927. unsigned long running = OPENSSL_VERSION_NUMBER & mask;
  928. return !(linking==running);
  929. ]])])], [openssl_ver_mismatch=no], [
  930. # This is a kludge to figure out whether compilation failed, or whether
  931. # running the program failed.
  932. if test "$ac_retval" = "1"; then
  933. openssl_ver_mismatch=inconclusive
  934. else
  935. openssl_ver_mismatch=yes
  936. fi], [openssl_ver_mismatch=cross])
  937. AC_MSG_RESULT([$openssl_ver_mismatch])
  938. AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
  939. [#include <openssl/ssl.h>
  940. ])
  941. dnl OpenSSL functions which we might not have. In theory, we could just
  942. dnl check the openssl version number, but in practice that gets pretty
  943. dnl confusing with LibreSSL, OpenSSL, and various distributions' patches
  944. dnl to them.
  945. AC_CHECK_FUNCS([ \
  946. ERR_load_KDF_strings \
  947. EVP_PBE_scrypt \
  948. SSL_CIPHER_find \
  949. SSL_CTX_set1_groups_list \
  950. SSL_CTX_set_security_level \
  951. SSL_SESSION_get_master_key \
  952. SSL_get_client_ciphers \
  953. SSL_get_client_random \
  954. SSL_get_server_random \
  955. TLS_method \
  956. ])
  957. dnl Check if OpenSSL structures are opaque
  958. AC_CHECK_MEMBERS([SSL.state], , ,
  959. [#include <openssl/ssl.h>
  960. ])
  961. AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
  962. #include <openssl/sha.h>
  963. ])
  964. fi # enable_nss
  965. dnl We will someday make KECCAK_TINY optional, but for now we still need
  966. dnl it for SHAKE, since OpenSSL's SHAKE can't be squeezed more than
  967. dnl once. See comment in the definition of crypto_xof_t.
  968. dnl AM_CONDITIONAL(BUILD_KECCAK_TINY,
  969. dnl test "x$ac_cv_func_EVP_sha3_256" != "xyes")
  970. AM_CONDITIONAL(BUILD_KECCAK_TINY, true)
  971. dnl ======================================================================
  972. dnl Can we use KIST?
  973. dnl Define the set of checks for KIST scheduler support.
  974. AC_DEFUN([CHECK_KIST_SUPPORT],[
  975. dnl KIST needs struct tcp_info and for certain members to exist.
  976. AC_CHECK_MEMBERS(
  977. [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
  978. , ,[[#include <netinet/tcp.h>]])
  979. dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
  980. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  981. #include <linux/sockios.h>
  982. #ifndef SIOCOUTQNSD
  983. #error
  984. #endif
  985. ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
  986. if test "x$have_siocoutqnsd" = "xyes"; then
  987. if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
  988. if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
  989. have_kist_support=yes
  990. fi
  991. fi
  992. fi
  993. ])
  994. dnl Now, trigger the check.
  995. CHECK_KIST_SUPPORT
  996. AS_IF([test "x$have_kist_support" = "xyes"],
  997. [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
  998. on this system])],
  999. [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
  1000. LIBS="$save_LIBS"
  1001. LDFLAGS="$save_LDFLAGS"
  1002. CPPFLAGS="$save_CPPFLAGS"
  1003. dnl ------------------------------------------------------
  1004. dnl Where do you live, zlib? And how do we call you?
  1005. tor_zlib_pkg_redhat="zlib"
  1006. tor_zlib_pkg_debian="zlib1g"
  1007. tor_zlib_devpkg_redhat="zlib-devel"
  1008. tor_zlib_devpkg_debian="zlib1g-dev"
  1009. TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
  1010. [#include <zlib.h>],
  1011. [const char * zlibVersion(void);],
  1012. [zlibVersion();], [--with-zlib-dir],
  1013. [/opt/zlib])
  1014. if test "$enable_static_zlib" = "yes"; then
  1015. if test "$tor_cv_library_zlib_dir" = "(system)"; then
  1016. AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
  1017. using --enable-static-zlib")
  1018. else
  1019. TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
  1020. fi
  1021. else
  1022. TOR_ZLIB_LIBS="-lz"
  1023. fi
  1024. AC_SUBST(TOR_ZLIB_LIBS)
  1025. dnl ------------------------------------------------------
  1026. dnl Where we do we find lzma?
  1027. AC_ARG_ENABLE(lzma,
  1028. AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
  1029. [case "${enableval}" in
  1030. "yes") ;;
  1031. "no") ;;
  1032. * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
  1033. esac], [enable_lzma=auto])
  1034. if test "x$enable_lzma" = "xno"; then
  1035. have_lzma=no;
  1036. else
  1037. PKG_CHECK_MODULES([LZMA],
  1038. [liblzma],
  1039. have_lzma=yes,
  1040. have_lzma=no)
  1041. if test "x$have_lzma" = "xno" ; then
  1042. tor_incr_n_warnings
  1043. AC_MSG_WARN([Unable to find liblzma, $pkg_config_user_action, or set LZMA_CFLAGS and LZMA_LIBS.])
  1044. fi
  1045. fi
  1046. if test "x$have_lzma" = "xyes"; then
  1047. AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
  1048. TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
  1049. TOR_LZMA_LIBS="${LZMA_LIBS}"
  1050. fi
  1051. AC_SUBST(TOR_LZMA_CFLAGS)
  1052. AC_SUBST(TOR_LZMA_LIBS)
  1053. dnl ------------------------------------------------------
  1054. dnl Where we do we find zstd?
  1055. AC_ARG_ENABLE(zstd,
  1056. AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
  1057. [case "${enableval}" in
  1058. "yes") ;;
  1059. "no") ;;
  1060. * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
  1061. esac], [enable_zstd=auto])
  1062. if test "x$enable_zstd" = "xno"; then
  1063. have_zstd=no;
  1064. else
  1065. PKG_CHECK_MODULES([ZSTD],
  1066. [libzstd >= 1.1],
  1067. have_zstd=yes,
  1068. have_zstd=no)
  1069. if test "x$have_zstd" = "xno" ; then
  1070. tor_incr_n_warnings
  1071. AC_MSG_WARN([Unable to find libzstd, $pkg_config_user_action, or set ZSTD_CFLAGS and ZSTD_LIBS.])
  1072. fi
  1073. fi
  1074. if test "x$have_zstd" = "xyes"; then
  1075. AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
  1076. TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
  1077. TOR_ZSTD_LIBS="${ZSTD_LIBS}"
  1078. dnl now check for zstd functions
  1079. save_LIBS="$LIBS"
  1080. save_CFLAGS="$CFLAGS"
  1081. LIBS="$LIBS $ZSTD_LIBS"
  1082. CFLAGS="$CFLAGS $ZSTD_CFLAGS"
  1083. AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
  1084. ZSTD_estimateDCtxSize)
  1085. LIBS="$save_LIBS"
  1086. CFLAGS="$save_CFLAGS"
  1087. fi
  1088. AC_SUBST(TOR_ZSTD_CFLAGS)
  1089. AC_SUBST(TOR_ZSTD_LIBS)
  1090. dnl ----------------------------------------------------------------------
  1091. dnl Check if libcap is available for capabilities.
  1092. tor_cap_pkg_debian="libcap2"
  1093. tor_cap_pkg_redhat="libcap"
  1094. tor_cap_devpkg_debian="libcap-dev"
  1095. tor_cap_devpkg_redhat="libcap-devel"
  1096. AC_CHECK_LIB([cap], [cap_init], [],
  1097. AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
  1098. )
  1099. AC_CHECK_FUNCS(cap_set_proc)
  1100. dnl ---------------------------------------------------------------------
  1101. dnl Now that we know about our major libraries, we can check for compiler
  1102. dnl and linker hardening options. We need to do this with the libraries known,
  1103. dnl since sometimes the linker will like an option but not be willing to
  1104. dnl use it with a build of a library.
  1105. all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
  1106. all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_SYSTEMD_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI $TOR_LIB_USERENV $TOR_CAP_LIBS"
  1107. CFLAGS_FTRAPV=
  1108. CFLAGS_FWRAPV=
  1109. CFLAGS_ASAN=
  1110. CFLAGS_UBSAN=
  1111. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
  1112. #if !defined(__clang__)
  1113. #error
  1114. #endif])], have_clang=yes, have_clang=no)
  1115. if test "x$enable_pic" = "xyes"; then
  1116. TOR_CHECK_CFLAGS(-fPIC)
  1117. fi
  1118. if test "x$enable_gcc_hardening" != "xno"; then
  1119. CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
  1120. if test "x$have_clang" = "xyes"; then
  1121. TOR_CHECK_CFLAGS(-Qunused-arguments)
  1122. fi
  1123. TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
  1124. AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
  1125. AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
  1126. m4_ifdef([AS_VAR_IF],[
  1127. AS_VAR_IF(can_compile, [yes],
  1128. AS_VAR_IF(can_link, [yes],
  1129. [],
  1130. AC_MSG_ERROR([We tried to build with stack protection; it looks like your compiler supports it but your libc does not provide it. Are you missing libssp? (You can --disable-gcc-hardening to ignore this error.)]))
  1131. )])
  1132. AS_VAR_POPDEF([can_link])
  1133. AS_VAR_POPDEF([can_compile])
  1134. TOR_CHECK_CFLAGS(-Wstack-protector)
  1135. TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
  1136. if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
  1137. if test "$enable_pic" != "yes"; then
  1138. # If we have already enabled -fPIC, then we don't also need to
  1139. # compile with -fPIE...
  1140. TOR_CHECK_CFLAGS(-fPIE)
  1141. fi
  1142. # ... but we want to link our executables with -pie in any case, since
  1143. # they're executables, not a library.
  1144. TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
  1145. fi
  1146. TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
  1147. AC_MSG_CHECKING([whether we can run hardened binaries])
  1148. AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
  1149. [AC_MSG_RESULT([yes])],
  1150. [AC_MSG_RESULT([no])
  1151. AC_MSG_ERROR([dnl
  1152. We can link with compiler hardening options, but we can't run with them.
  1153. That's a bad sign! If you must, you can pass --disable-gcc-hardening to
  1154. configure, but it would be better to figure out what the underlying problem
  1155. is.])],
  1156. [AC_MSG_RESULT([cross])])
  1157. fi
  1158. if test "$fragile_hardening" = "yes"; then
  1159. TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
  1160. if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
  1161. tor_incr_n_warnings
  1162. AC_MSG_WARN([The compiler supports -ftrapv, but for some reason I was not able to link with -ftrapv. Are you missing run-time support? Run-time hardening will not work as well as it should.])
  1163. fi
  1164. if test "$tor_cv_cflags__ftrapv" != "yes"; then
  1165. AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
  1166. fi
  1167. TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
  1168. if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
  1169. AC_MSG_ERROR([The compiler supports -fsanitize=address, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libubsan.*, and with Clang you need libclang_rt.ubsan*])
  1170. fi
  1171. TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
  1172. if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
  1173. AC_MSG_ERROR([The compiler supports -fsanitize=undefined, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libasan.*, and with Clang you need libclang_rt.ubsan*])
  1174. fi
  1175. TOR_TRY_COMPILE_WITH_CFLAGS([-fno-sanitize=float-divide-by-zero], also_link, CFLAGS_UBSAN="-fno-sanitize=float-divide-by-zero", true)
  1176. if test "$tor_cv_cflags__fno_sanitize_float_divide_by_zero" = "yes" && test "$tor_can_link__fno_sanitize_float_divide_by_zero" != "yes"; then
  1177. AC_MSG_ERROR([The compiler supports -fno-sanitize=float-divide-by-zero, but for some reason I was not able to link when using it. Are you missing run-time support? With GCC you need libasan.*, and with Clang you need libclang_rt.ubsan*])
  1178. fi
  1179. TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
  1180. fi
  1181. CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
  1182. CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
  1183. mulodi_fixes_ftrapv=no
  1184. if test "$have_clang" = "yes"; then
  1185. saved_CFLAGS="$CFLAGS"
  1186. CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
  1187. AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
  1188. AC_LINK_IFELSE([
  1189. AC_LANG_SOURCE([[
  1190. #include <stdint.h>
  1191. #include <stdlib.h>
  1192. int main(int argc, char **argv)
  1193. {
  1194. int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
  1195. * (int64_t)atoi(argv[3]);
  1196. return x == 9;
  1197. } ]])],
  1198. [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
  1199. [ftrapv_can_link=no; AC_MSG_RESULT([no])])
  1200. if test "$ftrapv_can_link" = "no"; then
  1201. AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
  1202. AC_LINK_IFELSE([
  1203. AC_LANG_SOURCE([[
  1204. #include <stdint.h>
  1205. #include <stdlib.h>
  1206. int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
  1207. *overflow=0;
  1208. return a;
  1209. }
  1210. int main(int argc, char **argv)
  1211. {
  1212. int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
  1213. * (int64_t)atoi(argv[3]);
  1214. return x == 9;
  1215. } ]])],
  1216. [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
  1217. [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
  1218. fi
  1219. CFLAGS="$saved_CFLAGS"
  1220. fi
  1221. AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
  1222. dnl These cflags add bunches of branches, and we haven't been able to
  1223. dnl persuade ourselves that they're suitable for code that needs to be
  1224. dnl constant time.
  1225. AC_SUBST(CFLAGS_BUGTRAP)
  1226. dnl These cflags are variant ones suitable for code that needs to be
  1227. dnl constant-time.
  1228. AC_SUBST(CFLAGS_CONSTTIME)
  1229. if test "x$enable_linker_hardening" != "xno"; then
  1230. TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
  1231. fi
  1232. # For backtrace support
  1233. TOR_CHECK_LDFLAGS(-rdynamic)
  1234. dnl ------------------------------------------------------
  1235. dnl Now see if we have a -fomit-frame-pointer compiler option.
  1236. saved_CFLAGS="$CFLAGS"
  1237. TOR_CHECK_CFLAGS(-fomit-frame-pointer)
  1238. F_OMIT_FRAME_POINTER=''
  1239. if test "$saved_CFLAGS" != "$CFLAGS"; then
  1240. if test "$fragile_hardening" = "yes"; then
  1241. F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
  1242. fi
  1243. fi
  1244. CFLAGS="$saved_CFLAGS"
  1245. AC_SUBST(F_OMIT_FRAME_POINTER)
  1246. dnl ------------------------------------------------------
  1247. dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
  1248. dnl for us, as GCC 4.6 and later do at many optimization levels), then
  1249. dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
  1250. dnl code will work.
  1251. TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
  1252. dnl ============================================================
  1253. dnl Check for libseccomp
  1254. if test "x$enable_seccomp" != "xno"; then
  1255. AC_CHECK_HEADERS([seccomp.h])
  1256. AC_SEARCH_LIBS(seccomp_init, [seccomp])
  1257. fi
  1258. dnl ============================================================
  1259. dnl Check for libscrypt
  1260. if test "x$enable_libscrypt" != "xno"; then
  1261. AC_CHECK_HEADERS([libscrypt.h])
  1262. AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
  1263. AC_CHECK_FUNCS([libscrypt_scrypt])
  1264. fi
  1265. dnl ============================================================
  1266. dnl We need an implementation of curve25519.
  1267. dnl set these defaults.
  1268. build_curve25519_donna=no
  1269. build_curve25519_donna_c64=no
  1270. use_curve25519_donna=no
  1271. use_curve25519_nacl=no
  1272. CURVE25519_LIBS=
  1273. dnl The best choice is using curve25519-donna-c64, but that requires
  1274. dnl that we
  1275. AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
  1276. tor_cv_can_use_curve25519_donna_c64,
  1277. [AC_RUN_IFELSE(
  1278. [AC_LANG_PROGRAM([dnl
  1279. #include <stdint.h>
  1280. typedef unsigned uint128_t __attribute__((mode(TI)));
  1281. int func(uint64_t a, uint64_t b) {
  1282. uint128_t c = ((uint128_t)a) * b;
  1283. int ok = ((uint64_t)(c>>96)) == 522859 &&
  1284. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  1285. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  1286. (((uint64_t)(c))&0xffffffffL) == 0;
  1287. return ok;
  1288. }
  1289. ], [dnl
  1290. int ok = func( ((uint64_t)2000000000) * 1000000000,
  1291. ((uint64_t)1234567890) << 24);
  1292. return !ok;
  1293. ])],
  1294. [tor_cv_can_use_curve25519_donna_c64=yes],
  1295. [tor_cv_can_use_curve25519_donna_c64=no],
  1296. [AC_LINK_IFELSE(
  1297. [AC_LANG_PROGRAM([dnl
  1298. #include <stdint.h>
  1299. typedef unsigned uint128_t __attribute__((mode(TI)));
  1300. int func(uint64_t a, uint64_t b) {
  1301. uint128_t c = ((uint128_t)a) * b;
  1302. int ok = ((uint64_t)(c>>96)) == 522859 &&
  1303. (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
  1304. (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
  1305. (((uint64_t)(c))&0xffffffffL) == 0;
  1306. return ok;
  1307. }
  1308. ], [dnl
  1309. int ok = func( ((uint64_t)2000000000) * 1000000000,
  1310. ((uint64_t)1234567890) << 24);
  1311. return !ok;
  1312. ])],
  1313. [tor_cv_can_use_curve25519_donna_c64=cross],
  1314. [tor_cv_can_use_curve25519_donna_c64=no])])])
  1315. AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
  1316. nacl/crypto_scalarmult_curve25519.h])
  1317. AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
  1318. tor_cv_can_use_curve25519_nacl,
  1319. [tor_saved_LIBS="$LIBS"
  1320. LIBS="$LIBS -lnacl"
  1321. AC_LINK_IFELSE(
  1322. [AC_LANG_PROGRAM([dnl
  1323. #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
  1324. #include <crypto_scalarmult_curve25519.h>
  1325. #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
  1326. #include <nacl/crypto_scalarmult_curve25519.h>
  1327. #endif
  1328. #ifdef crypto_scalarmult_curve25519_ref_BYTES
  1329. #error Hey, this is the reference implementation! That's not fast.
  1330. #endif
  1331. ], [
  1332. unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
  1333. ])], [tor_cv_can_use_curve25519_nacl=yes],
  1334. [tor_cv_can_use_curve25519_nacl=no])
  1335. LIBS="$tor_saved_LIBS" ])
  1336. dnl Okay, now we need to figure out which one to actually use. Fall back
  1337. dnl to curve25519-donna.c
  1338. if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
  1339. build_curve25519_donna_c64=yes
  1340. use_curve25519_donna=yes
  1341. elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
  1342. use_curve25519_nacl=yes
  1343. CURVE25519_LIBS=-lnacl
  1344. else
  1345. build_curve25519_donna=yes
  1346. use_curve25519_donna=yes
  1347. fi
  1348. if test "x$use_curve25519_donna" = "xyes"; then
  1349. AC_DEFINE(USE_CURVE25519_DONNA, 1,
  1350. [Defined if we should use an internal curve25519_donna{,_c64} implementation])
  1351. fi
  1352. if test "x$use_curve25519_nacl" = "xyes"; then
  1353. AC_DEFINE(USE_CURVE25519_NACL, 1,
  1354. [Defined if we should use a curve25519 from nacl])
  1355. fi
  1356. AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
  1357. test "x$build_curve25519_donna" = "xyes")
  1358. AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
  1359. test "x$build_curve25519_donna_c64" = "xyes")
  1360. AC_SUBST(CURVE25519_LIBS)
  1361. dnl Make sure to enable support for large off_t if available.
  1362. AC_SYS_LARGEFILE
  1363. AC_CHECK_HEADERS([errno.h \
  1364. fcntl.h \
  1365. signal.h \
  1366. string.h \
  1367. sys/capability.h \
  1368. sys/fcntl.h \
  1369. sys/stat.h \
  1370. sys/time.h \
  1371. sys/types.h \
  1372. time.h \
  1373. unistd.h \
  1374. arpa/inet.h \
  1375. crt_externs.h \
  1376. execinfo.h \
  1377. gnu/libc-version.h \
  1378. grp.h \
  1379. ifaddrs.h \
  1380. inttypes.h \
  1381. limits.h \
  1382. linux/types.h \
  1383. mach/vm_inherit.h \
  1384. machine/limits.h \
  1385. malloc.h \
  1386. netdb.h \
  1387. netinet/in.h \
  1388. netinet/in6.h \
  1389. pwd.h \
  1390. readpassphrase.h \
  1391. stdatomic.h \
  1392. sys/eventfd.h \
  1393. sys/file.h \
  1394. sys/ioctl.h \
  1395. sys/limits.h \
  1396. sys/mman.h \
  1397. sys/param.h \
  1398. sys/prctl.h \
  1399. sys/random.h \
  1400. sys/resource.h \
  1401. sys/select.h \
  1402. sys/socket.h \
  1403. sys/statvfs.h \
  1404. sys/syscall.h \
  1405. sys/sysctl.h \
  1406. sys/time.h \
  1407. sys/types.h \
  1408. sys/un.h \
  1409. sys/utime.h \
  1410. sys/wait.h \
  1411. syslog.h \
  1412. utime.h \
  1413. glob.h])
  1414. AC_CHECK_HEADERS(sys/param.h)
  1415. AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
  1416. [#ifdef HAVE_SYS_TYPES_H
  1417. #include <sys/types.h>
  1418. #endif
  1419. #ifdef HAVE_SYS_SOCKET_H
  1420. #include <sys/socket.h>
  1421. #endif])
  1422. AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
  1423. [#ifdef HAVE_SYS_TYPES_H
  1424. #include <sys/types.h>
  1425. #endif
  1426. #ifdef HAVE_SYS_SOCKET_H
  1427. #include <sys/socket.h>
  1428. #endif
  1429. #ifdef HAVE_NET_IF_H
  1430. #include <net/if.h>
  1431. #endif
  1432. #ifdef HAVE_NETINET_IN_H
  1433. #include <netinet/in.h>
  1434. #endif])
  1435. AC_CHECK_HEADERS(linux/if.h,[],[],
  1436. [
  1437. #ifdef HAVE_SYS_SOCKET_H
  1438. #include <sys/socket.h>
  1439. #endif
  1440. ])
  1441. AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
  1442. linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
  1443. [#ifdef HAVE_SYS_TYPES_H
  1444. #include <sys/types.h>
  1445. #endif
  1446. #ifdef HAVE_SYS_SOCKET_H
  1447. #include <sys/socket.h>
  1448. #endif
  1449. #ifdef HAVE_LIMITS_H
  1450. #include <limits.h>
  1451. #endif
  1452. #ifdef HAVE_LINUX_TYPES_H
  1453. #include <linux/types.h>
  1454. #endif
  1455. #ifdef HAVE_NETINET_IN6_H
  1456. #include <netinet/in6.h>
  1457. #endif
  1458. #ifdef HAVE_NETINET_IN_H
  1459. #include <netinet/in.h>
  1460. #endif])
  1461. AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
  1462. linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
  1463. [#ifdef HAVE_SYS_TYPES_H
  1464. #include <sys/types.h>
  1465. #endif
  1466. #ifdef HAVE_SYS_SOCKET_H
  1467. #include <sys/socket.h>
  1468. #endif
  1469. #ifdef HAVE_LIMITS_H
  1470. #include <limits.h>
  1471. #endif
  1472. #ifdef HAVE_LINUX_TYPES_H
  1473. #include <linux/types.h>
  1474. #endif
  1475. #ifdef HAVE_NETINET_IN6_H
  1476. #include <netinet/in6.h>
  1477. #endif
  1478. #ifdef HAVE_NETINET_IN_H
  1479. #include <netinet/in.h>
  1480. #endif
  1481. #ifdef HAVE_LINUX_IF_H
  1482. #include <linux/if.h>
  1483. #endif])
  1484. transparent_ok=0
  1485. if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
  1486. transparent_ok=1
  1487. fi
  1488. if test "x$linux_netfilter_ipv4" = "x1"; then
  1489. transparent_ok=1
  1490. fi
  1491. if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
  1492. transparent_ok=1
  1493. fi
  1494. if test "x$transparent_ok" = "x1"; then
  1495. AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
  1496. else
  1497. AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
  1498. fi
  1499. AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
  1500. [#ifdef HAVE_SYS_TYPES_H
  1501. #include <sys/types.h>
  1502. #endif
  1503. #ifdef HAVE_SYS_TIME_H
  1504. #include <sys/time.h>
  1505. #endif])
  1506. AC_CHECK_SIZEOF(char)
  1507. AC_CHECK_SIZEOF(short)
  1508. AC_CHECK_SIZEOF(int)
  1509. AC_CHECK_SIZEOF(unsigned int)
  1510. AC_CHECK_SIZEOF(long)
  1511. AC_CHECK_SIZEOF(long long)
  1512. AC_CHECK_SIZEOF(__int64)
  1513. AC_CHECK_SIZEOF(void *)
  1514. AC_CHECK_SIZEOF(time_t)
  1515. AC_CHECK_SIZEOF(size_t)
  1516. AC_CHECK_SIZEOF(pid_t)
  1517. AC_CHECK_TYPES([uint, u_char, ssize_t])
  1518. AC_PC_FROM_UCONTEXT([:])
  1519. dnl used to include sockaddr_storage, but everybody has that.
  1520. AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
  1521. [#ifdef HAVE_SYS_TYPES_H
  1522. #include <sys/types.h>
  1523. #endif
  1524. #ifdef HAVE_NETINET_IN_H
  1525. #include <netinet/in.h>
  1526. #endif
  1527. #ifdef HAVE_NETINET_IN6_H
  1528. #include <netinet/in6.h>
  1529. #endif
  1530. #ifdef HAVE_SYS_SOCKET_H
  1531. #include <sys/socket.h>
  1532. #endif
  1533. #ifdef _WIN32
  1534. #define _WIN32_WINNT 0x0501
  1535. #define WIN32_LEAN_AND_MEAN
  1536. #include <winsock2.h>
  1537. #include <ws2tcpip.h>
  1538. #endif
  1539. ])
  1540. AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
  1541. [#ifdef HAVE_SYS_TYPES_H
  1542. #include <sys/types.h>
  1543. #endif
  1544. #ifdef HAVE_NETINET_IN_H
  1545. #include <netinet/in.h>
  1546. #endif
  1547. #ifdef HAVE_NETINET_IN6_H
  1548. #include <netinet/in6.h>
  1549. #endif
  1550. #ifdef HAVE_SYS_SOCKET_H
  1551. #include <sys/socket.h>
  1552. #endif
  1553. #ifdef _WIN32
  1554. #define _WIN32_WINNT 0x0501
  1555. #define WIN32_LEAN_AND_MEAN
  1556. #include <winsock2.h>
  1557. #include <ws2tcpip.h>
  1558. #endif
  1559. ])
  1560. AC_CHECK_TYPES([rlim_t], , ,
  1561. [#ifdef HAVE_SYS_TYPES_H
  1562. #include <sys/types.h>
  1563. #endif
  1564. #ifdef HAVE_SYS_TIME_H
  1565. #include <sys/time.h>
  1566. #endif
  1567. #ifdef HAVE_SYS_RESOURCE_H
  1568. #include <sys/resource.h>
  1569. #endif
  1570. ])
  1571. AX_CHECK_SIGN([time_t],
  1572. [ : ],
  1573. [ : ], [
  1574. #ifdef HAVE_SYS_TYPES_H
  1575. #include <sys/types.h>
  1576. #endif
  1577. #ifdef HAVE_SYS_TIME_H
  1578. #include <sys/time.h>
  1579. #endif
  1580. #ifdef HAVE_TIME_H
  1581. #include <time.h>
  1582. #endif
  1583. ])
  1584. if test "$ax_cv_decl_time_t_signed" = "no"; then
  1585. AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
  1586. fi
  1587. AX_CHECK_SIGN([size_t],
  1588. [ tor_cv_size_t_signed=yes ],
  1589. [ tor_cv_size_t_signed=no ], [
  1590. #ifdef HAVE_SYS_TYPES_H
  1591. #include <sys/types.h>
  1592. #endif
  1593. ])
  1594. if test "$ax_cv_decl_size_t_signed" = "yes"; then
  1595. AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
  1596. fi
  1597. AX_CHECK_SIGN([enum always],
  1598. [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
  1599. [ : ], [
  1600. enum always { AAA, BBB, CCC };
  1601. ])
  1602. AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
  1603. #ifdef HAVE_SYS_SOCKET_H
  1604. #include <sys/socket.h>
  1605. #endif
  1606. ])
  1607. # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
  1608. AC_CHECK_SIZEOF(cell_t)
  1609. # Let's see if stdatomic works. (There are some debian clangs that screw it
  1610. # up; see Tor bug #26779 and debian bug 903709.)
  1611. AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
  1612. tor_cv_stdatomic_works,
  1613. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  1614. #include <stdatomic.h>
  1615. struct x { atomic_size_t y; };
  1616. void try_atomic_init(struct x *xx)
  1617. {
  1618. atomic_init(&xx->y, 99);
  1619. atomic_fetch_add(&xx->y, 1);
  1620. }
  1621. ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
  1622. if test "$tor_cv_stdatomic_works" = "yes"; then
  1623. AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
  1624. elif test "$ac_cv_header_stdatomic_h" = "yes"; then
  1625. tor_incr_n_warnings
  1626. AC_MSG_WARN([Your compiler provides the stdatomic.h header, but it doesn't seem to work. I'll pretend it isn't there. If you are using Clang on Debian, maybe this is because of https://bugs.debian.org/903709 ])
  1627. fi
  1628. # Now make sure that NULL can be represented as zero bytes.
  1629. AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
  1630. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1631. [[#include <stdlib.h>
  1632. #include <string.h>
  1633. #include <stdio.h>
  1634. #ifdef HAVE_STDDEF_H
  1635. #include <stddef.h>
  1636. #endif
  1637. int main (void) { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
  1638. return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
  1639. [tor_cv_null_is_zero=yes],
  1640. [tor_cv_null_is_zero=no],
  1641. [tor_cv_null_is_zero=cross])])
  1642. if test "$tor_cv_null_is_zero" = "cross"; then
  1643. # Cross-compiling; let's hope that the target isn't raving mad.
  1644. AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
  1645. fi
  1646. if test "$tor_cv_null_is_zero" != "no"; then
  1647. AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
  1648. [Define to 1 iff memset(0) sets pointers to NULL])
  1649. fi
  1650. AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
  1651. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1652. [[#include <stdlib.h>
  1653. #include <string.h>
  1654. #include <stdio.h>
  1655. #ifdef HAVE_STDDEF_H
  1656. #include <stddef.h>
  1657. #endif
  1658. int main (void) { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
  1659. return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
  1660. [tor_cv_dbl0_is_zero=yes],
  1661. [tor_cv_dbl0_is_zero=no],
  1662. [tor_cv_dbl0_is_zero=cross])])
  1663. if test "$tor_cv_dbl0_is_zero" = "cross"; then
  1664. # Cross-compiling; let's hope that the target isn't raving mad.
  1665. AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
  1666. fi
  1667. if test "$tor_cv_dbl0_is_zero" != "no"; then
  1668. AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
  1669. [Define to 1 iff memset(0) sets doubles to 0.0])
  1670. fi
  1671. # And what happens when we malloc zero?
  1672. AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
  1673. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1674. [[#include <stdlib.h>
  1675. #include <string.h>
  1676. #include <stdio.h>
  1677. #ifdef HAVE_STDDEF_H
  1678. #include <stddef.h>
  1679. #endif
  1680. int main (void) { return malloc(0)?0:1; }]])],
  1681. [tor_cv_malloc_zero_works=yes],
  1682. [tor_cv_malloc_zero_works=no],
  1683. [tor_cv_malloc_zero_works=cross])])
  1684. if test "$tor_cv_malloc_zero_works" = "cross"; then
  1685. # Cross-compiling; let's hope that the target isn't raving mad.
  1686. AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
  1687. fi
  1688. if test "$tor_cv_malloc_zero_works" = "yes"; then
  1689. AC_DEFINE([MALLOC_ZERO_WORKS], 1,
  1690. [Define to 1 iff malloc(0) returns a pointer])
  1691. fi
  1692. # whether we seem to be in a 2s-complement world.
  1693. AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
  1694. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1695. [[int main (void) { int problem = ((-99) != (~99)+1);
  1696. return problem ? 1 : 0; }]])],
  1697. [tor_cv_twos_complement=yes],
  1698. [tor_cv_twos_complement=no],
  1699. [tor_cv_twos_complement=cross])])
  1700. if test "$tor_cv_twos_complement" = "cross"; then
  1701. # Cross-compiling; let's hope that the target isn't raving mad.
  1702. AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
  1703. fi
  1704. if test "$tor_cv_twos_complement" != "no"; then
  1705. AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
  1706. [Define to 1 iff we represent negative integers with
  1707. two's complement])
  1708. fi
  1709. # What does shifting a negative value do?
  1710. AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
  1711. [AC_RUN_IFELSE([AC_LANG_SOURCE(
  1712. [[int main (void) { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
  1713. [tor_cv_sign_extend=yes],
  1714. [tor_cv_sign_extend=no],
  1715. [tor_cv_sign_extend=cross])])
  1716. if test "$tor_cv_sign_extend" = "cross"; then
  1717. # Cross-compiling; let's hope that the target isn't raving mad.
  1718. AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
  1719. fi
  1720. if test "$tor_cv_sign_extend" != "no"; then
  1721. AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
  1722. [Define to 1 iff right-shifting a negative value performs sign-extension])
  1723. fi
  1724. # Is uint8_t the same type as unsigned char?
  1725. AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
  1726. [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  1727. #include <stdint.h>
  1728. extern uint8_t c;
  1729. unsigned char c;]])],
  1730. [tor_cv_uint8_uchar=yes],
  1731. [tor_cv_uint8_uchar=no],
  1732. [tor_cv_uint8_uchar=cross])])
  1733. if test "$tor_cv_uint8_uchar" = "cross"; then
  1734. AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
  1735. fi
  1736. if test "$tor_cv_uint8_uchar" = "no"; then
  1737. AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
  1738. fi
  1739. AC_ARG_WITH(tcmalloc,
  1740. AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library. Deprecated; see --with-malloc]))
  1741. default_malloc=system
  1742. if test "x$enable_openbsd_malloc" = "xyes" ; then
  1743. AC_MSG_NOTICE([The --enable-openbsd-malloc argument is deprecated; use --with-malloc=openbsd instead.])
  1744. default_malloc=openbsd
  1745. fi
  1746. if test "x$with_tcmalloc" = "xyes"; then
  1747. AC_MSG_NOTICE([The --with-tcmalloc argument is deprecated; use --with-malloc=tcmalloc instead.])
  1748. default_malloc=tcmalloc
  1749. fi
  1750. AC_ARG_WITH(malloc,
  1751. AS_HELP_STRING([--with-malloc=[system,jemalloc,tcmalloc,openbsd]],
  1752. [select special malloc implementation [system]]),
  1753. [ malloc="$with_malloc" ], [ malloc="$default_malloc" ])
  1754. AS_CASE([$malloc],
  1755. [tcmalloc], [
  1756. PKG_CHECK_MODULES([TCMALLOC],
  1757. [libtcmalloc],
  1758. have_tcmalloc=yes,
  1759. have_tcmalloc=no)
  1760. if test "x$have_tcmalloc" = "xno" ; then
  1761. AC_MSG_ERROR([Unable to find tcmalloc requested by --with-malloc, $pkg_config_user_action, or set TCMALLOC_CFLAGS and TCMALLOC_LIBS.])
  1762. fi
  1763. CFLAGS="$CFLAGS $TCMALLOC_CFLAGS"
  1764. LIBS="$TCMALLOC_LIBS $LIBS"
  1765. ],
  1766. [jemalloc], [
  1767. PKG_CHECK_MODULES([JEMALLOC],
  1768. [jemalloc],
  1769. have_jemalloc=yes,
  1770. have_jemalloc=no)
  1771. if test "x$have_jemalloc" = "xno" ; then
  1772. AC_MSG_ERROR([Unable to find jemalloc requested by --with-malloc, $pkg_config_user_action, or set JEMALLOC_CFLAGS and JEMALLOC_LIBS.])
  1773. fi
  1774. CFLAGS="$CFLAGS $JEMALLOC_CFLAGS"
  1775. LIBS="$JEMALLOC_LIBS $LIBS"
  1776. using_custom_malloc=yes
  1777. ],
  1778. [openbsd], [
  1779. tor_incr_n_warnings
  1780. AC_MSG_WARN([The openbsd malloc port is deprecated in Tor 0.3.5 and will be removed in a future version.])
  1781. enable_openbsd_malloc=yes
  1782. ],
  1783. [system], [
  1784. # handle this later, including the jemalloc fallback
  1785. ],
  1786. [AC_MSG_ERROR([--with-malloc=`$with_malloc' not supported, see --help])
  1787. ])
  1788. AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
  1789. if test "$malloc" != "system"; then
  1790. # Tell the C compiler not to use the system allocator functions.
  1791. TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
  1792. fi
  1793. if test "$using_custom_malloc" = "yes"; then
  1794. # Tell the C compiler not to use the system allocator functions.
  1795. TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
  1796. fi
  1797. # By default, we're going to assume we don't have mlockall()
  1798. # bionic and other platforms have various broken mlockall subsystems.
  1799. # Some systems don't have a working mlockall, some aren't linkable,
  1800. # and some have it but don't declare it.
  1801. AC_CHECK_FUNCS(mlockall)
  1802. AC_CHECK_DECLS([mlockall], , , [
  1803. #ifdef HAVE_SYS_MMAN_H
  1804. #include <sys/mman.h>
  1805. #endif])
  1806. # Allow user to specify an alternate syslog facility
  1807. AC_ARG_WITH(syslog-facility,
  1808. AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
  1809. syslog_facility="$withval", syslog_facility="LOG_DAEMON")
  1810. AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
  1811. AC_SUBST(LOGFACILITY)
  1812. # Check if we have getresuid and getresgid
  1813. AC_CHECK_FUNCS(getresuid getresgid)
  1814. # Check for gethostbyname_r in all its glorious incompatible versions.
  1815. # (This logic is based on that in Python's configure.in)
  1816. AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
  1817. [Define this if you have any gethostbyname_r()])
  1818. AC_CHECK_FUNC(gethostbyname_r, [
  1819. AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
  1820. OLD_CFLAGS=$CFLAGS
  1821. CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
  1822. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1823. #include <netdb.h>
  1824. ]], [[
  1825. char *cp1, *cp2;
  1826. struct hostent *h1, *h2;
  1827. int i1, i2;
  1828. (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
  1829. ]])],[
  1830. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1831. AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
  1832. [Define this if gethostbyname_r takes 6 arguments])
  1833. AC_MSG_RESULT(6)
  1834. ], [
  1835. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1836. #include <netdb.h>
  1837. ]], [[
  1838. char *cp1, *cp2;
  1839. struct hostent *h1;
  1840. int i1, i2;
  1841. (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
  1842. ]])], [
  1843. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1844. AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
  1845. [Define this if gethostbyname_r takes 5 arguments])
  1846. AC_MSG_RESULT(5)
  1847. ], [
  1848. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1849. #include <netdb.h>
  1850. ]], [[
  1851. char *cp1;
  1852. struct hostent *h1;
  1853. struct hostent_data hd;
  1854. (void) gethostbyname_r(cp1,h1,&hd);
  1855. ]])], [
  1856. AC_DEFINE(HAVE_GETHOSTBYNAME_R)
  1857. AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
  1858. [Define this if gethostbyname_r takes 3 arguments])
  1859. AC_MSG_RESULT(3)
  1860. ], [
  1861. AC_MSG_RESULT(0)
  1862. ])
  1863. ])
  1864. ])
  1865. CFLAGS=$OLD_CFLAGS
  1866. ])
  1867. AC_CACHE_CHECK([whether the C compiler supports __func__],
  1868. tor_cv_have_func_macro,
  1869. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1870. #include <stdio.h>
  1871. int main(int c, char **v) { puts(__func__); }])],
  1872. tor_cv_have_func_macro=yes,
  1873. tor_cv_have_func_macro=no))
  1874. AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
  1875. tor_cv_have_FUNC_macro,
  1876. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1877. #include <stdio.h>
  1878. int main(int c, char **v) { puts(__FUNC__); }])],
  1879. tor_cv_have_FUNC_macro=yes,
  1880. tor_cv_have_FUNC_macro=no))
  1881. AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
  1882. tor_cv_have_FUNCTION_macro,
  1883. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1884. #include <stdio.h>
  1885. int main(int c, char **v) { puts(__FUNCTION__); }])],
  1886. tor_cv_have_FUNCTION_macro=yes,
  1887. tor_cv_have_FUNCTION_macro=no))
  1888. AC_CACHE_CHECK([whether we have extern char **environ already declared],
  1889. tor_cv_have_environ_declared,
  1890. AC_COMPILE_IFELSE([AC_LANG_SOURCE([
  1891. #ifdef HAVE_UNISTD_H
  1892. #include <unistd.h>
  1893. #endif
  1894. #include <stdlib.h>
  1895. int main(int c, char **v) { char **t = environ; }])],
  1896. tor_cv_have_environ_declared=yes,
  1897. tor_cv_have_environ_declared=no))
  1898. if test "$tor_cv_have_func_macro" = "yes"; then
  1899. AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
  1900. fi
  1901. if test "$tor_cv_have_FUNC_macro" = "yes"; then
  1902. AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
  1903. fi
  1904. if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
  1905. AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
  1906. [Defined if the compiler supports __FUNCTION__])
  1907. fi
  1908. if test "$tor_cv_have_environ_declared" = "yes"; then
  1909. AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
  1910. [Defined if we have extern char **environ already declared])
  1911. fi
  1912. # $prefix stores the value of the --prefix command line option, or
  1913. # NONE if the option wasn't set. In the case that it wasn't set, make
  1914. # it be the default, so that we can use it to expand directories now.
  1915. if test "x$prefix" = "xNONE"; then
  1916. prefix=$ac_default_prefix
  1917. fi
  1918. # and similarly for $exec_prefix
  1919. if test "x$exec_prefix" = "xNONE"; then
  1920. exec_prefix=$prefix
  1921. fi
  1922. if test "x$BUILDDIR" = "x"; then
  1923. BUILDDIR=`pwd`
  1924. fi
  1925. AC_SUBST(BUILDDIR)
  1926. AH_TEMPLATE([BUILDDIR],[tor's build directory])
  1927. AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
  1928. if test "x$SRCDIR" = "x"; then
  1929. SRCDIR=$(cd "$srcdir"; pwd)
  1930. fi
  1931. AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
  1932. AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
  1933. if test "x$CONFDIR" = "x"; then
  1934. CONFDIR=`eval echo $sysconfdir/tor`
  1935. fi
  1936. AC_SUBST(CONFDIR)
  1937. AH_TEMPLATE([CONFDIR],[tor's configuration directory])
  1938. AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
  1939. BINDIR=`eval echo $bindir`
  1940. AC_SUBST(BINDIR)
  1941. LOCALSTATEDIR=`eval echo $localstatedir`
  1942. AC_SUBST(LOCALSTATEDIR)
  1943. if test "$bwin32" = "true"; then
  1944. # Test if the linker supports the --nxcompat and --dynamicbase options
  1945. # for Windows
  1946. save_LDFLAGS="$LDFLAGS"
  1947. LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
  1948. AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
  1949. AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
  1950. [AC_MSG_RESULT([yes])]
  1951. [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
  1952. [AC_MSG_RESULT([no])]
  1953. )
  1954. LDFLAGS="$save_LDFLAGS"
  1955. fi
  1956. # Set CFLAGS _after_ all the above checks, since our warnings are stricter
  1957. # than autoconf's macros like.
  1958. if test "$GCC" = "yes"; then
  1959. # Disable GCC's strict aliasing checks. They are an hours-to-debug
  1960. # accident waiting to happen.
  1961. CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
  1962. else
  1963. # Override optimization level for non-gcc compilers
  1964. CFLAGS="$CFLAGS -O"
  1965. enable_gcc_warnings=no
  1966. enable_gcc_warnings_advisory=no
  1967. fi
  1968. # Warnings implies advisory-warnings and -Werror.
  1969. if test "$enable_gcc_warnings" = "yes"; then
  1970. enable_gcc_warnings_advisory=yes
  1971. enable_fatal_warnings=yes
  1972. fi
  1973. # OS X Lion started deprecating the system openssl. Let's just disable
  1974. # all deprecation warnings on OS X. Also, to potentially make the binary
  1975. # a little smaller, let's enable dead_strip.
  1976. case "$host_os" in
  1977. darwin*)
  1978. CFLAGS="$CFLAGS -Wno-deprecated-declarations"
  1979. LDFLAGS="$LDFLAGS -dead_strip" ;;
  1980. esac
  1981. TOR_WARNING_FLAGS=""
  1982. # Add some more warnings which we use in development but not in the
  1983. # released versions. (Some relevant gcc versions can't handle these.)
  1984. #
  1985. # Note that we have to do this near the end of the autoconf process, or
  1986. # else we may run into problems when these warnings hit on the testing C
  1987. # programs that autoconf wants to build.
  1988. if test "x$enable_gcc_warnings_advisory" != "xno"; then
  1989. case "$host" in
  1990. *-*-openbsd* | *-*-bitrig*)
  1991. # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
  1992. # That's fine, except that the headers don't pass -Wredundant-decls.
  1993. # Therefore, let's disable -Wsystem-headers when we're building
  1994. # with maximal warnings on OpenBSD.
  1995. CFLAGS="$CFLAGS -Wno-system-headers" ;;
  1996. esac
  1997. CFLAGS_NOWARNINGS="$CFLAGS"
  1998. # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
  1999. # have it work better.
  2000. # CFLAGS="$CFLAGS -Wstrict-overflow=1"
  2001. # This warning was added in gcc 4.3, but it appears to generate
  2002. # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
  2003. #CFLAGS="$CFLAGS -Wlogical-op"
  2004. m4_foreach_w([warning_flag], [
  2005. -Waddress
  2006. -Waddress-of-array-temporary
  2007. -Waddress-of-temporary
  2008. -Wambiguous-macro
  2009. -Wanonymous-pack-parens
  2010. -Warc
  2011. -Warc-abi
  2012. -Warc-bridge-casts-disallowed-in-nonarc
  2013. -Warc-maybe-repeated-use-of-weak
  2014. -Warc-performSelector-leaks
  2015. -Warc-repeated-use-of-weak
  2016. -Warray-bounds
  2017. -Warray-bounds-pointer-arithmetic
  2018. -Wasm
  2019. -Wasm-operand-widths
  2020. -Watomic-properties
  2021. -Watomic-property-with-user-defined-accessor
  2022. -Wauto-import
  2023. -Wauto-storage-class
  2024. -Wauto-var-id
  2025. -Wavailability
  2026. -Wbackslash-newline-escape
  2027. -Wbad-array-new-length
  2028. -Wbind-to-temporary-copy
  2029. -Wbitfield-constant-conversion
  2030. -Wbool-conversion
  2031. -Wbool-conversions
  2032. -Wbuiltin-requires-header
  2033. -Wchar-align
  2034. -Wcompare-distinct-pointer-types
  2035. -Wcomplex-component-init
  2036. -Wconditional-type-mismatch
  2037. -Wconfig-macros
  2038. -Wconstant-conversion
  2039. -Wconstant-logical-operand
  2040. -Wconstexpr-not-const
  2041. -Wcustom-atomic-properties
  2042. -Wdangling-field
  2043. -Wdangling-initializer-list
  2044. -Wdate-time
  2045. -Wdelegating-ctor-cycles
  2046. -Wdeprecated-implementations
  2047. -Wdeprecated-register
  2048. -Wdirect-ivar-access
  2049. -Wdiscard-qual
  2050. -Wdistributed-object-modifiers
  2051. -Wdivision-by-zero
  2052. -Wdollar-in-identifier-extension
  2053. -Wdouble-promotion
  2054. -Wduplicate-decl-specifier
  2055. -Wduplicate-enum
  2056. -Wduplicate-method-arg
  2057. -Wduplicate-method-match
  2058. -Wduplicated-cond
  2059. -Wdynamic-class-memaccess
  2060. -Wembedded-directive
  2061. -Wempty-translation-unit
  2062. -Wenum-conversion
  2063. -Wexit-time-destructors
  2064. -Wexplicit-ownership-type
  2065. -Wextern-initializer
  2066. -Wextra
  2067. -Wextra-semi
  2068. -Wextra-tokens
  2069. -Wflexible-array-extensions
  2070. -Wfloat-conversion
  2071. -Wformat-non-iso
  2072. -Wfour-char-constants
  2073. -Wgcc-compat
  2074. -Wglobal-constructors
  2075. -Wgnu-array-member-paren-init
  2076. -Wgnu-designator
  2077. -Wgnu-static-float-init
  2078. -Wheader-guard
  2079. -Wheader-hygiene
  2080. -Widiomatic-parentheses
  2081. -Wignored-attributes
  2082. -Wimplicit-atomic-properties
  2083. -Wimplicit-conversion-floating-point-to-bool
  2084. -Wimplicit-exception-spec-mismatch
  2085. -Wimplicit-fallthrough
  2086. -Wimplicit-fallthrough-per-function
  2087. -Wimplicit-retain-self
  2088. -Wimport-preprocessor-directive-pedantic
  2089. -Wincompatible-library-redeclaration
  2090. -Wincompatible-pointer-types-discards-qualifiers
  2091. -Wincomplete-implementation
  2092. -Wincomplete-module
  2093. -Wincomplete-umbrella
  2094. -Winit-self
  2095. -Wint-conversions
  2096. -Wint-to-void-pointer-cast
  2097. -Winteger-overflow
  2098. -Winvalid-constexpr
  2099. -Winvalid-iboutlet
  2100. -Winvalid-noreturn
  2101. -Winvalid-pp-token
  2102. -Winvalid-source-encoding
  2103. -Winvalid-token-paste
  2104. -Wknr-promoted-parameter
  2105. -Wlarge-by-value-copy
  2106. -Wliteral-conversion
  2107. -Wliteral-range
  2108. -Wlocal-type-template-args
  2109. -Wlogical-op
  2110. -Wloop-analysis
  2111. -Wmain-return-type
  2112. -Wmalformed-warning-check
  2113. -Wmethod-signatures
  2114. -Wmicrosoft
  2115. -Wmicrosoft-exists
  2116. -Wmismatched-parameter-types
  2117. -Wmismatched-return-types
  2118. -Wmissing-field-initializers
  2119. -Wmissing-format-attribute
  2120. -Wmissing-noreturn
  2121. -Wmissing-selector-name
  2122. -Wmissing-sysroot
  2123. -Wmissing-variable-declarations
  2124. -Wmodule-conflict
  2125. -Wnested-anon-types
  2126. -Wnewline-eof
  2127. -Wnon-literal-null-conversion
  2128. -Wnon-pod-varargs
  2129. -Wnonportable-cfstrings
  2130. -Wnormalized=nfkc
  2131. -Wnull-arithmetic
  2132. -Wnull-character
  2133. -Wnull-conversion
  2134. -Wnull-dereference
  2135. -Wout-of-line-declaration
  2136. -Wover-aligned
  2137. -Woverlength-strings
  2138. -Woverride-init
  2139. -Woverriding-method-mismatch
  2140. -Wpointer-type-mismatch
  2141. -Wpredefined-identifier-outside-function
  2142. -Wprotocol-property-synthesis-ambiguity
  2143. -Wreadonly-iboutlet-property
  2144. -Wreadonly-setter-attrs
  2145. -Wreceiver-expr
  2146. -Wreceiver-forward-class
  2147. -Wreceiver-is-weak
  2148. -Wreinterpret-base-class
  2149. -Wrequires-super-attribute
  2150. -Wreserved-user-defined-literal
  2151. -Wreturn-stack-address
  2152. -Wsection
  2153. -Wselector-type-mismatch
  2154. -Wsentinel
  2155. -Wserialized-diagnostics
  2156. -Wshadow
  2157. -Wshift-count-negative
  2158. -Wshift-count-overflow
  2159. -Wshift-negative-value
  2160. -Wshift-overflow=2
  2161. -Wshift-sign-overflow
  2162. -Wshorten-64-to-32
  2163. -Wsizeof-array-argument
  2164. -Wsource-uses-openmp
  2165. -Wstatic-float-init
  2166. -Wstatic-in-inline
  2167. -Wstatic-local-in-inline
  2168. -Wstrict-overflow=1
  2169. -Wstring-compare
  2170. -Wstring-conversion
  2171. -Wstrlcpy-strlcat-size
  2172. -Wstrncat-size
  2173. -Wsuggest-attribute=format
  2174. -Wsuggest-attribute=noreturn
  2175. -Wsuper-class-method-mismatch
  2176. -Wswitch-bool
  2177. -Wsync-nand
  2178. -Wtautological-constant-out-of-range-compare
  2179. -Wtentative-definition-incomplete-type
  2180. -Wtrampolines
  2181. -Wtype-safety
  2182. -Wtypedef-redefinition
  2183. -Wtypename-missing
  2184. -Wundefined-inline
  2185. -Wundefined-internal
  2186. -Wundefined-reinterpret-cast
  2187. -Wunicode
  2188. -Wunicode-whitespace
  2189. -Wunknown-warning-option
  2190. -Wunnamed-type-template-args
  2191. -Wunneeded-member-function
  2192. -Wunsequenced
  2193. -Wunsupported-visibility
  2194. -Wunused-but-set-parameter
  2195. -Wunused-but-set-variable
  2196. -Wunused-command-line-argument
  2197. -Wunused-const-variable=2
  2198. -Wunused-exception-parameter
  2199. -Wunused-local-typedefs
  2200. -Wunused-member-function
  2201. -Wunused-sanitize-argument
  2202. -Wunused-volatile-lvalue
  2203. -Wuser-defined-literals
  2204. -Wvariadic-macros
  2205. -Wvector-conversion
  2206. -Wvector-conversions
  2207. -Wvexing-parse
  2208. -Wvisibility
  2209. -Wvla-extension
  2210. -Wzero-length-array
  2211. ], [ TOR_TRY_COMPILE_WITH_CFLAGS(warning_flag, [],
  2212. [TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS warning_flag" CFLAGS="$CFLAGS warning_flag"], true)
  2213. ])
  2214. dnl We should re-enable this in some later version. Clang doesn't
  2215. dnl mind, but it causes trouble with GCC.
  2216. dnl -Wstrict-overflow=2
  2217. dnl These seem to require annotations that we don't currently use,
  2218. dnl and they give false positives in our pthreads wrappers. (Clang 4)
  2219. dnl -Wthread-safety
  2220. dnl -Wthread-safety-analysis
  2221. dnl -Wthread-safety-attributes
  2222. dnl -Wthread-safety-beta
  2223. dnl -Wthread-safety-precise
  2224. W_FLAGS="$W_FLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
  2225. W_FLAGS="$W_FLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
  2226. W_FLAGS="$W_FLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
  2227. W_FLAGS="$W_FLAGS -Wwrite-strings"
  2228. W_FLAGS="$W_FLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
  2229. W_FLAGS="$W_FLAGS -Waggregate-return -Wpacked -Wunused"
  2230. W_FLAGS="$W_FLAGS -Wunused-parameter "
  2231. # These interfere with building main() { return 0; }, which autoconf
  2232. # likes to use as its default program.
  2233. W_FLAGS="$W_FLAGS -Wold-style-definition -Wmissing-declarations"
  2234. TOR_WARNING_FLAGS="$TOR_WARNING_FLAGS $W_FLAGS"
  2235. CFLAGS="$CFLAGS $W_FLAGS"
  2236. if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
  2237. AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
  2238. fi
  2239. if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
  2240. AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
  2241. fi
  2242. if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
  2243. AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
  2244. fi
  2245. CFLAGS="$CFLAGS_NOWARNINGS"
  2246. if test "x$enable_fatal_warnings" = "xyes"; then
  2247. # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
  2248. # default autoconf programs are full of errors.
  2249. CFLAGS="$CFLAGS -Werror"
  2250. fi
  2251. fi
  2252. AC_SUBST(TOR_WARNING_FLAGS)
  2253. echo "$TOR_WARNING_FLAGS">warning_flags
  2254. TOR_TRY_COMPILE_WITH_CFLAGS([@warning_flags], [],
  2255. CFLAGS="$CFLAGS @warning_flags",
  2256. CFLAGS="$CFLAGS $TOR_WARNING_FLAGS")
  2257. if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
  2258. case "$host_os" in
  2259. darwin*)
  2260. tor_incr_n_warnings
  2261. AC_MSG_WARN([Tried to enable coverage on OSX without using the clang compiler. This might not work! If coverage fails, use CC=clang when configuring with --enable-coverage.])
  2262. esac
  2263. fi
  2264. CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
  2265. AC_CONFIG_FILES([
  2266. Doxyfile
  2267. Makefile
  2268. contrib/operator-tools/tor.logrotate
  2269. src/config/torrc.sample
  2270. src/config/torrc.minimal
  2271. scripts/maint/checkOptionDocs.pl
  2272. warning_flags
  2273. ])
  2274. if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
  2275. regular_mans="doc/man/tor doc/man/tor-gencert doc/man/tor-resolve doc/man/torify"
  2276. for file in $regular_mans ; do
  2277. if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
  2278. echo "==================================";
  2279. echo;
  2280. echo "Building Tor has failed since manpages cannot be built.";
  2281. echo;
  2282. echo "You need asciidoc installed to be able to build the manpages.";
  2283. echo "To build without manpages, use the --disable-asciidoc argument";
  2284. echo "when calling configure.";
  2285. echo;
  2286. echo "==================================";
  2287. exit 1;
  2288. fi
  2289. done
  2290. fi
  2291. if test "$fragile_hardening" = "yes"; then
  2292. tor_incr_n_warnings
  2293. AC_MSG_WARN([
  2294. ============
  2295. Warning! Building Tor with --enable-fragile-hardening (also known as
  2296. --enable-expensive-hardening) makes some kinds of attacks harder, but makes
  2297. other kinds of attacks easier. A Tor instance build with this option will be
  2298. somewhat less vulnerable to remote code execution, arithmetic overflow, or
  2299. out-of-bounds read/writes... but at the cost of becoming more vulnerable to
  2300. denial of service attacks. For more information, see
  2301. https://gitlab.torproject.org/tpo/core/team/-/wikis/TorFragileHardening
  2302. ============
  2303. ])
  2304. fi
  2305. AC_OUTPUT
  2306. if test "$openssl_ver_mismatch" = "yes"; then
  2307. tor_incr_n_warnings
  2308. AC_MSG_WARN([
  2309. ============
  2310. Warning! The version OpenSSL headers we get from compiling with
  2311. "${TOR_CPPFLAGS_OPENSSL:-(no extra options)}"
  2312. do not match version of the OpenSSL library we get when linking with
  2313. "$TOR_LDFLAGS_OPENSSL $TOR_OPENSSL_LIBS".
  2314. This might cause compilation to fail. Try using --with-openssl-dir to specify
  2315. the exact OpenSSL path you want.
  2316. ============
  2317. ])
  2318. fi
  2319. #
  2320. # Mini-report on what will be built.
  2321. #
  2322. PPRINT_INIT
  2323. PPRINT_SET_INDENT(1)
  2324. PPRINT_SET_TS(65)
  2325. AS_ECHO
  2326. AS_ECHO("Tor Version: ${PPRINT_COLOR_BLDBLU}Tor $PACKAGE_VERSION $PPRINT_COLOR_RST")
  2327. AS_ECHO
  2328. PPRINT_SUBTITLE([Build Features])
  2329. PPRINT_PROP_STRING([Compiler], [$CC])
  2330. PPRINT_PROP_STRING([Host OS], [$host_os])
  2331. AS_ECHO
  2332. test "x$enable_fatal_warnings" = "xyes" && value=1 || value=0
  2333. PPRINT_PROP_BOOL([Warnings are fatal (--enable-fatal-warnings)], $value)
  2334. test "x$enable_android" = "xyes" && value=1 || value=0
  2335. PPRINT_PROP_BOOL([Android support (--enable-android)], $value)
  2336. AS_ECHO
  2337. PPRINT_SUBTITLE([Static Build])
  2338. test "x$enable_static_tor" = "xyes" && value=1 || value=0
  2339. PPRINT_PROP_BOOL([tor (--enable-static-tor)], $value)
  2340. if test "x$enable_static_libevent" = "xyes"; then
  2341. PPRINT_PROP_STRING([libevent], [$TOR_LIBDIR_libevent])
  2342. else
  2343. PPRINT_PROP_BOOL([libevent (--enable-static-libevent)], $value)
  2344. fi
  2345. if test "x$enable_static_openssl" = "xyes"; then
  2346. PPRINT_PROP_STRING([libssl], [$TOR_LIBDIR_openssl])
  2347. else
  2348. PPRINT_PROP_BOOL([libssl (--enable-static-openssl)], $value)
  2349. fi
  2350. if test "x$enable_static_zlib" = "xyes"; then
  2351. PPRINT_PROP_STRING([zlib1g], [$TOR_LIBDIR_zlib])
  2352. else
  2353. PPRINT_PROP_BOOL([zlib1g (--enable-static-zlib)], $value)
  2354. fi
  2355. AS_ECHO
  2356. PPRINT_SUBTITLE([Optional Libraries])
  2357. test "x$enable_nss" = "xyes" && value=1 || value=0
  2358. PPRINT_PROP_BOOL([libnss (--enable-nss)], $value)
  2359. test "x$enable_seccomp" != "xno" && value=1 || value=0
  2360. PPRINT_PROP_BOOL([libseccomp (--disable-seccomp)], $value)
  2361. test "x$enable_libscrypt" != "xno" && value=1 || value=0
  2362. PPRINT_PROP_BOOL([libscrypt (--disable-libscrypt)], $value)
  2363. test "x$enable_systemd" = "xyes" && value=1 || value=0
  2364. PPRINT_PROP_BOOL([Systemd support (--enable-systemd)], $value)
  2365. test "x$have_lzma" = "xyes" && value=1 || value=0
  2366. PPRINT_PROP_BOOL([liblzma (--enable-lzma)], $value)
  2367. test "x$have_zstd" = "xyes" && value=1 || value=0
  2368. PPRINT_PROP_BOOL([libzstd (--enable-zstd)], $value)
  2369. AS_ECHO
  2370. PPRINT_SUBTITLE([Hardening])
  2371. test "x$enable_gcc_hardening" != "xno" && value=1 || value=0
  2372. PPRINT_PROP_BOOL([Compiler Hardening (--disable-gcc-hardening)], $value)
  2373. test "x$enable_linker_hardening" != "xno" && value=1 || value=0
  2374. PPRINT_PROP_BOOL([Linker Hardening (--disable-linker-hardening)], $value)
  2375. test "x$fragile_hardening" = "xyes" && value=1 || value=0
  2376. PPRINT_PROP_BOOL([Fragile Hardening (--enable-fragile-hardening, dev only)], $value)
  2377. AS_ECHO
  2378. PPRINT_SUBTITLE([Modules])
  2379. m4_foreach_w([mname], MODULES,
  2380. [
  2381. AM_COND_IF(m4_join([], [BUILD_MODULE_], m4_toupper([]mname[])), value=1, value=0)
  2382. m4_set_contains([MODULES_WITH_NO_OPTIONS], mname,
  2383. PPRINT_PROP_BOOL([mname], $value),
  2384. PPRINT_PROP_BOOL([mname (--disable-module-mname)], $value))
  2385. ]
  2386. )
  2387. AS_ECHO
  2388. PPRINT_SUBTITLE([Documentation])
  2389. test "x$enable_asciidoc" != "xno" && value=1 || value=0
  2390. PPRINT_PROP_BOOL([AsciiDoc (--disable-asciidoc)], $value)
  2391. test "x$enable_manpage" != "xno" && value=1 || value=0
  2392. PPRINT_PROP_BOOL([Man Pages (--disable-manpage)], $value)
  2393. test "x$enable_html_manual" != "xno" && value=1 || value=0
  2394. PPRINT_PROP_BOOL([HTML Manual (--disable-html-manual)], $value)
  2395. AS_ECHO
  2396. PPRINT_SUBTITLE([Tests])
  2397. test "x$enable_unittests" != "xno" && value=1 || value=0
  2398. PPRINT_PROP_BOOL([Unit tests (--disable-unittests)], $value)
  2399. test "x$enable_asserts_in_tests" = "xno" && value=1 || value=0
  2400. PPRINT_PROP_BOOL([assert()s enabled (--enable-asserts-in-tests, dev only)], $value)
  2401. test "x$enable_coverage" = "xyes" && value=1 || value=0
  2402. PPRINT_PROP_BOOL([Code Coverage (--enable-coverage)], $value)
  2403. test "x$enable_libfuzzer" = "xyes" && value=1 || value=0
  2404. PPRINT_PROP_BOOL([libFuzzer support (--enable-libfuzzer)], $value)
  2405. test "x$enable_oss_fuzz" = "xyes" && value=1 || value=0
  2406. PPRINT_PROP_BOOL([OSS-Fuzz support (--enable-oss-fuzz)], $value)
  2407. AS_ECHO
  2408. PPRINT_SUBTITLE([Tracing (--enable-tracing-instrumentation-<type>)])
  2409. test "x$enable_tracing_instrumentation_log_debug" = "xyes" && value=1 || value=0
  2410. PPRINT_PROP_BOOL([Tracepoints to log_debug() (log-debug)], $value)
  2411. test "x$enable_tracing_instrumentation_usdt" = "xyes" && value=1 || value=0
  2412. PPRINT_PROP_BOOL([USDT Instrumentation (usdt)], $value)
  2413. test "x$enable_tracing_instrumentation_lttng" = "xyes" && value=1 || value=0
  2414. PPRINT_PROP_BOOL([LTTng Instrumentation (lttng)], $value)
  2415. AS_ECHO
  2416. PPRINT_SUBTITLE([Install Directories])
  2417. report_mandir="`eval eval echo $mandir`"
  2418. PPRINT_PROP_STRING([Binaries], [$BINDIR])
  2419. PPRINT_PROP_STRING([Configuration], [$CONFDIR])
  2420. PPRINT_PROP_STRING([Man Pages], [$report_mandir])
  2421. AS_ECHO
  2422. AS_ECHO(["Configure Line: ./configure $configure_flags"])
  2423. if test "$tor_ac_n_warnings" != "0"; then
  2424. AS_ECHO
  2425. PPRINT_WARN([
  2426. Encountered $tor_ac_n_warnings warning(s). See messages above for more info.
  2427. ])
  2428. fi