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