configure.ac 88 KB

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