1 dnl Copyright (c) 2001-2004, Roger Dingledine
2 dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 dnl Copyright (c) 2007-2017, The Tor Project, Inc.
4 dnl See LICENSE for licensing information
7 AC_INIT([tor],[0.3.4.11])
8 AC_CONFIG_SRCDIR([src/or/main.c])
9 AC_CONFIG_MACRO_DIR([m4])
11 # "foreign" means we don't follow GNU package layout standards
12 # "1.11" means we require automake version 1.11 or newer
13 # "subdir-objects" means put .o files in the same directory as the .c files
14 AM_INIT_AUTOMAKE([foreign 1.11 subdir-objects -Wall -Werror])
16 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
17 AC_CONFIG_HEADERS([orconfig.h])
19 AC_USE_SYSTEM_EXTENSIONS
24 if test -f "/etc/redhat-release"; then
25 if test -f "/usr/kerberos/include"; then
26 CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
30 # Not a no-op; we want to make sure that CPPFLAGS is set before we use
31 # the += operator on it in src/or/Makefile.am
32 CPPFLAGS="$CPPFLAGS -I\${top_srcdir}/src/common"
34 AC_ARG_ENABLE(openbsd-malloc,
35 AS_HELP_STRING(--enable-openbsd-malloc, [use malloc code from OpenBSD. Linux only]))
36 AC_ARG_ENABLE(static-openssl,
37 AS_HELP_STRING(--enable-static-openssl, [link against a static openssl library. Requires --with-openssl-dir]))
38 AC_ARG_ENABLE(static-libevent,
39 AS_HELP_STRING(--enable-static-libevent, [link against a static libevent library. Requires --with-libevent-dir]))
40 AC_ARG_ENABLE(static-zlib,
41 AS_HELP_STRING(--enable-static-zlib, [link against a static zlib library. Requires --with-zlib-dir]))
42 AC_ARG_ENABLE(static-tor,
43 AS_HELP_STRING(--enable-static-tor, [create an entirely static Tor binary. Requires --with-openssl-dir and --with-libevent-dir and --with-zlib-dir]))
44 AC_ARG_ENABLE(unittests,
45 AS_HELP_STRING(--disable-unittests, [don't build unit tests for Tor. Risky!]))
46 AC_ARG_ENABLE(coverage,
47 AS_HELP_STRING(--enable-coverage, [enable coverage support in the unit-test build]))
48 AC_ARG_ENABLE(asserts-in-tests,
49 AS_HELP_STRING(--disable-asserts-in-tests, [disable tor_assert() calls in the unit tests, for branch coverage]))
50 AC_ARG_ENABLE(system-torrc,
51 AS_HELP_STRING(--disable-system-torrc, [don't look for a system-wide torrc file]))
52 AC_ARG_ENABLE(libfuzzer,
53 AS_HELP_STRING(--enable-libfuzzer, [build extra fuzzers based on 'libfuzzer']))
54 AC_ARG_ENABLE(oss-fuzz,
55 AS_HELP_STRING(--enable-oss-fuzz, [build extra fuzzers based on 'oss-fuzz' environment]))
56 AC_ARG_ENABLE(memory-sentinels,
57 AS_HELP_STRING(--disable-memory-sentinels, [disable code that tries to prevent some kinds of memory access bugs. For fuzzing only.]))
59 AS_HELP_STRING(--enable-rust, [enable rust integration]))
60 AC_ARG_ENABLE(cargo-online-mode,
61 AS_HELP_STRING(--enable-cargo-online-mode, [Allow cargo to make network requests to fetch crates. For builds with rust only.]))
62 AC_ARG_ENABLE(restart-debugging,
63 AS_HELP_STRING(--enable-restart-debugging, [Build Tor with support for debugging in-process restart. Developers only.]))
64 AC_ARG_ENABLE(zstd-advanced-apis,
65 AS_HELP_STRING(--disable-zstd-advanced-apis, [Build without support for zstd's "static-only" APIs.]))
67 if test "x$enable_coverage" != "xyes" -a "x$enable_asserts_in_tests" = "xno" ; then
68 AC_MSG_ERROR([Can't disable assertions outside of coverage build])
71 AM_CONDITIONAL(UNITTESTS_ENABLED, test "x$enable_unittests" != "xno")
72 AM_CONDITIONAL(COVERAGE_ENABLED, test "x$enable_coverage" = "xyes")
73 AM_CONDITIONAL(DISABLE_ASSERTS_IN_UNIT_TESTS, test "x$enable_asserts_in_tests" = "xno")
74 AM_CONDITIONAL(LIBFUZZER_ENABLED, test "x$enable_libfuzzer" = "xyes")
75 AM_CONDITIONAL(OSS_FUZZ_ENABLED, test "x$enable_oss_fuzz" = "xyes")
76 AM_CONDITIONAL(USE_RUST, test "x$enable_rust" = "xyes")
78 if test "$enable_static_tor" = "yes"; then
79 enable_static_libevent="yes";
80 enable_static_openssl="yes";
81 enable_static_zlib="yes";
82 CFLAGS="$CFLAGS -static"
85 if test "$enable_system_torrc" = "no"; then
86 AC_DEFINE(DISABLE_SYSTEM_TORRC, 1,
87 [Defined if we're not going to look for a torrc in SYSCONF])
90 if test "$enable_memory_sentinels" = "no"; then
91 AC_DEFINE(DISABLE_MEMORY_SENTINELS, 1,
92 [Defined if we're turning off memory safety code to look for bugs])
95 AM_CONDITIONAL(USE_OPENBSD_MALLOC, test "x$enable_openbsd_malloc" = "xyes")
97 AC_ARG_ENABLE(asciidoc,
98 AS_HELP_STRING(--disable-asciidoc, [don't use asciidoc (disables building of manpages)]),
99 [case "${enableval}" in
100 "yes") asciidoc=true ;;
101 "no") asciidoc=false ;;
102 *) AC_MSG_ERROR(bad value for --disable-asciidoc) ;;
103 esac], [asciidoc=true])
105 # systemd notify support
106 AC_ARG_ENABLE(systemd,
107 AS_HELP_STRING(--enable-systemd, [enable systemd notification support]),
108 [case "${enableval}" in
109 "yes") systemd=true ;;
110 "no") systemd=false ;;
111 * ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
112 esac], [systemd=auto])
114 if test "$enable_restart_debugging" = "yes"; then
115 AC_DEFINE(ENABLE_RESTART_DEBUGGING, 1,
116 [Defined if we're building with support for in-process restart debugging.])
119 if test "$enable_zstd_advanced_apis" != "no"; then
120 AC_DEFINE(ENABLE_ZSTD_ADVANCED_APIS, 1,
121 [Defined if we're going to try to use zstd's "static-only" APIs.])
125 if test "x$enable_systemd" = "xno"; then
128 PKG_CHECK_MODULES(SYSTEMD,
132 if test "x$have_systemd" = "xno"; then
133 AC_MSG_NOTICE([Okay, checking for systemd a different way...])
134 PKG_CHECK_MODULES(SYSTEMD,
141 if test "x$have_systemd" = "xyes"; then
142 AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
143 TOR_SYSTEMD_CFLAGS="${SYSTEMD_CFLAGS}"
144 TOR_SYSTEMD_LIBS="${SYSTEMD_LIBS}"
145 PKG_CHECK_MODULES(LIBSYSTEMD209, [libsystemd >= 209],
146 [AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
148 AC_SUBST(TOR_SYSTEMD_CFLAGS)
149 AC_SUBST(TOR_SYSTEMD_LIBS)
151 if test "x$enable_systemd" = "xyes" -a "x$have_systemd" != "xyes" ; then
152 AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
157 AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
161 AC_ARG_ENABLE(gcc-warnings,
162 AS_HELP_STRING(--enable-gcc-warnings, [deprecated alias for enable-fatal-warnings]))
163 AC_ARG_ENABLE(fatal-warnings,
164 AS_HELP_STRING(--enable-fatal-warnings, [tell the compiler to treat all warnings as errors.]))
165 AC_ARG_ENABLE(gcc-warnings-advisory,
166 AS_HELP_STRING(--disable-gcc-warnings-advisory, [disable the regular verbose warnings]))
168 dnl Others suggest '/gs /safeseh /nxcompat /dynamicbase' for non-gcc on Windows
169 AC_ARG_ENABLE(gcc-hardening,
170 AS_HELP_STRING(--disable-gcc-hardening, [disable compiler security checks]))
172 dnl Deprecated --enable-expensive-hardening but keep it for now for backward compat.
173 AC_ARG_ENABLE(expensive-hardening,
174 AS_HELP_STRING(--enable-expensive-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
175 AC_ARG_ENABLE(fragile-hardening,
176 AS_HELP_STRING(--enable-fragile-hardening, [enable more fragile and expensive compiler hardening; makes Tor slower]))
177 if test "x$enable_expensive_hardening" = "xyes" || test "x$enable_fragile_hardening" = "xyes"; then
178 fragile_hardening="yes"
179 AC_DEFINE(DEBUG_SMARTLIST, 1, [Enable smartlist debugging])
182 dnl Linker hardening options
183 dnl Currently these options are ELF specific - you can't use this with MacOSX
184 AC_ARG_ENABLE(linker-hardening,
185 AS_HELP_STRING(--disable-linker-hardening, [disable linker security fixups]))
187 AC_ARG_ENABLE(local-appdata,
188 AS_HELP_STRING(--enable-local-appdata, [default to host local application data paths on Windows]))
189 if test "$enable_local_appdata" = "yes"; then
190 AC_DEFINE(ENABLE_LOCAL_APPDATA, 1,
191 [Defined if we default to host local appdata paths on Windows])
195 AC_ARG_ENABLE(tor2web-mode,
196 AS_HELP_STRING(--enable-tor2web-mode, [support tor2web non-anonymous mode]),
197 [if test "x$enableval" = "xyes"; then
198 CFLAGS="$CFLAGS -D ENABLE_TOR2WEB_MODE=1"
201 AC_ARG_ENABLE(tool-name-check,
202 AS_HELP_STRING(--disable-tool-name-check, [check for sanely named toolchain when cross-compiling]))
204 AC_ARG_ENABLE(seccomp,
205 AS_HELP_STRING(--disable-seccomp, [do not attempt to use libseccomp]))
207 AC_ARG_ENABLE(libscrypt,
208 AS_HELP_STRING(--disable-libscrypt, [do not attempt to use libscrypt]))
210 dnl Enable event tracing which are transformed to debug log statement.
211 AC_ARG_ENABLE(event-tracing-debug,
212 AS_HELP_STRING(--enable-event-tracing-debug, [build with event tracing to debug log]))
213 AM_CONDITIONAL([USE_EVENT_TRACING_DEBUG], [test "x$enable_event_tracing_debug" = "xyes"])
215 if test x$enable_event_tracing_debug = xyes; then
216 AC_DEFINE([USE_EVENT_TRACING_DEBUG], [1], [Tracing framework to log debug])
217 AC_DEFINE([TOR_EVENT_TRACING_ENABLED], [1], [Compile the event tracing instrumentation])
220 dnl Enable Android only features.
221 AC_ARG_ENABLE(android,
222 AS_HELP_STRING(--enable-android, [build with Android features enabled]))
223 AM_CONDITIONAL([USE_ANDROID], [test "x$enable_android" = "xyes"])
225 if test "x$enable_android" = "xyes"; then
226 AC_DEFINE([USE_ANDROID], [1], [Compile with Android specific features enabled])
228 dnl Check if the Android log library is available.
229 AC_CHECK_HEADERS([android/log.h])
230 AC_SEARCH_LIBS(__android_log_write, [log])
235 dnl Tor modules options. These options are namespaced with --disable-module-XXX
239 m4_define(MODULES, dirauth)
241 dnl Directory Authority module.
242 AC_ARG_ENABLE([module-dirauth],
243 AS_HELP_STRING([--disable-module-dirauth],
244 [Do not build tor with the dirauth module]),
245 [], dnl Action if-given
246 AC_DEFINE([HAVE_MODULE_DIRAUTH], [1],
247 [Compile with Directory Authority feature support]))
248 AM_CONDITIONAL(BUILD_MODULE_DIRAUTH, [test "x$enable_module_dirauth" != "xno"])
250 dnl Helper variables.
251 TOR_MODULES_ALL_ENABLED=
252 AC_DEFUN([ADD_MODULE], [
253 MODULE=m4_toupper($1)
254 TOR_MODULES_ALL_ENABLED="${TOR_MODULES_ALL_ENABLED} -DHAVE_MODULE_${MODULE}=1"
256 m4_foreach_w([module], MODULES, [ADD_MODULE([module])])
257 AC_SUBST(TOR_MODULES_ALL_ENABLED)
259 dnl check for the correct "ar" when cross-compiling.
260 dnl (AM_PROG_AR was new in automake 1.11.2, which we do not yet require,
261 dnl so kludge up a replacement for the case where it isn't there yet.)
262 m4_ifdef([AM_PROG_AR],
264 [AN_MAKEVAR([AR], [AC_PROG_AR])
265 AN_PROGRAM([ar], [AC_PROG_AR])
266 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL([AR], [ar], [:])])
269 dnl Check whether the above macro has settled for a simply named tool even
270 dnl though we're cross compiling. We must do this before running AC_PROG_CC,
271 dnl because that will find any cc on the system, not only the cross-compiler,
272 dnl and then verify that a binary built with this compiler runs on the
273 dnl build system. It will then come to the false conclusion that we're not
275 if test "x$enable_tool_name_check" != "xno"; then
276 if test "x$ac_tool_warned" = "xyes"; then
277 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.)])
278 elif test "x$ac_ct_AR" != "x" -a "x$cross_compiling" = "xmaybe"; then
279 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.)])
289 AC_ARG_VAR([PERL], [path to Perl binary])
290 AC_CHECK_PROGS([PERL], [perl])
291 AM_CONDITIONAL(USE_PERL, [test "x$ac_cv_prog_PERL" != "x"])
293 dnl check for asciidoc and a2x
294 AC_PATH_PROG([ASCIIDOC], [asciidoc], none)
295 AC_PATH_PROGS([A2X], [a2x a2x.py], none)
297 AM_CONDITIONAL(USE_ASCIIDOC, test "x$asciidoc" = "xtrue")
302 AC_ARG_VAR([PYTHON], [path to Python binary])
303 AC_CHECK_PROGS(PYTHON, [ \
305 python3.8 python3.7 python3.6 python3.5 python3.4 \
308 if test "x$PYTHON" = "x"; then
309 AC_MSG_WARN([Python unavailable; some tests will not be run.])
311 AM_CONDITIONAL(USEPYTHON, [test "x$PYTHON" != "x"])
313 dnl List all external rust crates we depend on here. Include the version
318 AC_SUBST(rust_crates)
320 ifdef([AC_C_FLEXIBLE_ARRAY_MEMBER], [
321 AC_C_FLEXIBLE_ARRAY_MEMBER
323 dnl Maybe we've got an old autoconf...
324 AC_CACHE_CHECK([for flexible array members],
328 struct abc { int a; char b[]; };
330 struct abc *def = malloc(sizeof(struct abc)+sizeof(char));
333 [tor_cv_c_flexarray=yes],
334 [tor_cv_c_flexarray=no])])
335 if test "$tor_cv_flexarray" = "yes"; then
336 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
338 AC_DEFINE([FLEXIBLE_ARRAY_MEMBER], [1], [Define to nothing if C supports flexible array members, and to 1 if it does not.])
342 AC_CACHE_CHECK([for working C99 mid-block declaration syntax],
345 [AC_LANG_PROGRAM([], [int x; x = 3; int y; y = 4 + x;])],
346 [tor_cv_c_c99_decl=yes],
347 [tor_cv_c_c99_decl=no] )])
348 if test "$tor_cv_c_c99_decl" != "yes"; then
349 AC_MSG_ERROR([Your compiler doesn't support c99 mid-block declarations. This is required as of Tor 0.2.6.x])
352 AC_CACHE_CHECK([for working C99 designated initializers],
353 tor_cv_c_c99_designated_init,
355 [AC_LANG_PROGRAM([struct s { int a; int b; };],
356 [[ struct s ss = { .b = 5, .a = 6 }; ]])],
357 [tor_cv_c_c99_designated_init=yes],
358 [tor_cv_c_c99_designated_init=no] )])
360 if test "$tor_cv_c_c99_designated_init" != "yes"; then
361 AC_MSG_ERROR([Your compiler doesn't support c99 designated initializers. This is required as of Tor 0.2.6.x])
365 AC_ARG_WITH(tor-user,
366 AS_HELP_STRING(--with-tor-user=NAME, [specify username for tor daemon]),
374 AC_ARG_WITH(tor-group,
375 AS_HELP_STRING(--with-tor-group=NAME, [specify group name for tor daemon]),
383 dnl If _WIN32 is defined and non-zero, we are building for win32
384 AC_MSG_CHECKING([for win32])
385 AC_RUN_IFELSE([AC_LANG_SOURCE([
386 int main(int c, char **v) {
397 bwin32=true; AC_MSG_RESULT([yes]),
398 bwin32=false; AC_MSG_RESULT([no]),
399 bwin32=cross; AC_MSG_RESULT([cross])
402 if test "$bwin32" = "cross"; then
403 AC_MSG_CHECKING([for win32 (cross)])
404 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
406 int main(int c, char **v) {return 0;}
409 int main(int c, char **v) {return x(y);}
412 bwin32=true; AC_MSG_RESULT([yes]),
413 bwin32=false; AC_MSG_RESULT([no]))
418 /* Defined to access windows functions and definitions for >=WinXP */
420 # define WINVER 0x0501
423 /* Defined to access _other_ windows functions and definitions for >=WinXP */
424 # ifndef _WIN32_WINNT
425 # define _WIN32_WINNT 0x0501
428 /* Defined to avoid including some windows headers as part of Windows.h */
429 # ifndef WIN32_LEAN_AND_MEAN
430 # define WIN32_LEAN_AND_MEAN 1
436 AM_CONDITIONAL(BUILD_NT_SERVICES, test "x$bwin32" = "xtrue")
437 AM_CONDITIONAL(BUILD_LIBTORRUNNER, test "x$bwin32" != "xtrue")
439 dnl Enable C99 when compiling with MIPSpro
440 AC_MSG_CHECKING([for MIPSpro compiler])
441 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [
442 #if (defined(__sgi) && defined(_COMPILER_VERSION))
447 bmipspro=false; AC_MSG_RESULT(no),
448 bmipspro=true; AC_MSG_RESULT(yes))
450 if test "$bmipspro" = "true"; then
451 CFLAGS="$CFLAGS -c99"
456 AC_ARG_VAR([TOR_RUST_TARGET], [Rust target, must be specified when cross-compiling (HOST != BUILD). example: i686-pc-windows-gnu])
458 if test "x$enable_rust" = "xyes"; then
459 AC_ARG_VAR([RUSTC], [path to the rustc binary])
460 AC_CHECK_PROG([RUSTC], [rustc], [rustc],[no])
461 if test "x$RUSTC" = "xno"; then
462 AC_MSG_ERROR([rustc unavailable but rust integration requested.])
465 AC_ARG_VAR([CARGO], [path to the cargo binary])
466 AC_CHECK_PROG([CARGO], [cargo], [cargo],[no])
467 if test "x$CARGO" = "xno"; then
468 AC_MSG_ERROR([cargo unavailable but rust integration requested.])
471 AC_DEFINE([HAVE_RUST], 1, [have Rust])
472 if test "x$enable_fatal_warnings" = "xyes"; then
477 if test "x$enable_cargo_online_mode" = "xyes"; then
481 CARGO_ONLINE=--frozen
484 dnl When we're not allowed to touch the network, we need crate dependencies
485 dnl locally available.
486 AC_MSG_CHECKING([rust crate dependencies])
487 AC_ARG_VAR([TOR_RUST_DEPENDENCIES], [path to directory with local crate mirror])
488 if test "x$TOR_RUST_DEPENDENCIES" = "x"; then
489 TOR_RUST_DEPENDENCIES="${srcdir}/src/ext/rust/crates"
491 dnl Check whether the path exists before we try to cd into it.
492 if test ! -d "$TOR_RUST_DEPENDENCIES"; then
493 AC_MSG_ERROR([Rust dependency directory $TOR_RUST_DEPENDENCIES does not exist. Specify a dependency directory using the TOR_RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
496 dnl Make the path absolute, since we'll be using it from within a
498 TOR_RUST_DEPENDENCIES=$(cd "$TOR_RUST_DEPENDENCIES" ; pwd)
500 for dep in $rust_crates; do
501 if test ! -d "$TOR_RUST_DEPENDENCIES"/"$dep"; then
502 AC_MSG_ERROR([Failure to find rust dependency $TOR_RUST_DEPENDENCIES/$dep. Specify a dependency directory using the TOR_RUST_DEPENDENCIES variable or allow cargo to fetch crates using --enable-cargo-online-mode.])
506 if test "x$ERRORED" = "x"; then
511 dnl This is a workaround for #46797
512 dnl (a.k.a https://github.com/rust-lang/rust/issues/46797 ). Once the
513 dnl upstream bug is fixed, we can remove this workaround.
516 TOR_RUST_EXTRA_LIBS="-lresolv"
520 dnl For now both MSVC and MinGW rust libraries will output static libs with
521 dnl the MSVC naming convention.
522 if test "$bwin32" = "true"; then
523 tor_rust_static_name=tor_rust.lib
525 tor_rust_static_name=libtor_rust.a
530 if test -n "$TOR_RUST_TARGET"; then
531 if test "$host" = "$build"; then
532 AC_MSG_ERROR([HOST = BUILD is invalid if TOR_RUST_TARGET is specified, see configure --help for more information.])
534 RUST_TARGET_PROP="target = '$TOR_RUST_TARGET'"
535 TOR_RUST_LIB_PATH="src/rust/target/$TOR_RUST_TARGET/release/$tor_rust_static_name"
537 if test "$host" != "$build"; then
538 AC_MSG_ERROR([TOR_RUST_TARGET must be specified when cross-compiling with Rust enabled.])
541 TOR_RUST_LIB_PATH="src/rust/target/release/$tor_rust_static_name"
544 AC_SUBST(RUST_TARGET_PROP)
545 AC_SUBST(TOR_RUST_LIB_PATH)
546 AC_SUBST(CARGO_ONLINE)
550 dnl Let's check the rustc version, too
551 AC_MSG_CHECKING([rust version])
552 RUSTC_VERSION=`$RUSTC --version`
553 RUSTC_VERSION_MAJOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 1`
554 RUSTC_VERSION_MINOR=`$RUSTC --version | cut -d ' ' -f 2 | cut -d '.' -f 2`
555 if test "x$RUSTC_VERSION_MAJOR" = "x" -o "x$RUSTC_VERSION_MINOR" = "x"; then
556 AC_MSG_ERROR([rustc version couldn't be identified])
558 if test "$RUSTC_VERSION_MAJOR" -lt 2 -a "$RUSTC_VERSION_MINOR" -lt 14; then
559 AC_MSG_ERROR([rustc must be at least version 1.14])
561 AC_MSG_RESULT([$RUSTC_VERSION])
564 AC_SUBST(TOR_RUST_EXTRA_LIBS)
566 AC_SEARCH_LIBS(socket, [socket network])
567 AC_SEARCH_LIBS(gethostbyname, [nsl])
568 AC_SEARCH_LIBS(dlopen, [dl])
569 AC_SEARCH_LIBS(inet_aton, [resolv])
570 AC_SEARCH_LIBS(backtrace, [execinfo])
572 AC_SEARCH_LIBS([clock_gettime], [rt])
573 if test "$LIBS" != "$saved_LIBS"; then
574 # Looks like we need -lrt for clock_gettime().
578 if test "$bwin32" = "false"; then
579 AC_SEARCH_LIBS(pthread_create, [pthread])
580 AC_SEARCH_LIBS(pthread_detach, [pthread])
583 AM_CONDITIONAL(THREADS_WIN32, test "$bwin32" = "true")
584 AM_CONDITIONAL(THREADS_PTHREADS, test "$bwin32" = "false")
588 RtlSecureZeroMemory \
592 backtrace_symbols_fd \
598 get_current_dir_name \
605 gnu_get_libc_version \
639 # Apple messed up when they added some functions: they
640 # forgot to decorate them with appropriate AVAILABLE_MAC_OS_VERSION
643 # We should only probe for these functions if we are sure that we
644 # are not targeting OS X 10.9 or earlier.
645 AC_MSG_CHECKING([for a pre-Yosemite OS X build target])
646 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
648 # include <AvailabilityMacros.h>
649 # ifndef MAC_OS_X_VERSION_10_10
650 # define MAC_OS_X_VERSION_10_10 101000
652 # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
653 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_10
654 # error "Running on Mac OS X 10.9 or earlier"
659 [on_macos_pre_10_10=no ; AC_MSG_RESULT([no])],
660 [on_macos_pre_10_10=yes; AC_MSG_RESULT([yes])])
662 if test "$on_macos_pre_10_10" = "no"; then
664 mach_approximate_time \
668 # We should only probe for these functions if we are sure that we
669 # are not targeting OSX 10.11 or earlier.
670 AC_MSG_CHECKING([for a pre-Sierra OSX build target])
671 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
673 # include <AvailabilityMacros.h>
674 # ifndef MAC_OS_X_VERSION_10_12
675 # define MAC_OS_X_VERSION_10_12 101200
677 # if defined(MAC_OS_X_VERSION_MIN_REQUIRED)
678 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
679 # error "Running on Mac OSX 10.11 or earlier"
684 [on_macos_pre_10_12=no ; AC_MSG_RESULT([no])],
685 [on_macos_pre_10_12=yes; AC_MSG_RESULT([yes])])
687 if test "$on_macos_pre_10_12" = "no"; then
694 if test "$bwin32" != "true"; then
695 AC_CHECK_HEADERS(pthread.h)
696 AC_CHECK_FUNCS(pthread_create)
697 AC_CHECK_FUNCS(pthread_condattr_setclock)
700 if test "$bwin32" = "true"; then
701 AC_CHECK_DECLS([SecureZeroMemory, _getwch], , , [
708 AM_CONDITIONAL(BUILD_READPASSPHRASE_C,
709 test "x$ac_cv_func_readpassphrase" = "xno" && test "$bwin32" = "false")
711 AC_MSG_CHECKING([whether free(NULL) works])
712 AC_RUN_IFELSE([AC_LANG_PROGRAM([
718 [free_null_ok=true; AC_MSG_RESULT(yes)],
719 [free_null_ok=false; AC_MSG_RESULT(no)],
720 [free_null_ok=cross; AC_MSG_RESULT(cross)])
722 if test "$free_null_ok" = "false"; then
723 AC_MSG_ERROR([Your libc implementation doesn't allow free(NULL), as required by C99.])
726 dnl ------------------------------------------------------
727 dnl Where do you live, libevent? And how do we call you?
729 if test "$bwin32" = "true"; then
730 TOR_LIB_WS32=-lws2_32
731 TOR_LIB_IPHLPAPI=-liphlpapi
732 # Some of the cargo-cults recommend -lwsock32 as well, but I don't
733 # think it's actually necessary.
735 TOR_LIB_USERENV=-luserenv
741 AC_SUBST(TOR_LIB_WS32)
742 AC_SUBST(TOR_LIB_GDI)
743 AC_SUBST(TOR_LIB_IPHLPAPI)
744 AC_SUBST(TOR_LIB_USERENV)
746 tor_libevent_pkg_redhat="libevent"
747 tor_libevent_pkg_debian="libevent-dev"
748 tor_libevent_devpkg_redhat="libevent-devel"
749 tor_libevent_devpkg_debian="libevent-dev"
751 dnl On Gnu/Linux or any place we require it, we'll add librt to the Libevent
752 dnl linking for static builds.
753 STATIC_LIBEVENT_FLAGS=""
754 if test "$enable_static_libevent" = "yes"; then
755 if test "$have_rt" = "yes"; then
756 STATIC_LIBEVENT_FLAGS=" -lrt "
760 TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32], [
762 #include <winsock2.h>
764 #include <sys/time.h>
765 #include <sys/types.h>
766 #include <event2/event.h>], [
768 #include <winsock2.h>
771 struct event_base *event_base_new(void);
772 void event_base_free(struct event_base *);],
775 {WSADATA d; WSAStartup(0x101,&d); }
777 event_base_free(event_base_new());
778 ], [--with-libevent-dir], [/opt/libevent])
780 dnl Determine the incantation needed to link libevent.
782 save_LDFLAGS="$LDFLAGS"
783 save_CPPFLAGS="$CPPFLAGS"
785 LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
786 LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
787 CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
789 AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
791 if test "$enable_static_libevent" = "yes"; then
792 if test "$tor_cv_library_libevent_dir" = "(system)"; then
793 AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
795 TOR_LIBEVENT_LIBS="$TOR_LIBDIR_libevent/libevent.a $STATIC_LIBEVENT_FLAGS"
798 if test "x$ac_cv_header_event2_event_h" = "xyes"; then
799 AC_SEARCH_LIBS(event_new, [event event_core], , AC_MSG_ERROR("libevent2 is installed but linking it failed while searching for event_new"))
800 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"))
802 if test "$ac_cv_search_event_new" != "none required"; then
803 TOR_LIBEVENT_LIBS="$ac_cv_search_event_new"
805 if test "$ac_cv_search_evdns_base_new" != "none required"; then
806 TOR_LIBEVENT_LIBS="$ac_cv_search_evdns_base_new $TOR_LIBEVENT_LIBS"
809 AC_MSG_ERROR("libevent2 is required but the headers could not be found")
813 dnl Now check for particular libevent functions.
814 AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file \
815 evutil_secure_rng_add_bytes \
819 LDFLAGS="$save_LDFLAGS"
820 CPPFLAGS="$save_CPPFLAGS"
822 dnl Check that libevent is at least at version 2.0.10, the first stable
823 dnl release of its series
824 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
825 AC_MSG_CHECKING([whether Libevent is new enough])
826 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
827 #include <event2/event.h>
828 #if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
834 ])], [ AC_MSG_RESULT([yes]) ],
835 [ AC_MSG_RESULT([no])
836 AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
839 LDFLAGS="$save_LDFLAGS"
840 CPPFLAGS="$save_CPPFLAGS"
842 AC_SUBST(TOR_LIBEVENT_LIBS)
844 dnl ------------------------------------------------------
845 dnl Where do you live, libm?
847 dnl On some platforms (Haiku/BeOS) the math library is
848 dnl part of libroot. In which case don't link against lm
851 AC_SEARCH_LIBS(pow, [m], , AC_MSG_ERROR([Could not find pow in libm or libc.]))
852 if test "$ac_cv_search_pow" != "none required"; then
853 TOR_LIB_MATH="$ac_cv_search_pow"
856 AC_SUBST(TOR_LIB_MATH)
858 dnl ------------------------------------------------------
859 dnl Where do you live, openssl? And how do we call you?
861 tor_openssl_pkg_redhat="openssl"
862 tor_openssl_pkg_debian="libssl-dev"
863 tor_openssl_devpkg_redhat="openssl-devel"
864 tor_openssl_devpkg_debian="libssl-dev"
866 ALT_openssl_WITHVAL=""
868 AS_HELP_STRING(--with-ssl-dir=PATH, [obsolete alias for --with-openssl-dir]),
870 if test "x$withval" != "xno" && test "x$withval" != "x"; then
871 ALT_openssl_WITHVAL="$withval"
875 AC_MSG_NOTICE([Now, we'll look for OpenSSL >= 1.0.1])
876 TOR_SEARCH_LIBRARY(openssl, $tryssldir, [-lssl -lcrypto $TOR_LIB_GDI $TOR_LIB_WS32],
877 [#include <openssl/ssl.h>
878 char *getenv(const char *);],
879 [struct ssl_cipher_st;
880 unsigned SSL_CIPHER_get_id(const struct ssl_cipher_st *);
881 char *getenv(const char *);],
882 dnl This funny-looking test program calls getenv, so that the compiler
883 dnl will neither make code that call SSL_CIPHER_get_id(NULL) [producing
884 dnl a crash], nor optimize out the call to SSL_CIPHER_get_id().
885 dnl We look for SSL_cipher_get_id() because it is present in
886 dnl OpenSSL >=1.0.1, because it is not deprecated, and because Tor
888 [if (getenv("THIS_SHOULDNT_BE_SET_X201803")) SSL_CIPHER_get_id((void *)0);], [],
889 [/usr/local/opt/openssl /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /opt/openssl])
891 dnl XXXX check for OPENSSL_VERSION_NUMBER == SSLeay()
893 if test "$enable_static_openssl" = "yes"; then
894 if test "$tor_cv_library_openssl_dir" = "(system)"; then
895 AC_MSG_ERROR("You must specify an explicit --with-openssl-dir=x option when using --enable-static-openssl")
897 TOR_OPENSSL_LIBS="$TOR_LIBDIR_openssl/libssl.a $TOR_LIBDIR_openssl/libcrypto.a"
900 TOR_OPENSSL_LIBS="-lssl -lcrypto"
902 AC_SUBST(TOR_OPENSSL_LIBS)
904 dnl Now check for particular openssl functions.
906 save_LDFLAGS="$LDFLAGS"
907 save_CPPFLAGS="$CPPFLAGS"
908 LIBS="$TOR_OPENSSL_LIBS $LIBS"
909 LDFLAGS="$TOR_LDFLAGS_openssl $LDFLAGS"
910 CPPFLAGS="$TOR_CPPFLAGS_openssl $CPPFLAGS"
912 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
913 #include <openssl/opensslv.h>
914 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x1000100fL
919 [ AC_MSG_ERROR([OpenSSL is too old. We require 1.0.1 or later. You can specify a path to a newer one with --with-openssl-dir.]) ])
921 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
922 #include <openssl/opensslv.h>
923 #include <openssl/evp.h>
924 #if defined(OPENSSL_NO_EC) || defined(OPENSSL_NO_ECDH) || defined(OPENSSL_NO_ECDSA)
927 #if !defined(NID_X9_62_prime256v1) || !defined(NID_secp224r1)
928 #error "curves unavailable"
932 [ 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.]) ])
934 AC_CHECK_MEMBERS([struct ssl_method_st.get_cipher_by_char], , ,
935 [#include <openssl/ssl.h>
939 SSL_SESSION_get_master_key \
940 SSL_get_server_random \
941 SSL_get_client_ciphers \
942 SSL_get_client_random \
943 SSL_CTX_set1_groups_list \
945 SSL_CTX_set_security_level \
949 dnl Check if OpenSSL has scrypt implementation.
950 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
952 dnl Check if OpenSSL structures are opaque
953 AC_CHECK_MEMBERS([SSL.state], , ,
954 [#include <openssl/ssl.h>
957 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
958 #include <openssl/sha.h>
961 dnl Define the set of checks for KIST scheduler support.
962 AC_DEFUN([CHECK_KIST_SUPPORT],[
963 dnl KIST needs struct tcp_info and for certain members to exist.
965 [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
966 , ,[[#include <netinet/tcp.h>]])
967 dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
968 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
969 #include <linux/sockios.h>
973 ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
974 if test "x$have_siocoutqnsd" = "xyes"; then
975 if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
976 if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
977 have_kist_support=yes
982 dnl Now, trigger the check.
984 AS_IF([test "x$have_kist_support" = "xyes"],
985 [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
987 [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
990 LDFLAGS="$save_LDFLAGS"
991 CPPFLAGS="$save_CPPFLAGS"
993 dnl ------------------------------------------------------
994 dnl Where do you live, zlib? And how do we call you?
996 tor_zlib_pkg_redhat="zlib"
997 tor_zlib_pkg_debian="zlib1g"
998 tor_zlib_devpkg_redhat="zlib-devel"
999 tor_zlib_devpkg_debian="zlib1g-dev"
1001 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1002 [#include <zlib.h>],
1003 [const char * zlibVersion(void);],
1004 [zlibVersion();], [--with-zlib-dir],
1007 if test "$enable_static_zlib" = "yes"; then
1008 if test "$tor_cv_library_zlib_dir" = "(system)"; then
1009 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1010 using --enable-static-zlib")
1012 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1017 AC_SUBST(TOR_ZLIB_LIBS)
1019 dnl ------------------------------------------------------
1020 dnl Where we do we find lzma?
1023 AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1024 [case "${enableval}" in
1027 * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1030 if test "x$enable_lzma" = "xno"; then
1033 PKG_CHECK_MODULES([LZMA],
1038 if test "x$have_lzma" = "xno" ; then
1039 AC_MSG_WARN([Unable to find liblzma.])
1043 if test "x$have_lzma" = "xyes"; then
1044 AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1045 TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1046 TOR_LZMA_LIBS="${LZMA_LIBS}"
1048 AC_SUBST(TOR_LZMA_CFLAGS)
1049 AC_SUBST(TOR_LZMA_LIBS)
1051 dnl ------------------------------------------------------
1052 dnl Where we do we find zstd?
1055 AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1056 [case "${enableval}" in
1059 * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1062 if test "x$enable_zstd" = "xno"; then
1065 PKG_CHECK_MODULES([ZSTD],
1070 if test "x$have_zstd" = "xno" ; then
1071 AC_MSG_WARN([Unable to find libzstd.])
1075 if test "x$have_zstd" = "xyes"; then
1076 AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1077 TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1078 TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1080 dnl now check for zstd functions
1082 save_CFLAGS="$CFLAGS"
1083 LIBS="$LIBS $ZSTD_LIBS"
1084 CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1085 AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1086 ZSTD_estimateDCtxSize)
1088 CFLAGS="$save_CFLAGS"
1090 AC_SUBST(TOR_ZSTD_CFLAGS)
1091 AC_SUBST(TOR_ZSTD_LIBS)
1093 dnl ----------------------------------------------------------------------
1094 dnl Check if libcap is available for capabilities.
1096 tor_cap_pkg_debian="libcap2"
1097 tor_cap_pkg_redhat="libcap"
1098 tor_cap_devpkg_debian="libcap-dev"
1099 tor_cap_devpkg_redhat="libcap-devel"
1101 AC_CHECK_LIB([cap], [cap_init], [],
1102 AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1104 AC_CHECK_FUNCS(cap_set_proc)
1106 dnl ---------------------------------------------------------------------
1107 dnl Now that we know about our major libraries, we can check for compiler
1108 dnl and linker hardening options. We need to do this with the libraries known,
1109 dnl since sometimes the linker will like an option but not be willing to
1110 dnl use it with a build of a library.
1112 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1113 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"
1121 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1122 #if !defined(__clang__)
1124 #endif])], have_clang=yes, have_clang=no)
1126 if test "x$enable_gcc_hardening" != "xno"; then
1127 CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1128 if test "x$have_clang" = "xyes"; then
1129 TOR_CHECK_CFLAGS(-Qunused-arguments)
1131 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1132 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1133 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1134 m4_ifdef([AS_VAR_IF],[
1135 AS_VAR_IF(can_compile, [yes],
1136 AS_VAR_IF(can_link, [yes],
1138 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.)]))
1140 AS_VAR_POPDEF([can_link])
1141 AS_VAR_POPDEF([can_compile])
1142 TOR_CHECK_CFLAGS(-Wstack-protector)
1143 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1144 if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1145 TOR_CHECK_CFLAGS(-fPIE)
1146 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1148 TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1151 if test "$fragile_hardening" = "yes"; then
1152 TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1153 if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1154 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.])
1157 if test "$tor_cv_cflags__ftrapv" != "yes"; then
1158 AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1161 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1162 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1163 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*])
1166 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1167 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1168 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*])
1171 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1174 dnl Find the correct libraries to add in order to use the sanitizers.
1176 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1177 dnl option, which will prevent the compiler from linking the sanitizer
1178 dnl libraries it needs. We need to specify them manually.
1180 dnl What's more, we need to specify them in a linker script rather than
1181 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1183 RUST_LINKER_OPTIONS=""
1184 if test "x$have_clang" = "xyes"; then
1185 if test "x$CFLAGS_ASAN" != "x"; then
1186 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_ASAN"
1188 if test "x$CFLAGS_UBSAN" != "x"; then
1189 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_UBSAN"
1192 if test "x$CFLAGS_ASAN" != "x"; then
1193 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lasan"
1195 if test "x$CFLAGS_UBSAN" != "x"; then
1196 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lubsan"
1199 AC_SUBST(RUST_LINKER_OPTIONS)
1201 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1202 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1204 mulodi_fixes_ftrapv=no
1205 if test "$have_clang" = "yes"; then
1206 saved_CFLAGS="$CFLAGS"
1207 CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1208 AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1213 int main(int argc, char **argv)
1215 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1216 * (int64_t)atoi(argv[3]);
1219 [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1220 [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1221 if test "$ftrapv_can_link" = "no"; then
1222 AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1227 int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1231 int main(int argc, char **argv)
1233 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1234 * (int64_t)atoi(argv[3]);
1237 [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1238 [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1240 CFLAGS="$saved_CFLAGS"
1243 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1245 dnl These cflags add bunches of branches, and we haven't been able to
1246 dnl persuade ourselves that they're suitable for code that needs to be
1248 AC_SUBST(CFLAGS_BUGTRAP)
1249 dnl These cflags are variant ones sutable for code that needs to be
1251 AC_SUBST(CFLAGS_CONSTTIME)
1253 if test "x$enable_linker_hardening" != "xno"; then
1254 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1257 # For backtrace support
1258 TOR_CHECK_LDFLAGS(-rdynamic)
1260 dnl ------------------------------------------------------
1261 dnl Now see if we have a -fomit-frame-pointer compiler option.
1263 saved_CFLAGS="$CFLAGS"
1264 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1265 F_OMIT_FRAME_POINTER=''
1266 if test "$saved_CFLAGS" != "$CFLAGS"; then
1267 if test "$fragile_hardening" = "yes"; then
1268 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1271 CFLAGS="$saved_CFLAGS"
1272 AC_SUBST(F_OMIT_FRAME_POINTER)
1274 dnl ------------------------------------------------------
1275 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1276 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1277 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1279 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1281 dnl ============================================================
1282 dnl Check for libseccomp
1284 if test "x$enable_seccomp" != "xno"; then
1285 AC_CHECK_HEADERS([seccomp.h])
1286 AC_SEARCH_LIBS(seccomp_init, [seccomp])
1289 dnl ============================================================
1290 dnl Check for libscrypt
1292 if test "x$enable_libscrypt" != "xno"; then
1293 AC_CHECK_HEADERS([libscrypt.h])
1294 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1295 AC_CHECK_FUNCS([libscrypt_scrypt])
1298 dnl ============================================================
1299 dnl We need an implementation of curve25519.
1301 dnl set these defaults.
1302 build_curve25519_donna=no
1303 build_curve25519_donna_c64=no
1304 use_curve25519_donna=no
1305 use_curve25519_nacl=no
1308 dnl The best choice is using curve25519-donna-c64, but that requires
1310 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1311 tor_cv_can_use_curve25519_donna_c64,
1313 [AC_LANG_PROGRAM([dnl
1315 typedef unsigned uint128_t __attribute__((mode(TI)));
1316 int func(uint64_t a, uint64_t b) {
1317 uint128_t c = ((uint128_t)a) * b;
1318 int ok = ((uint64_t)(c>>96)) == 522859 &&
1319 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1320 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1321 (((uint64_t)(c))&0xffffffffL) == 0;
1325 int ok = func( ((uint64_t)2000000000) * 1000000000,
1326 ((uint64_t)1234567890) << 24);
1329 [tor_cv_can_use_curve25519_donna_c64=yes],
1330 [tor_cv_can_use_curve25519_donna_c64=no],
1332 [AC_LANG_PROGRAM([dnl
1334 typedef unsigned uint128_t __attribute__((mode(TI)));
1335 int func(uint64_t a, uint64_t b) {
1336 uint128_t c = ((uint128_t)a) * b;
1337 int ok = ((uint64_t)(c>>96)) == 522859 &&
1338 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1339 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1340 (((uint64_t)(c))&0xffffffffL) == 0;
1344 int ok = func( ((uint64_t)2000000000) * 1000000000,
1345 ((uint64_t)1234567890) << 24);
1348 [tor_cv_can_use_curve25519_donna_c64=cross],
1349 [tor_cv_can_use_curve25519_donna_c64=no])])])
1351 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1352 nacl/crypto_scalarmult_curve25519.h])
1354 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1355 tor_cv_can_use_curve25519_nacl,
1356 [tor_saved_LIBS="$LIBS"
1359 [AC_LANG_PROGRAM([dnl
1360 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1361 #include <crypto_scalarmult_curve25519.h>
1362 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1363 #include <nacl/crypto_scalarmult_curve25519.h>
1365 #ifdef crypto_scalarmult_curve25519_ref_BYTES
1366 #error Hey, this is the reference implementation! That's not fast.
1369 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1370 ])], [tor_cv_can_use_curve25519_nacl=yes],
1371 [tor_cv_can_use_curve25519_nacl=no])
1372 LIBS="$tor_saved_LIBS" ])
1374 dnl Okay, now we need to figure out which one to actually use. Fall back
1375 dnl to curve25519-donna.c
1377 if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1378 build_curve25519_donna_c64=yes
1379 use_curve25519_donna=yes
1380 elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1381 use_curve25519_nacl=yes
1382 CURVE25519_LIBS=-lnacl
1384 build_curve25519_donna=yes
1385 use_curve25519_donna=yes
1388 if test "x$use_curve25519_donna" = "xyes"; then
1389 AC_DEFINE(USE_CURVE25519_DONNA, 1,
1390 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1392 if test "x$use_curve25519_nacl" = "xyes"; then
1393 AC_DEFINE(USE_CURVE25519_NACL, 1,
1394 [Defined if we should use a curve25519 from nacl])
1396 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1397 test "x$build_curve25519_donna" = "xyes")
1398 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1399 test "x$build_curve25519_donna_c64" = "xyes")
1400 AC_SUBST(CURVE25519_LIBS)
1402 dnl Make sure to enable support for large off_t if available.
1405 AC_CHECK_HEADERS([assert.h \
1420 gnu/libc-version.h \
1460 AC_CHECK_HEADERS(sys/param.h)
1462 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1463 [#ifdef HAVE_SYS_TYPES_H
1464 #include <sys/types.h>
1466 #ifdef HAVE_SYS_SOCKET_H
1467 #include <sys/socket.h>
1469 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1470 [#ifdef HAVE_SYS_TYPES_H
1471 #include <sys/types.h>
1473 #ifdef HAVE_SYS_SOCKET_H
1474 #include <sys/socket.h>
1476 #ifdef HAVE_NET_IF_H
1479 #ifdef HAVE_NETINET_IN_H
1480 #include <netinet/in.h>
1483 AC_CHECK_HEADERS(linux/if.h,[],[],
1485 #ifdef HAVE_SYS_SOCKET_H
1486 #include <sys/socket.h>
1490 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1491 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1492 [#ifdef HAVE_SYS_TYPES_H
1493 #include <sys/types.h>
1495 #ifdef HAVE_SYS_SOCKET_H
1496 #include <sys/socket.h>
1498 #ifdef HAVE_LIMITS_H
1501 #ifdef HAVE_LINUX_TYPES_H
1502 #include <linux/types.h>
1504 #ifdef HAVE_NETINET_IN6_H
1505 #include <netinet/in6.h>
1507 #ifdef HAVE_NETINET_IN_H
1508 #include <netinet/in.h>
1511 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1512 linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1513 [#ifdef HAVE_SYS_TYPES_H
1514 #include <sys/types.h>
1516 #ifdef HAVE_SYS_SOCKET_H
1517 #include <sys/socket.h>
1519 #ifdef HAVE_LIMITS_H
1522 #ifdef HAVE_LINUX_TYPES_H
1523 #include <linux/types.h>
1525 #ifdef HAVE_NETINET_IN6_H
1526 #include <netinet/in6.h>
1528 #ifdef HAVE_NETINET_IN_H
1529 #include <netinet/in.h>
1531 #ifdef HAVE_LINUX_IF_H
1532 #include <linux/if.h>
1536 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1539 if test "x$linux_netfilter_ipv4" = "x1"; then
1542 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1545 if test "x$transparent_ok" = "x1"; then
1546 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1548 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1551 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1552 [#ifdef HAVE_SYS_TYPES_H
1553 #include <sys/types.h>
1555 #ifdef HAVE_SYS_TIME_H
1556 #include <sys/time.h>
1559 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1562 AC_CHECK_SIZEOF(int8_t)
1563 AC_CHECK_SIZEOF(int16_t)
1564 AC_CHECK_SIZEOF(int32_t)
1565 AC_CHECK_SIZEOF(int64_t)
1566 AC_CHECK_SIZEOF(uint8_t)
1567 AC_CHECK_SIZEOF(uint16_t)
1568 AC_CHECK_SIZEOF(uint32_t)
1569 AC_CHECK_SIZEOF(uint64_t)
1570 AC_CHECK_SIZEOF(intptr_t)
1571 AC_CHECK_SIZEOF(uintptr_t)
1573 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1575 AC_CHECK_SIZEOF(char)
1576 AC_CHECK_SIZEOF(short)
1577 AC_CHECK_SIZEOF(int)
1578 AC_CHECK_SIZEOF(long)
1579 AC_CHECK_SIZEOF(long long)
1580 AC_CHECK_SIZEOF(__int64)
1581 AC_CHECK_SIZEOF(void *)
1582 AC_CHECK_SIZEOF(time_t)
1583 AC_CHECK_SIZEOF(size_t)
1584 AC_CHECK_SIZEOF(pid_t)
1586 AC_CHECK_TYPES([uint, u_char, ssize_t])
1588 AC_PC_FROM_UCONTEXT([:])
1590 dnl used to include sockaddr_storage, but everybody has that.
1591 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1592 [#ifdef HAVE_SYS_TYPES_H
1593 #include <sys/types.h>
1595 #ifdef HAVE_NETINET_IN_H
1596 #include <netinet/in.h>
1598 #ifdef HAVE_NETINET_IN6_H
1599 #include <netinet/in6.h>
1601 #ifdef HAVE_SYS_SOCKET_H
1602 #include <sys/socket.h>
1605 #define _WIN32_WINNT 0x0501
1606 #define WIN32_LEAN_AND_MEAN
1607 #include <winsock2.h>
1608 #include <ws2tcpip.h>
1611 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1612 [#ifdef HAVE_SYS_TYPES_H
1613 #include <sys/types.h>
1615 #ifdef HAVE_NETINET_IN_H
1616 #include <netinet/in.h>
1618 #ifdef HAVE_NETINET_IN6_H
1619 #include <netinet/in6.h>
1621 #ifdef HAVE_SYS_SOCKET_H
1622 #include <sys/socket.h>
1625 #define _WIN32_WINNT 0x0501
1626 #define WIN32_LEAN_AND_MEAN
1627 #include <winsock2.h>
1628 #include <ws2tcpip.h>
1632 AC_CHECK_TYPES([rlim_t], , ,
1633 [#ifdef HAVE_SYS_TYPES_H
1634 #include <sys/types.h>
1636 #ifdef HAVE_SYS_TIME_H
1637 #include <sys/time.h>
1639 #ifdef HAVE_SYS_RESOURCE_H
1640 #include <sys/resource.h>
1644 AX_CHECK_SIGN([time_t],
1647 #ifdef HAVE_SYS_TYPES_H
1648 #include <sys/types.h>
1650 #ifdef HAVE_SYS_TIME_H
1651 #include <sys/time.h>
1658 if test "$ax_cv_decl_time_t_signed" = "no"; then
1659 AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1662 AX_CHECK_SIGN([size_t],
1663 [ tor_cv_size_t_signed=yes ],
1664 [ tor_cv_size_t_signed=no ], [
1665 #ifdef HAVE_SYS_TYPES_H
1666 #include <sys/types.h>
1670 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1671 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1674 AX_CHECK_SIGN([enum always],
1675 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1677 enum always { AAA, BBB, CCC };
1680 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1681 #ifdef HAVE_SYS_SOCKET_H
1682 #include <sys/socket.h>
1686 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1688 AC_CHECK_SIZEOF(cell_t)
1690 # Let's see if stdatomic works. (There are some debian clangs that screw it
1691 # up; see Tor bug #26779 and debian bug 903709.)
1692 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1693 tor_cv_stdatomic_works,
1694 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1695 #include <stdatomic.h>
1696 struct x { atomic_size_t y; };
1697 void try_atomic_init(struct x *xx)
1699 atomic_init(&xx->y, 99);
1700 atomic_fetch_add(&xx->y, 1);
1702 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1704 if test "$tor_cv_stdatomic_works" = "yes"; then
1705 AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1706 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1707 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 ])
1710 # Now make sure that NULL can be represented as zero bytes.
1711 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1712 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1713 [[#include <stdlib.h>
1716 #ifdef HAVE_STDDEF_H
1719 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1720 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1721 [tor_cv_null_is_zero=yes],
1722 [tor_cv_null_is_zero=no],
1723 [tor_cv_null_is_zero=cross])])
1725 if test "$tor_cv_null_is_zero" = "cross"; then
1726 # Cross-compiling; let's hope that the target isn't raving mad.
1727 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1730 if test "$tor_cv_null_is_zero" != "no"; then
1731 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1732 [Define to 1 iff memset(0) sets pointers to NULL])
1735 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1736 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1737 [[#include <stdlib.h>
1740 #ifdef HAVE_STDDEF_H
1743 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1744 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1745 [tor_cv_dbl0_is_zero=yes],
1746 [tor_cv_dbl0_is_zero=no],
1747 [tor_cv_dbl0_is_zero=cross])])
1749 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1750 # Cross-compiling; let's hope that the target isn't raving mad.
1751 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1754 if test "$tor_cv_dbl0_is_zero" != "no"; then
1755 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1756 [Define to 1 iff memset(0) sets doubles to 0.0])
1759 # And what happens when we malloc zero?
1760 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1761 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1762 [[#include <stdlib.h>
1765 #ifdef HAVE_STDDEF_H
1768 int main () { return malloc(0)?0:1; }]])],
1769 [tor_cv_malloc_zero_works=yes],
1770 [tor_cv_malloc_zero_works=no],
1771 [tor_cv_malloc_zero_works=cross])])
1773 if test "$tor_cv_malloc_zero_works" = "cross"; then
1774 # Cross-compiling; let's hope that the target isn't raving mad.
1775 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1778 if test "$tor_cv_malloc_zero_works" = "yes"; then
1779 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1780 [Define to 1 iff malloc(0) returns a pointer])
1783 # whether we seem to be in a 2s-complement world.
1784 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1785 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1786 [[int main () { int problem = ((-99) != (~99)+1);
1787 return problem ? 1 : 0; }]])],
1788 [tor_cv_twos_complement=yes],
1789 [tor_cv_twos_complement=no],
1790 [tor_cv_twos_complement=cross])])
1792 if test "$tor_cv_twos_complement" = "cross"; then
1793 # Cross-compiling; let's hope that the target isn't raving mad.
1794 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1797 if test "$tor_cv_twos_complement" != "no"; then
1798 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1799 [Define to 1 iff we represent negative integers with
1803 # What does shifting a negative value do?
1804 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1805 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1806 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1807 [tor_cv_sign_extend=yes],
1808 [tor_cv_sign_extend=no],
1809 [tor_cv_sign_extend=cross])])
1811 if test "$tor_cv_sign_extend" = "cross"; then
1812 # Cross-compiling; let's hope that the target isn't raving mad.
1813 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1816 if test "$tor_cv_sign_extend" != "no"; then
1817 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1818 [Define to 1 iff right-shifting a negative value performs sign-extension])
1821 # Is uint8_t the same type as unsigned char?
1822 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1823 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1826 unsigned char c;]])],
1827 [tor_cv_uint8_uchar=yes],
1828 [tor_cv_uint8_uchar=no],
1829 [tor_cv_uint8_uchar=cross])])
1831 if test "$tor_cv_uint8_uchar" = "cross"; then
1832 AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1835 if test "$tor_cv_uint8_uchar" = "no"; then
1836 AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1839 # Whether we should use the dmalloc memory allocation debugging library.
1840 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1841 AC_ARG_WITH(dmalloc,
1842 AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
1843 [if [[ "$withval" = "yes" ]]; then
1849 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1852 if [[ $dmalloc -eq 1 ]]; then
1853 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1854 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1855 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1856 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1859 AC_ARG_WITH(tcmalloc,
1860 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1861 [ tcmalloc=yes ], [ tcmalloc=no ])
1863 if test "x$tcmalloc" = "xyes"; then
1864 LDFLAGS="-ltcmalloc $LDFLAGS"
1867 using_custom_malloc=no
1868 if test "x$enable_openbsd_malloc" = "xyes"; then
1869 using_custom_malloc=yes
1871 if test "x$tcmalloc" = "xyes"; then
1872 using_custom_malloc=yes
1874 if test "$using_custom_malloc" = "no"; then
1875 AC_CHECK_FUNCS(mallinfo)
1877 if test "$using_custom_malloc" = "yes"; then
1878 # Tell the C compiler not to use the system allocator functions.
1879 TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
1882 # By default, we're going to assume we don't have mlockall()
1883 # bionic and other platforms have various broken mlockall subsystems.
1884 # Some systems don't have a working mlockall, some aren't linkable,
1885 # and some have it but don't declare it.
1886 AC_CHECK_FUNCS(mlockall)
1887 AC_CHECK_DECLS([mlockall], , , [
1888 #ifdef HAVE_SYS_MMAN_H
1889 #include <sys/mman.h>
1892 # Allow user to specify an alternate syslog facility
1893 AC_ARG_WITH(syslog-facility,
1894 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1895 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1896 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1897 AC_SUBST(LOGFACILITY)
1899 # Check if we have getresuid and getresgid
1900 AC_CHECK_FUNCS(getresuid getresgid)
1902 # Check for gethostbyname_r in all its glorious incompatible versions.
1903 # (This logic is based on that in Python's configure.in)
1904 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1905 [Define this if you have any gethostbyname_r()])
1907 AC_CHECK_FUNC(gethostbyname_r, [
1908 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1910 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1911 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1915 struct hostent *h1, *h2;
1917 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1919 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1920 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1921 [Define this if gethostbyname_r takes 6 arguments])
1924 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1930 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1932 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1933 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1934 [Define this if gethostbyname_r takes 5 arguments])
1937 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1942 struct hostent_data hd;
1943 (void) gethostbyname_r(cp1,h1,&hd);
1945 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1946 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1947 [Define this if gethostbyname_r takes 3 arguments])
1957 AC_CACHE_CHECK([whether the C compiler supports __func__],
1958 tor_cv_have_func_macro,
1959 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1961 int main(int c, char **v) { puts(__func__); }])],
1962 tor_cv_have_func_macro=yes,
1963 tor_cv_have_func_macro=no))
1965 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1966 tor_cv_have_FUNC_macro,
1967 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1969 int main(int c, char **v) { puts(__FUNC__); }])],
1970 tor_cv_have_FUNC_macro=yes,
1971 tor_cv_have_FUNC_macro=no))
1973 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1974 tor_cv_have_FUNCTION_macro,
1975 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1977 int main(int c, char **v) { puts(__FUNCTION__); }])],
1978 tor_cv_have_FUNCTION_macro=yes,
1979 tor_cv_have_FUNCTION_macro=no))
1981 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1982 tor_cv_have_environ_declared,
1983 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1984 #ifdef HAVE_UNISTD_H
1988 int main(int c, char **v) { char **t = environ; }])],
1989 tor_cv_have_environ_declared=yes,
1990 tor_cv_have_environ_declared=no))
1992 if test "$tor_cv_have_func_macro" = "yes"; then
1993 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1996 if test "$tor_cv_have_FUNC_macro" = "yes"; then
1997 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
2000 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2001 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2002 [Defined if the compiler supports __FUNCTION__])
2005 if test "$tor_cv_have_environ_declared" = "yes"; then
2006 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2007 [Defined if we have extern char **environ already declared])
2010 # $prefix stores the value of the --prefix command line option, or
2011 # NONE if the option wasn't set. In the case that it wasn't set, make
2012 # it be the default, so that we can use it to expand directories now.
2013 if test "x$prefix" = "xNONE"; then
2014 prefix=$ac_default_prefix
2017 # and similarly for $exec_prefix
2018 if test "x$exec_prefix" = "xNONE"; then
2022 if test "x$BUILDDIR" = "x"; then
2026 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2027 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2029 if test "x$SRCDIR" = "x"; then
2030 SRCDIR=$(cd "$srcdir"; pwd)
2032 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2033 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2035 if test "x$CONFDIR" = "x"; then
2036 CONFDIR=`eval echo $sysconfdir/tor`
2039 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2040 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2042 BINDIR=`eval echo $bindir`
2044 LOCALSTATEDIR=`eval echo $localstatedir`
2045 AC_SUBST(LOCALSTATEDIR)
2047 if test "$bwin32" = "true"; then
2048 # Test if the linker supports the --nxcompat and --dynamicbase options
2050 save_LDFLAGS="$LDFLAGS"
2051 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2052 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2053 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2054 [AC_MSG_RESULT([yes])]
2055 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2056 [AC_MSG_RESULT([no])]
2058 LDFLAGS="$save_LDFLAGS"
2061 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2062 # than autoconf's macros like.
2063 if test "$GCC" = "yes"; then
2064 # Disable GCC's strict aliasing checks. They are an hours-to-debug
2065 # accident waiting to happen.
2066 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2068 # Override optimization level for non-gcc compilers
2070 enable_gcc_warnings=no
2071 enable_gcc_warnings_advisory=no
2074 # Warnings implies advisory-warnings and -Werror.
2075 if test "$enable_gcc_warnings" = "yes"; then
2076 enable_gcc_warnings_advisory=yes
2077 enable_fatal_warnings=yes
2080 # OS X Lion started deprecating the system openssl. Let's just disable
2081 # all deprecation warnings on OS X. Also, to potentially make the binary
2082 # a little smaller, let's enable dead_strip.
2086 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2087 LDFLAGS="$LDFLAGS -dead_strip" ;;
2090 # Add some more warnings which we use in development but not in the
2091 # released versions. (Some relevant gcc versions can't handle these.)
2093 # Note that we have to do this near the end of the autoconf process, or
2094 # else we may run into problems when these warnings hit on the testing C
2095 # programs that autoconf wants to build.
2096 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2099 *-*-openbsd* | *-*-bitrig*)
2100 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2101 # That's fine, except that the headers don't pass -Wredundant-decls.
2102 # Therefore, let's disable -Wsystem-headers when we're building
2103 # with maximal warnings on OpenBSD.
2104 CFLAGS="$CFLAGS -Wno-system-headers" ;;
2107 # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
2108 # have it work better.
2109 # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2111 # This warning was added in gcc 4.3, but it appears to generate
2112 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
2113 #CFLAGS="$CFLAGS -Wlogical-op"
2115 m4_foreach_w([warning_flag], [
2117 -Waddress-of-array-temporary
2118 -Waddress-of-temporary
2120 -Wanonymous-pack-parens
2123 -Warc-bridge-casts-disallowed-in-nonarc
2124 -Warc-maybe-repeated-use-of-weak
2125 -Warc-performSelector-leaks
2126 -Warc-repeated-use-of-weak
2128 -Warray-bounds-pointer-arithmetic
2130 -Wasm-operand-widths
2132 -Watomic-property-with-user-defined-accessor
2134 -Wauto-storage-class
2137 -Wbackslash-newline-escape
2138 -Wbad-array-new-length
2139 -Wbind-to-temporary-copy
2140 -Wbitfield-constant-conversion
2143 -Wbuiltin-requires-header
2145 -Wcompare-distinct-pointer-types
2146 -Wcomplex-component-init
2147 -Wconditional-type-mismatch
2149 -Wconstant-conversion
2150 -Wconstant-logical-operand
2151 -Wconstexpr-not-const
2152 -Wcustom-atomic-properties
2154 -Wdangling-initializer-list
2156 -Wdelegating-ctor-cycles
2157 -Wdeprecated-implementations
2158 -Wdeprecated-register
2159 -Wdirect-ivar-access
2161 -Wdistributed-object-modifiers
2163 -Wdollar-in-identifier-extension
2165 -Wduplicate-decl-specifier
2167 -Wduplicate-method-arg
2168 -Wduplicate-method-match
2170 -Wdynamic-class-memaccess
2171 -Wembedded-directive
2172 -Wempty-translation-unit
2174 -Wexit-time-destructors
2175 -Wexplicit-ownership-type
2176 -Wextern-initializer
2180 -Wflexible-array-extensions
2183 -Wfour-char-constants
2185 -Wglobal-constructors
2186 -Wgnu-array-member-paren-init
2188 -Wgnu-static-float-init
2191 -Widiomatic-parentheses
2192 -Wignored-attributes
2193 -Wimplicit-atomic-properties
2194 -Wimplicit-conversion-floating-point-to-bool
2195 -Wimplicit-exception-spec-mismatch
2196 -Wimplicit-fallthrough
2197 -Wimplicit-fallthrough-per-function
2198 -Wimplicit-retain-self
2199 -Wimport-preprocessor-directive-pedantic
2200 -Wincompatible-library-redeclaration
2201 -Wincompatible-pointer-types-discards-qualifiers
2202 -Wincomplete-implementation
2204 -Wincomplete-umbrella
2207 -Wint-to-void-pointer-cast
2213 -Winvalid-source-encoding
2214 -Winvalid-token-paste
2215 -Wknr-promoted-parameter
2216 -Wlarge-by-value-copy
2217 -Wliteral-conversion
2219 -Wlocal-type-template-args
2223 -Wmalformed-warning-check
2227 -Wmismatched-parameter-types
2228 -Wmismatched-return-types
2229 -Wmissing-field-initializers
2230 -Wmissing-format-attribute
2232 -Wmissing-selector-name
2234 -Wmissing-variable-declarations
2238 -Wnon-literal-null-conversion
2240 -Wnonportable-cfstrings
2246 -Wout-of-line-declaration
2248 -Woverlength-strings
2250 -Woverriding-method-mismatch
2251 -Wpointer-type-mismatch
2252 -Wpredefined-identifier-outside-function
2253 -Wprotocol-property-synthesis-ambiguity
2254 -Wreadonly-iboutlet-property
2255 -Wreadonly-setter-attrs
2257 -Wreceiver-forward-class
2259 -Wreinterpret-base-class
2260 -Wrequires-super-attribute
2261 -Wreserved-user-defined-literal
2262 -Wreturn-stack-address
2264 -Wselector-type-mismatch
2266 -Wserialized-diagnostics
2268 -Wshift-count-negative
2269 -Wshift-count-overflow
2270 -Wshift-negative-value
2272 -Wshift-sign-overflow
2274 -Wsizeof-array-argument
2275 -Wsource-uses-openmp
2278 -Wstatic-local-in-inline
2282 -Wstrlcpy-strlcat-size
2284 -Wsuggest-attribute=format
2285 -Wsuggest-attribute=noreturn
2286 -Wsuper-class-method-mismatch
2289 -Wtautological-constant-out-of-range-compare
2290 -Wtentative-definition-incomplete-type
2293 -Wtypedef-redefinition
2296 -Wundefined-internal
2297 -Wundefined-reinterpret-cast
2299 -Wunicode-whitespace
2300 -Wunknown-warning-option
2301 -Wunnamed-type-template-args
2302 -Wunneeded-member-function
2304 -Wunsupported-visibility
2305 -Wunused-but-set-parameter
2306 -Wunused-but-set-variable
2307 -Wunused-command-line-argument
2308 -Wunused-const-variable=2
2309 -Wunused-exception-parameter
2310 -Wunused-local-typedefs
2311 -Wunused-member-function
2312 -Wunused-sanitize-argument
2313 -Wunused-volatile-lvalue
2314 -Wuser-defined-literals
2317 -Wvector-conversions
2322 ], [ TOR_CHECK_CFLAGS([warning_flag]) ])
2324 dnl We should re-enable this in some later version. Clang doesn't
2325 dnl mind, but it causes trouble with GCC.
2326 dnl -Wstrict-overflow=2
2328 dnl These seem to require annotations that we don't currently use,
2329 dnl and they give false positives in our pthreads wrappers. (Clang 4)
2331 dnl -Wthread-safety-analysis
2332 dnl -Wthread-safety-attributes
2333 dnl -Wthread-safety-beta
2334 dnl -Wthread-safety-precise
2336 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2337 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2338 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2339 CFLAGS="$CFLAGS -Wwrite-strings"
2340 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2341 CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
2342 CFLAGS="$CFLAGS -Wunused-parameter "
2343 # These interfere with building main() { return 0; }, which autoconf
2344 # likes to use as its default program.
2345 CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations"
2347 if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2348 AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2350 if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2351 AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2353 if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2354 AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2357 if test "x$enable_fatal_warnings" = "xyes"; then
2358 # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2359 # default autoconf programs are full of errors.
2360 CFLAGS="$CFLAGS -Werror"
2365 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2368 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.])
2372 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2379 contrib/dist/suse/tor.sh
2380 contrib/operator-tools/tor.logrotate
2383 contrib/dist/tor.service
2384 src/config/torrc.sample
2385 src/config/torrc.minimal
2386 src/rust/.cargo/config
2387 scripts/maint/checkOptionDocs.pl
2388 scripts/maint/updateVersions.pl
2391 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2392 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2393 for file in $regular_mans ; do
2394 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2395 echo "==================================";
2397 echo "Building Tor has failed since manpages cannot be built.";
2399 echo "You need asciidoc installed to be able to build the manpages.";
2400 echo "To build without manpages, use the --disable-asciidoc argument";
2401 echo "when calling configure.";
2403 echo "==================================";
2409 if test "$fragile_hardening" = "yes"; then
2413 Warning! Building Tor with --enable-fragile-hardening (also known as
2414 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2415 other kinds of attacks easier. A Tor instance build with this option will be
2416 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2417 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2418 denial of service attacks. For more information, see
2419 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening