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.8-dev])
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 \
944 SSL_CTX_set_security_level \
948 dnl Check if OpenSSL has scrypt implementation.
949 AC_CHECK_FUNCS([ EVP_PBE_scrypt ])
951 dnl Check if OpenSSL structures are opaque
952 AC_CHECK_MEMBERS([SSL.state], , ,
953 [#include <openssl/ssl.h>
956 AC_CHECK_SIZEOF(SHA_CTX, , [AC_INCLUDES_DEFAULT()
957 #include <openssl/sha.h>
960 dnl Define the set of checks for KIST scheduler support.
961 AC_DEFUN([CHECK_KIST_SUPPORT],[
962 dnl KIST needs struct tcp_info and for certain members to exist.
964 [struct tcp_info.tcpi_unacked, struct tcp_info.tcpi_snd_mss],
965 , ,[[#include <netinet/tcp.h>]])
966 dnl KIST needs SIOCOUTQNSD to exist for an ioctl call.
967 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
968 #include <linux/sockios.h>
972 ])], have_siocoutqnsd=yes, have_siocoutqnsd=no)
973 if test "x$have_siocoutqnsd" = "xyes"; then
974 if test "x$ac_cv_member_struct_tcp_info_tcpi_unacked" = "xyes"; then
975 if test "x$ac_cv_member_struct_tcp_info_tcpi_snd_mss" = "xyes"; then
976 have_kist_support=yes
981 dnl Now, trigger the check.
983 AS_IF([test "x$have_kist_support" = "xyes"],
984 [AC_DEFINE(HAVE_KIST_SUPPORT, 1, [Defined if KIST scheduler is supported
986 [AC_MSG_NOTICE([KIST scheduler can't be used. Missing support.])])
989 LDFLAGS="$save_LDFLAGS"
990 CPPFLAGS="$save_CPPFLAGS"
992 dnl ------------------------------------------------------
993 dnl Where do you live, zlib? And how do we call you?
995 tor_zlib_pkg_redhat="zlib"
996 tor_zlib_pkg_debian="zlib1g"
997 tor_zlib_devpkg_redhat="zlib-devel"
998 tor_zlib_devpkg_debian="zlib1g-dev"
1000 TOR_SEARCH_LIBRARY(zlib, $tryzlibdir, [-lz],
1001 [#include <zlib.h>],
1002 [const char * zlibVersion(void);],
1003 [zlibVersion();], [--with-zlib-dir],
1006 if test "$enable_static_zlib" = "yes"; then
1007 if test "$tor_cv_library_zlib_dir" = "(system)"; then
1008 AC_MSG_ERROR("You must specify an explicit --with-zlib-dir=x option when
1009 using --enable-static-zlib")
1011 TOR_ZLIB_LIBS="$TOR_LIBDIR_zlib/libz.a"
1016 AC_SUBST(TOR_ZLIB_LIBS)
1018 dnl ------------------------------------------------------
1019 dnl Where we do we find lzma?
1022 AS_HELP_STRING(--enable-lzma, [enable support for the LZMA compression scheme.]),
1023 [case "${enableval}" in
1026 * ) AC_MSG_ERROR(bad value for --enable-lzma) ;;
1029 if test "x$enable_lzma" = "xno"; then
1032 PKG_CHECK_MODULES([LZMA],
1037 if test "x$have_lzma" = "xno" ; then
1038 AC_MSG_WARN([Unable to find liblzma.])
1042 if test "x$have_lzma" = "xyes"; then
1043 AC_DEFINE(HAVE_LZMA,1,[Have LZMA])
1044 TOR_LZMA_CFLAGS="${LZMA_CFLAGS}"
1045 TOR_LZMA_LIBS="${LZMA_LIBS}"
1047 AC_SUBST(TOR_LZMA_CFLAGS)
1048 AC_SUBST(TOR_LZMA_LIBS)
1050 dnl ------------------------------------------------------
1051 dnl Where we do we find zstd?
1054 AS_HELP_STRING(--enable-zstd, [enable support for the Zstandard compression scheme.]),
1055 [case "${enableval}" in
1058 * ) AC_MSG_ERROR(bad value for --enable-zstd) ;;
1061 if test "x$enable_zstd" = "xno"; then
1064 PKG_CHECK_MODULES([ZSTD],
1069 if test "x$have_zstd" = "xno" ; then
1070 AC_MSG_WARN([Unable to find libzstd.])
1074 if test "x$have_zstd" = "xyes"; then
1075 AC_DEFINE(HAVE_ZSTD,1,[Have Zstd])
1076 TOR_ZSTD_CFLAGS="${ZSTD_CFLAGS}"
1077 TOR_ZSTD_LIBS="${ZSTD_LIBS}"
1079 dnl now check for zstd functions
1081 save_CFLAGS="$CFLAGS"
1082 LIBS="$LIBS $ZSTD_LIBS"
1083 CFLAGS="$CFLAGS $ZSTD_CFLAGS"
1084 AC_CHECK_FUNCS(ZSTD_estimateCStreamSize \
1085 ZSTD_estimateDCtxSize)
1087 CFLAGS="$save_CFLAGS"
1089 AC_SUBST(TOR_ZSTD_CFLAGS)
1090 AC_SUBST(TOR_ZSTD_LIBS)
1092 dnl ----------------------------------------------------------------------
1093 dnl Check if libcap is available for capabilities.
1095 tor_cap_pkg_debian="libcap2"
1096 tor_cap_pkg_redhat="libcap"
1097 tor_cap_devpkg_debian="libcap-dev"
1098 tor_cap_devpkg_redhat="libcap-devel"
1100 AC_CHECK_LIB([cap], [cap_init], [],
1101 AC_MSG_NOTICE([Libcap was not found. Capabilities will not be usable.])
1103 AC_CHECK_FUNCS(cap_set_proc)
1105 dnl ---------------------------------------------------------------------
1106 dnl Now that we know about our major libraries, we can check for compiler
1107 dnl and linker hardening options. We need to do this with the libraries known,
1108 dnl since sometimes the linker will like an option but not be willing to
1109 dnl use it with a build of a library.
1111 all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
1112 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"
1120 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
1121 #if !defined(__clang__)
1123 #endif])], have_clang=yes, have_clang=no)
1125 if test "x$enable_gcc_hardening" != "xno"; then
1126 CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"
1127 if test "x$have_clang" = "xyes"; then
1128 TOR_CHECK_CFLAGS(-Qunused-arguments)
1130 TOR_CHECK_CFLAGS(-fstack-protector-all, also_link)
1131 AS_VAR_PUSHDEF([can_compile], [tor_cv_cflags_-fstack-protector-all])
1132 AS_VAR_PUSHDEF([can_link], [tor_can_link_-fstack-protector-all])
1133 m4_ifdef([AS_VAR_IF],[
1134 AS_VAR_IF(can_compile, [yes],
1135 AS_VAR_IF(can_link, [yes],
1137 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.)]))
1139 AS_VAR_POPDEF([can_link])
1140 AS_VAR_POPDEF([can_compile])
1141 TOR_CHECK_CFLAGS(-Wstack-protector)
1142 TOR_CHECK_CFLAGS(--param ssp-buffer-size=1)
1143 if test "$bwin32" = "false" && test "$enable_libfuzzer" != "yes" && test "$enable_oss_fuzz" != "yes"; then
1144 TOR_CHECK_CFLAGS(-fPIE)
1145 TOR_CHECK_LDFLAGS(-pie, "$all_ldflags_for_check", "$all_libs_for_check")
1147 TOR_TRY_COMPILE_WITH_CFLAGS(-fwrapv, also_link, CFLAGS_FWRAPV="-fwrapv", true)
1150 if test "$fragile_hardening" = "yes"; then
1151 TOR_TRY_COMPILE_WITH_CFLAGS(-ftrapv, also_link, CFLAGS_FTRAPV="-ftrapv", true)
1152 if test "$tor_cv_cflags__ftrapv" = "yes" && test "$tor_can_link__ftrapv" != "yes"; then
1153 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.])
1156 if test "$tor_cv_cflags__ftrapv" != "yes"; then
1157 AC_MSG_ERROR([You requested fragile hardening, but the compiler does not seem to support -ftrapv.])
1160 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=address], also_link, CFLAGS_ASAN="-fsanitize=address", true)
1161 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1162 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*])
1165 TOR_TRY_COMPILE_WITH_CFLAGS([-fsanitize=undefined], also_link, CFLAGS_UBSAN="-fsanitize=undefined", true)
1166 if test "$tor_cv_cflags__fsanitize_address" = "yes" && test "$tor_can_link__fsanitize_address" != "yes"; then
1167 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*])
1170 TOR_CHECK_CFLAGS([-fno-omit-frame-pointer])
1173 dnl Find the correct libraries to add in order to use the sanitizers.
1175 dnl When building Rust, Cargo will run the linker with the -nodefaultlibs
1176 dnl option, which will prevent the compiler from linking the sanitizer
1177 dnl libraries it needs. We need to specify them manually.
1179 dnl What's more, we need to specify them in a linker script rather than
1180 dnl from build.rs: these options aren't allowed in the cargo:rustc-flags
1182 RUST_LINKER_OPTIONS=""
1183 if test "x$have_clang" = "xyes"; then
1184 if test "x$CFLAGS_ASAN" != "x"; then
1185 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_ASAN"
1187 if test "x$CFLAGS_UBSAN" != "x"; then
1188 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS $CFLAGS_UBSAN"
1191 if test "x$CFLAGS_ASAN" != "x"; then
1192 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lasan"
1194 if test "x$CFLAGS_UBSAN" != "x"; then
1195 RUST_LINKER_OPTIONS="$RUST_LINKER_OPTIONS -lubsan"
1198 AC_SUBST(RUST_LINKER_OPTIONS)
1200 CFLAGS_BUGTRAP="$CFLAGS_FTRAPV $CFLAGS_ASAN $CFLAGS_UBSAN"
1201 CFLAGS_CONSTTIME="$CFLAGS_FWRAPV"
1203 mulodi_fixes_ftrapv=no
1204 if test "$have_clang" = "yes"; then
1205 saved_CFLAGS="$CFLAGS"
1206 CFLAGS="$CFLAGS $CFLAGS_FTRAPV"
1207 AC_MSG_CHECKING([whether clang -ftrapv can link a 64-bit int multiply])
1212 int main(int argc, char **argv)
1214 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1215 * (int64_t)atoi(argv[3]);
1218 [ftrapv_can_link=yes; AC_MSG_RESULT([yes])],
1219 [ftrapv_can_link=no; AC_MSG_RESULT([no])])
1220 if test "$ftrapv_can_link" = "no"; then
1221 AC_MSG_CHECKING([whether defining __mulodi4 fixes that])
1226 int64_t __mulodi4(int64_t a, int64_t b, int *overflow) {
1230 int main(int argc, char **argv)
1232 int64_t x = ((int64_t)atoi(argv[1])) * (int64_t)atoi(argv[2])
1233 * (int64_t)atoi(argv[3]);
1236 [mulodi_fixes_ftrapv=yes; AC_MSG_RESULT([yes])],
1237 [mulodi_fixes_ftrapv=no; AC_MSG_RESULT([no])])
1239 CFLAGS="$saved_CFLAGS"
1242 AM_CONDITIONAL(ADD_MULODI4, test "$mulodi_fixes_ftrapv" = "yes")
1244 dnl These cflags add bunches of branches, and we haven't been able to
1245 dnl persuade ourselves that they're suitable for code that needs to be
1247 AC_SUBST(CFLAGS_BUGTRAP)
1248 dnl These cflags are variant ones sutable for code that needs to be
1250 AC_SUBST(CFLAGS_CONSTTIME)
1252 if test "x$enable_linker_hardening" != "xno"; then
1253 TOR_CHECK_LDFLAGS(-z relro -z now, "$all_ldflags_for_check", "$all_libs_for_check")
1256 # For backtrace support
1257 TOR_CHECK_LDFLAGS(-rdynamic)
1259 dnl ------------------------------------------------------
1260 dnl Now see if we have a -fomit-frame-pointer compiler option.
1262 saved_CFLAGS="$CFLAGS"
1263 TOR_CHECK_CFLAGS(-fomit-frame-pointer)
1264 F_OMIT_FRAME_POINTER=''
1265 if test "$saved_CFLAGS" != "$CFLAGS"; then
1266 if test "$fragile_hardening" = "yes"; then
1267 F_OMIT_FRAME_POINTER='-fomit-frame-pointer'
1270 CFLAGS="$saved_CFLAGS"
1271 AC_SUBST(F_OMIT_FRAME_POINTER)
1273 dnl ------------------------------------------------------
1274 dnl If we are adding -fomit-frame-pointer (or if the compiler's doing it
1275 dnl for us, as GCC 4.6 and later do at many optimization levels), then
1276 dnl we should try to add -fasynchronous-unwind-tables so that our backtrace
1278 TOR_CHECK_CFLAGS(-fasynchronous-unwind-tables)
1280 dnl ============================================================
1281 dnl Check for libseccomp
1283 if test "x$enable_seccomp" != "xno"; then
1284 AC_CHECK_HEADERS([seccomp.h])
1285 AC_SEARCH_LIBS(seccomp_init, [seccomp])
1288 dnl ============================================================
1289 dnl Check for libscrypt
1291 if test "x$enable_libscrypt" != "xno"; then
1292 AC_CHECK_HEADERS([libscrypt.h])
1293 AC_SEARCH_LIBS(libscrypt_scrypt, [scrypt])
1294 AC_CHECK_FUNCS([libscrypt_scrypt])
1297 dnl ============================================================
1298 dnl We need an implementation of curve25519.
1300 dnl set these defaults.
1301 build_curve25519_donna=no
1302 build_curve25519_donna_c64=no
1303 use_curve25519_donna=no
1304 use_curve25519_nacl=no
1307 dnl The best choice is using curve25519-donna-c64, but that requires
1309 AC_CACHE_CHECK([whether we can use curve25519-donna-c64],
1310 tor_cv_can_use_curve25519_donna_c64,
1312 [AC_LANG_PROGRAM([dnl
1314 typedef unsigned uint128_t __attribute__((mode(TI)));
1315 int func(uint64_t a, uint64_t b) {
1316 uint128_t c = ((uint128_t)a) * b;
1317 int ok = ((uint64_t)(c>>96)) == 522859 &&
1318 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1319 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1320 (((uint64_t)(c))&0xffffffffL) == 0;
1324 int ok = func( ((uint64_t)2000000000) * 1000000000,
1325 ((uint64_t)1234567890) << 24);
1328 [tor_cv_can_use_curve25519_donna_c64=yes],
1329 [tor_cv_can_use_curve25519_donna_c64=no],
1331 [AC_LANG_PROGRAM([dnl
1333 typedef unsigned uint128_t __attribute__((mode(TI)));
1334 int func(uint64_t a, uint64_t b) {
1335 uint128_t c = ((uint128_t)a) * b;
1336 int ok = ((uint64_t)(c>>96)) == 522859 &&
1337 (((uint64_t)(c>>64))&0xffffffffL) == 3604448702L &&
1338 (((uint64_t)(c>>32))&0xffffffffL) == 2351960064L &&
1339 (((uint64_t)(c))&0xffffffffL) == 0;
1343 int ok = func( ((uint64_t)2000000000) * 1000000000,
1344 ((uint64_t)1234567890) << 24);
1347 [tor_cv_can_use_curve25519_donna_c64=cross],
1348 [tor_cv_can_use_curve25519_donna_c64=no])])])
1350 AC_CHECK_HEADERS([crypto_scalarmult_curve25519.h \
1351 nacl/crypto_scalarmult_curve25519.h])
1353 AC_CACHE_CHECK([for nacl compiled with a fast curve25519 implementation],
1354 tor_cv_can_use_curve25519_nacl,
1355 [tor_saved_LIBS="$LIBS"
1358 [AC_LANG_PROGRAM([dnl
1359 #ifdef HAVE_CRYPTO_SCALARMULT_CURVE25519_H
1360 #include <crypto_scalarmult_curve25519.h>
1361 #elif defined(HAVE_NACL_CRYPTO_SCALARMULT_CURVE25519_H)
1362 #include <nacl/crypto_scalarmult_curve25519.h>
1364 #ifdef crypto_scalarmult_curve25519_ref_BYTES
1365 #error Hey, this is the reference implementation! That's not fast.
1368 unsigned char *a, *b, *c; crypto_scalarmult_curve25519(a,b,c);
1369 ])], [tor_cv_can_use_curve25519_nacl=yes],
1370 [tor_cv_can_use_curve25519_nacl=no])
1371 LIBS="$tor_saved_LIBS" ])
1373 dnl Okay, now we need to figure out which one to actually use. Fall back
1374 dnl to curve25519-donna.c
1376 if test "x$tor_cv_can_use_curve25519_donna_c64" != "xno"; then
1377 build_curve25519_donna_c64=yes
1378 use_curve25519_donna=yes
1379 elif test "x$tor_cv_can_use_curve25519_nacl" = "xyes"; then
1380 use_curve25519_nacl=yes
1381 CURVE25519_LIBS=-lnacl
1383 build_curve25519_donna=yes
1384 use_curve25519_donna=yes
1387 if test "x$use_curve25519_donna" = "xyes"; then
1388 AC_DEFINE(USE_CURVE25519_DONNA, 1,
1389 [Defined if we should use an internal curve25519_donna{,_c64} implementation])
1391 if test "x$use_curve25519_nacl" = "xyes"; then
1392 AC_DEFINE(USE_CURVE25519_NACL, 1,
1393 [Defined if we should use a curve25519 from nacl])
1395 AM_CONDITIONAL(BUILD_CURVE25519_DONNA,
1396 test "x$build_curve25519_donna" = "xyes")
1397 AM_CONDITIONAL(BUILD_CURVE25519_DONNA_C64,
1398 test "x$build_curve25519_donna_c64" = "xyes")
1399 AC_SUBST(CURVE25519_LIBS)
1401 dnl Make sure to enable support for large off_t if available.
1404 AC_CHECK_HEADERS([assert.h \
1419 gnu/libc-version.h \
1459 AC_CHECK_HEADERS(sys/param.h)
1461 AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
1462 [#ifdef HAVE_SYS_TYPES_H
1463 #include <sys/types.h>
1465 #ifdef HAVE_SYS_SOCKET_H
1466 #include <sys/socket.h>
1468 AC_CHECK_HEADERS(net/pfvar.h, net_pfvar_found=1, net_pfvar_found=0,
1469 [#ifdef HAVE_SYS_TYPES_H
1470 #include <sys/types.h>
1472 #ifdef HAVE_SYS_SOCKET_H
1473 #include <sys/socket.h>
1475 #ifdef HAVE_NET_IF_H
1478 #ifdef HAVE_NETINET_IN_H
1479 #include <netinet/in.h>
1482 AC_CHECK_HEADERS(linux/if.h,[],[],
1484 #ifdef HAVE_SYS_SOCKET_H
1485 #include <sys/socket.h>
1489 AC_CHECK_HEADERS(linux/netfilter_ipv4.h,
1490 linux_netfilter_ipv4=1, linux_netfilter_ipv4=0,
1491 [#ifdef HAVE_SYS_TYPES_H
1492 #include <sys/types.h>
1494 #ifdef HAVE_SYS_SOCKET_H
1495 #include <sys/socket.h>
1497 #ifdef HAVE_LIMITS_H
1500 #ifdef HAVE_LINUX_TYPES_H
1501 #include <linux/types.h>
1503 #ifdef HAVE_NETINET_IN6_H
1504 #include <netinet/in6.h>
1506 #ifdef HAVE_NETINET_IN_H
1507 #include <netinet/in.h>
1510 AC_CHECK_HEADERS(linux/netfilter_ipv6/ip6_tables.h,
1511 linux_netfilter_ipv6_ip6_tables=1, linux_netfilter_ipv6_ip6_tables=0,
1512 [#ifdef HAVE_SYS_TYPES_H
1513 #include <sys/types.h>
1515 #ifdef HAVE_SYS_SOCKET_H
1516 #include <sys/socket.h>
1518 #ifdef HAVE_LIMITS_H
1521 #ifdef HAVE_LINUX_TYPES_H
1522 #include <linux/types.h>
1524 #ifdef HAVE_NETINET_IN6_H
1525 #include <netinet/in6.h>
1527 #ifdef HAVE_NETINET_IN_H
1528 #include <netinet/in.h>
1530 #ifdef HAVE_LINUX_IF_H
1531 #include <linux/if.h>
1535 if test "x$net_if_found" = "x1" && test "x$net_pfvar_found" = "x1"; then
1538 if test "x$linux_netfilter_ipv4" = "x1"; then
1541 if test "x$linux_netfilter_ipv6_ip6_tables" = "x1"; then
1544 if test "x$transparent_ok" = "x1"; then
1545 AC_DEFINE(USE_TRANSPARENT, 1, "Define to enable transparent proxy support")
1547 AC_MSG_NOTICE([Transparent proxy support enabled, but missing headers.])
1550 AC_CHECK_MEMBERS([struct timeval.tv_sec], , ,
1551 [#ifdef HAVE_SYS_TYPES_H
1552 #include <sys/types.h>
1554 #ifdef HAVE_SYS_TIME_H
1555 #include <sys/time.h>
1558 dnl In case we aren't given a working stdint.h, we'll need to grow our own.
1561 AC_CHECK_SIZEOF(int8_t)
1562 AC_CHECK_SIZEOF(int16_t)
1563 AC_CHECK_SIZEOF(int32_t)
1564 AC_CHECK_SIZEOF(int64_t)
1565 AC_CHECK_SIZEOF(uint8_t)
1566 AC_CHECK_SIZEOF(uint16_t)
1567 AC_CHECK_SIZEOF(uint32_t)
1568 AC_CHECK_SIZEOF(uint64_t)
1569 AC_CHECK_SIZEOF(intptr_t)
1570 AC_CHECK_SIZEOF(uintptr_t)
1572 dnl AC_CHECK_TYPES([int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t, intptr_t, uintptr_t])
1574 AC_CHECK_SIZEOF(char)
1575 AC_CHECK_SIZEOF(short)
1576 AC_CHECK_SIZEOF(int)
1577 AC_CHECK_SIZEOF(long)
1578 AC_CHECK_SIZEOF(long long)
1579 AC_CHECK_SIZEOF(__int64)
1580 AC_CHECK_SIZEOF(void *)
1581 AC_CHECK_SIZEOF(time_t)
1582 AC_CHECK_SIZEOF(size_t)
1583 AC_CHECK_SIZEOF(pid_t)
1585 AC_CHECK_TYPES([uint, u_char, ssize_t])
1587 AC_PC_FROM_UCONTEXT([:])
1589 dnl used to include sockaddr_storage, but everybody has that.
1590 AC_CHECK_TYPES([struct in6_addr, struct sockaddr_in6, sa_family_t], , ,
1591 [#ifdef HAVE_SYS_TYPES_H
1592 #include <sys/types.h>
1594 #ifdef HAVE_NETINET_IN_H
1595 #include <netinet/in.h>
1597 #ifdef HAVE_NETINET_IN6_H
1598 #include <netinet/in6.h>
1600 #ifdef HAVE_SYS_SOCKET_H
1601 #include <sys/socket.h>
1604 #define _WIN32_WINNT 0x0501
1605 #define WIN32_LEAN_AND_MEAN
1606 #include <winsock2.h>
1607 #include <ws2tcpip.h>
1610 AC_CHECK_MEMBERS([struct in6_addr.s6_addr32, struct in6_addr.s6_addr16, struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len], , ,
1611 [#ifdef HAVE_SYS_TYPES_H
1612 #include <sys/types.h>
1614 #ifdef HAVE_NETINET_IN_H
1615 #include <netinet/in.h>
1617 #ifdef HAVE_NETINET_IN6_H
1618 #include <netinet/in6.h>
1620 #ifdef HAVE_SYS_SOCKET_H
1621 #include <sys/socket.h>
1624 #define _WIN32_WINNT 0x0501
1625 #define WIN32_LEAN_AND_MEAN
1626 #include <winsock2.h>
1627 #include <ws2tcpip.h>
1631 AC_CHECK_TYPES([rlim_t], , ,
1632 [#ifdef HAVE_SYS_TYPES_H
1633 #include <sys/types.h>
1635 #ifdef HAVE_SYS_TIME_H
1636 #include <sys/time.h>
1638 #ifdef HAVE_SYS_RESOURCE_H
1639 #include <sys/resource.h>
1643 AX_CHECK_SIGN([time_t],
1646 #ifdef HAVE_SYS_TYPES_H
1647 #include <sys/types.h>
1649 #ifdef HAVE_SYS_TIME_H
1650 #include <sys/time.h>
1657 if test "$ax_cv_decl_time_t_signed" = "no"; then
1658 AC_MSG_ERROR([You have an unsigned time_t; Tor does not support that. Please tell the Tor developers about your interesting platform.])
1661 AX_CHECK_SIGN([size_t],
1662 [ tor_cv_size_t_signed=yes ],
1663 [ tor_cv_size_t_signed=no ], [
1664 #ifdef HAVE_SYS_TYPES_H
1665 #include <sys/types.h>
1669 if test "$ax_cv_decl_size_t_signed" = "yes"; then
1670 AC_MSG_ERROR([You have a signed size_t; that's grossly nonconformant.])
1673 AX_CHECK_SIGN([enum always],
1674 [ AC_DEFINE(ENUM_VALS_ARE_SIGNED, 1, [Define if enum is always signed]) ],
1676 enum always { AAA, BBB, CCC };
1679 AC_CHECK_SIZEOF(socklen_t, , [AC_INCLUDES_DEFAULT()
1680 #ifdef HAVE_SYS_SOCKET_H
1681 #include <sys/socket.h>
1685 # We want to make sure that we _don't_ have a cell_t defined, like IRIX does.
1687 AC_CHECK_SIZEOF(cell_t)
1689 # Let's see if stdatomic works. (There are some debian clangs that screw it
1690 # up; see Tor bug #26779 and debian bug 903709.)
1691 AC_CACHE_CHECK([whether C11 stdatomic.h actually works],
1692 tor_cv_stdatomic_works,
1693 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1694 #include <stdatomic.h>
1695 struct x { atomic_size_t y; };
1696 void try_atomic_init(struct x *xx)
1698 atomic_init(&xx->y, 99);
1699 atomic_fetch_add(&xx->y, 1);
1701 ]])], [tor_cv_stdatomic_works=yes], [tor_cv_stdatomic_works=no])])
1703 if test "$tor_cv_stdatomic_works" = "yes"; then
1704 AC_DEFINE(STDATOMIC_WORKS, 1, [Set to 1 if we can compile a simple stdatomic example.])
1705 elif test "$ac_cv_header_stdatomic_h" = "yes"; then
1706 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 ])
1709 # Now make sure that NULL can be represented as zero bytes.
1710 AC_CACHE_CHECK([whether memset(0) sets pointers to NULL], tor_cv_null_is_zero,
1711 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1712 [[#include <stdlib.h>
1715 #ifdef HAVE_STDDEF_H
1718 int main () { char *p1,*p2; p1=NULL; memset(&p2,0,sizeof(p2));
1719 return memcmp(&p1,&p2,sizeof(char*))?1:0; }]])],
1720 [tor_cv_null_is_zero=yes],
1721 [tor_cv_null_is_zero=no],
1722 [tor_cv_null_is_zero=cross])])
1724 if test "$tor_cv_null_is_zero" = "cross"; then
1725 # Cross-compiling; let's hope that the target isn't raving mad.
1726 AC_MSG_NOTICE([Cross-compiling: we'll assume that NULL is represented as a sequence of 0-valued bytes.])
1729 if test "$tor_cv_null_is_zero" != "no"; then
1730 AC_DEFINE([NULL_REP_IS_ZERO_BYTES], 1,
1731 [Define to 1 iff memset(0) sets pointers to NULL])
1734 AC_CACHE_CHECK([whether memset(0) sets doubles to 0.0], tor_cv_dbl0_is_zero,
1735 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1736 [[#include <stdlib.h>
1739 #ifdef HAVE_STDDEF_H
1742 int main () { double d1,d2; d1=0; memset(&d2,0,sizeof(d2));
1743 return memcmp(&d1,&d2,sizeof(d1))?1:0; }]])],
1744 [tor_cv_dbl0_is_zero=yes],
1745 [tor_cv_dbl0_is_zero=no],
1746 [tor_cv_dbl0_is_zero=cross])])
1748 if test "$tor_cv_dbl0_is_zero" = "cross"; then
1749 # Cross-compiling; let's hope that the target isn't raving mad.
1750 AC_MSG_NOTICE([Cross-compiling: we'll assume that 0.0 can be represented as a sequence of 0-valued bytes.])
1753 if test "$tor_cv_dbl0_is_zero" != "no"; then
1754 AC_DEFINE([DOUBLE_0_REP_IS_ZERO_BYTES], 1,
1755 [Define to 1 iff memset(0) sets doubles to 0.0])
1758 # And what happens when we malloc zero?
1759 AC_CACHE_CHECK([whether we can malloc(0) safely.], tor_cv_malloc_zero_works,
1760 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1761 [[#include <stdlib.h>
1764 #ifdef HAVE_STDDEF_H
1767 int main () { return malloc(0)?0:1; }]])],
1768 [tor_cv_malloc_zero_works=yes],
1769 [tor_cv_malloc_zero_works=no],
1770 [tor_cv_malloc_zero_works=cross])])
1772 if test "$tor_cv_malloc_zero_works" = "cross"; then
1773 # Cross-compiling; let's hope that the target isn't raving mad.
1774 AC_MSG_NOTICE([Cross-compiling: we'll assume that we need to check malloc() arguments for 0.])
1777 if test "$tor_cv_malloc_zero_works" = "yes"; then
1778 AC_DEFINE([MALLOC_ZERO_WORKS], 1,
1779 [Define to 1 iff malloc(0) returns a pointer])
1782 # whether we seem to be in a 2s-complement world.
1783 AC_CACHE_CHECK([whether we are using 2s-complement arithmetic], tor_cv_twos_complement,
1784 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1785 [[int main () { int problem = ((-99) != (~99)+1);
1786 return problem ? 1 : 0; }]])],
1787 [tor_cv_twos_complement=yes],
1788 [tor_cv_twos_complement=no],
1789 [tor_cv_twos_complement=cross])])
1791 if test "$tor_cv_twos_complement" = "cross"; then
1792 # Cross-compiling; let's hope that the target isn't raving mad.
1793 AC_MSG_NOTICE([Cross-compiling: we'll assume that negative integers are represented with two's complement.])
1796 if test "$tor_cv_twos_complement" != "no"; then
1797 AC_DEFINE([USING_TWOS_COMPLEMENT], 1,
1798 [Define to 1 iff we represent negative integers with
1802 # What does shifting a negative value do?
1803 AC_CACHE_CHECK([whether right-shift on negative values does sign-extension], tor_cv_sign_extend,
1804 [AC_RUN_IFELSE([AC_LANG_SOURCE(
1805 [[int main () { int okay = (-60 >> 8) == -1; return okay ? 0 : 1; }]])],
1806 [tor_cv_sign_extend=yes],
1807 [tor_cv_sign_extend=no],
1808 [tor_cv_sign_extend=cross])])
1810 if test "$tor_cv_sign_extend" = "cross"; then
1811 # Cross-compiling; let's hope that the target isn't raving mad.
1812 AC_MSG_NOTICE([Cross-compiling: we'll assume that right-shifting negative integers causes sign-extension])
1815 if test "$tor_cv_sign_extend" != "no"; then
1816 AC_DEFINE([RSHIFT_DOES_SIGN_EXTEND], 1,
1817 [Define to 1 iff right-shifting a negative value performs sign-extension])
1820 # Is uint8_t the same type as unsigned char?
1821 AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar,
1822 [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
1825 unsigned char c;]])],
1826 [tor_cv_uint8_uchar=yes],
1827 [tor_cv_uint8_uchar=no],
1828 [tor_cv_uint8_uchar=cross])])
1830 if test "$tor_cv_uint8_uchar" = "cross"; then
1831 AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char])
1834 if test "$tor_cv_uint8_uchar" = "no"; then
1835 AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.])
1838 # Whether we should use the dmalloc memory allocation debugging library.
1839 AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library))
1840 AC_ARG_WITH(dmalloc,
1841 AS_HELP_STRING(--with-dmalloc, [use debug memory allocation library]),
1842 [if [[ "$withval" = "yes" ]]; then
1848 fi], [ dmalloc=0; AC_MSG_RESULT(no) ]
1851 if [[ $dmalloc -eq 1 ]]; then
1852 AC_CHECK_HEADERS(dmalloc.h, , AC_MSG_ERROR(dmalloc header file not found. Do you have the development files for dmalloc installed?))
1853 AC_SEARCH_LIBS(dmalloc_malloc, [dmallocth dmalloc], , AC_MSG_ERROR(Libdmalloc library not found. If you enable it you better have it installed.))
1854 AC_DEFINE(USE_DMALLOC, 1, [Debug memory allocation library])
1855 AC_CHECK_FUNCS(dmalloc_strdup dmalloc_strndup)
1858 AC_ARG_WITH(tcmalloc,
1859 AS_HELP_STRING(--with-tcmalloc, [use tcmalloc memory allocation library]),
1860 [ tcmalloc=yes ], [ tcmalloc=no ])
1862 if test "x$tcmalloc" = "xyes"; then
1863 LDFLAGS="-ltcmalloc $LDFLAGS"
1866 using_custom_malloc=no
1867 if test "x$enable_openbsd_malloc" = "xyes"; then
1868 using_custom_malloc=yes
1870 if test "x$tcmalloc" = "xyes"; then
1871 using_custom_malloc=yes
1873 if test "$using_custom_malloc" = "no"; then
1874 AC_CHECK_FUNCS(mallinfo)
1876 if test "$using_custom_malloc" = "yes"; then
1877 # Tell the C compiler not to use the system allocator functions.
1878 TOR_CHECK_CFLAGS([-fno-builtin-malloc -fno-builtin-realloc -fno-builtin-calloc -fno-builtin-free])
1881 # By default, we're going to assume we don't have mlockall()
1882 # bionic and other platforms have various broken mlockall subsystems.
1883 # Some systems don't have a working mlockall, some aren't linkable,
1884 # and some have it but don't declare it.
1885 AC_CHECK_FUNCS(mlockall)
1886 AC_CHECK_DECLS([mlockall], , , [
1887 #ifdef HAVE_SYS_MMAN_H
1888 #include <sys/mman.h>
1891 # Allow user to specify an alternate syslog facility
1892 AC_ARG_WITH(syslog-facility,
1893 AS_HELP_STRING(--with-syslog-facility=LOG, [syslog facility to use (default=LOG_DAEMON)]),
1894 syslog_facility="$withval", syslog_facility="LOG_DAEMON")
1895 AC_DEFINE_UNQUOTED(LOGFACILITY,$syslog_facility,[name of the syslog facility])
1896 AC_SUBST(LOGFACILITY)
1898 # Check if we have getresuid and getresgid
1899 AC_CHECK_FUNCS(getresuid getresgid)
1901 # Check for gethostbyname_r in all its glorious incompatible versions.
1902 # (This logic is based on that in Python's configure.in)
1903 AH_TEMPLATE(HAVE_GETHOSTBYNAME_R,
1904 [Define this if you have any gethostbyname_r()])
1906 AC_CHECK_FUNC(gethostbyname_r, [
1907 AC_MSG_CHECKING([how many arguments gethostbyname_r() wants])
1909 CFLAGS="$CFLAGS $MY_CPPFLAGS $MY_THREAD_CPPFLAGS $MY_CFLAGS"
1910 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1914 struct hostent *h1, *h2;
1916 (void)gethostbyname_r(cp1,h1,cp2,i1,&h2,&i2);
1918 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1919 AC_DEFINE(HAVE_GETHOSTBYNAME_R_6_ARG, 1,
1920 [Define this if gethostbyname_r takes 6 arguments])
1923 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1929 (void)gethostbyname_r(cp1,h1,cp2,i1,&i2);
1931 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1932 AC_DEFINE(HAVE_GETHOSTBYNAME_R_5_ARG, 1,
1933 [Define this if gethostbyname_r takes 5 arguments])
1936 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
1941 struct hostent_data hd;
1942 (void) gethostbyname_r(cp1,h1,&hd);
1944 AC_DEFINE(HAVE_GETHOSTBYNAME_R)
1945 AC_DEFINE(HAVE_GETHOSTBYNAME_R_3_ARG, 1,
1946 [Define this if gethostbyname_r takes 3 arguments])
1956 AC_CACHE_CHECK([whether the C compiler supports __func__],
1957 tor_cv_have_func_macro,
1958 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1960 int main(int c, char **v) { puts(__func__); }])],
1961 tor_cv_have_func_macro=yes,
1962 tor_cv_have_func_macro=no))
1964 AC_CACHE_CHECK([whether the C compiler supports __FUNC__],
1965 tor_cv_have_FUNC_macro,
1966 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1968 int main(int c, char **v) { puts(__FUNC__); }])],
1969 tor_cv_have_FUNC_macro=yes,
1970 tor_cv_have_FUNC_macro=no))
1972 AC_CACHE_CHECK([whether the C compiler supports __FUNCTION__],
1973 tor_cv_have_FUNCTION_macro,
1974 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1976 int main(int c, char **v) { puts(__FUNCTION__); }])],
1977 tor_cv_have_FUNCTION_macro=yes,
1978 tor_cv_have_FUNCTION_macro=no))
1980 AC_CACHE_CHECK([whether we have extern char **environ already declared],
1981 tor_cv_have_environ_declared,
1982 AC_COMPILE_IFELSE([AC_LANG_SOURCE([
1983 #ifdef HAVE_UNISTD_H
1987 int main(int c, char **v) { char **t = environ; }])],
1988 tor_cv_have_environ_declared=yes,
1989 tor_cv_have_environ_declared=no))
1991 if test "$tor_cv_have_func_macro" = "yes"; then
1992 AC_DEFINE(HAVE_MACRO__func__, 1, [Defined if the compiler supports __func__])
1995 if test "$tor_cv_have_FUNC_macro" = "yes"; then
1996 AC_DEFINE(HAVE_MACRO__FUNC__, 1, [Defined if the compiler supports __FUNC__])
1999 if test "$tor_cv_have_FUNCTION_macro" = "yes"; then
2000 AC_DEFINE(HAVE_MACRO__FUNCTION__, 1,
2001 [Defined if the compiler supports __FUNCTION__])
2004 if test "$tor_cv_have_environ_declared" = "yes"; then
2005 AC_DEFINE(HAVE_EXTERN_ENVIRON_DECLARED, 1,
2006 [Defined if we have extern char **environ already declared])
2009 # $prefix stores the value of the --prefix command line option, or
2010 # NONE if the option wasn't set. In the case that it wasn't set, make
2011 # it be the default, so that we can use it to expand directories now.
2012 if test "x$prefix" = "xNONE"; then
2013 prefix=$ac_default_prefix
2016 # and similarly for $exec_prefix
2017 if test "x$exec_prefix" = "xNONE"; then
2021 if test "x$BUILDDIR" = "x"; then
2025 AH_TEMPLATE([BUILDDIR],[tor's build directory])
2026 AC_DEFINE_UNQUOTED(BUILDDIR,"$BUILDDIR")
2028 if test "x$SRCDIR" = "x"; then
2029 SRCDIR=$(cd "$srcdir"; pwd)
2031 AH_TEMPLATE([SRCDIR],[tor's sourcedir directory])
2032 AC_DEFINE_UNQUOTED(SRCDIR,"$SRCDIR")
2034 if test "x$CONFDIR" = "x"; then
2035 CONFDIR=`eval echo $sysconfdir/tor`
2038 AH_TEMPLATE([CONFDIR],[tor's configuration directory])
2039 AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
2041 BINDIR=`eval echo $bindir`
2043 LOCALSTATEDIR=`eval echo $localstatedir`
2044 AC_SUBST(LOCALSTATEDIR)
2046 if test "$bwin32" = "true"; then
2047 # Test if the linker supports the --nxcompat and --dynamicbase options
2049 save_LDFLAGS="$LDFLAGS"
2050 LDFLAGS="-Wl,--nxcompat -Wl,--dynamicbase"
2051 AC_MSG_CHECKING([whether the linker supports DllCharacteristics])
2052 AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
2053 [AC_MSG_RESULT([yes])]
2054 [save_LDFLAGS="$save_LDFLAGS $LDFLAGS"],
2055 [AC_MSG_RESULT([no])]
2057 LDFLAGS="$save_LDFLAGS"
2060 # Set CFLAGS _after_ all the above checks, since our warnings are stricter
2061 # than autoconf's macros like.
2062 if test "$GCC" = "yes"; then
2063 # Disable GCC's strict aliasing checks. They are an hours-to-debug
2064 # accident waiting to happen.
2065 CFLAGS="$CFLAGS -Wall -fno-strict-aliasing"
2067 # Override optimization level for non-gcc compilers
2069 enable_gcc_warnings=no
2070 enable_gcc_warnings_advisory=no
2073 # Warnings implies advisory-warnings and -Werror.
2074 if test "$enable_gcc_warnings" = "yes"; then
2075 enable_gcc_warnings_advisory=yes
2076 enable_fatal_warnings=yes
2079 # OS X Lion started deprecating the system openssl. Let's just disable
2080 # all deprecation warnings on OS X. Also, to potentially make the binary
2081 # a little smaller, let's enable dead_strip.
2085 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
2086 LDFLAGS="$LDFLAGS -dead_strip" ;;
2089 # Add some more warnings which we use in development but not in the
2090 # released versions. (Some relevant gcc versions can't handle these.)
2092 # Note that we have to do this near the end of the autoconf process, or
2093 # else we may run into problems when these warnings hit on the testing C
2094 # programs that autoconf wants to build.
2095 if test "x$enable_gcc_warnings_advisory" != "xno"; then
2098 *-*-openbsd* | *-*-bitrig*)
2099 # Some OpenBSD versions (like 4.8) have -Wsystem-headers by default.
2100 # That's fine, except that the headers don't pass -Wredundant-decls.
2101 # Therefore, let's disable -Wsystem-headers when we're building
2102 # with maximal warnings on OpenBSD.
2103 CFLAGS="$CFLAGS -Wno-system-headers" ;;
2106 # GCC4.3 users once report trouble with -Wstrict-overflow=5. GCC5 users
2107 # have it work better.
2108 # CFLAGS="$CFLAGS -Wstrict-overflow=1"
2110 # This warning was added in gcc 4.3, but it appears to generate
2111 # spurious warnings in gcc 4.4. I don't know if it works in 4.5.
2112 #CFLAGS="$CFLAGS -Wlogical-op"
2114 m4_foreach_w([warning_flag], [
2116 -Waddress-of-array-temporary
2117 -Waddress-of-temporary
2119 -Wanonymous-pack-parens
2122 -Warc-bridge-casts-disallowed-in-nonarc
2123 -Warc-maybe-repeated-use-of-weak
2124 -Warc-performSelector-leaks
2125 -Warc-repeated-use-of-weak
2127 -Warray-bounds-pointer-arithmetic
2129 -Wasm-operand-widths
2131 -Watomic-property-with-user-defined-accessor
2133 -Wauto-storage-class
2136 -Wbackslash-newline-escape
2137 -Wbad-array-new-length
2138 -Wbind-to-temporary-copy
2139 -Wbitfield-constant-conversion
2142 -Wbuiltin-requires-header
2144 -Wcompare-distinct-pointer-types
2145 -Wcomplex-component-init
2146 -Wconditional-type-mismatch
2148 -Wconstant-conversion
2149 -Wconstant-logical-operand
2150 -Wconstexpr-not-const
2151 -Wcustom-atomic-properties
2153 -Wdangling-initializer-list
2155 -Wdelegating-ctor-cycles
2156 -Wdeprecated-implementations
2157 -Wdeprecated-register
2158 -Wdirect-ivar-access
2160 -Wdistributed-object-modifiers
2162 -Wdollar-in-identifier-extension
2164 -Wduplicate-decl-specifier
2166 -Wduplicate-method-arg
2167 -Wduplicate-method-match
2169 -Wdynamic-class-memaccess
2170 -Wembedded-directive
2171 -Wempty-translation-unit
2173 -Wexit-time-destructors
2174 -Wexplicit-ownership-type
2175 -Wextern-initializer
2179 -Wflexible-array-extensions
2182 -Wfour-char-constants
2184 -Wglobal-constructors
2185 -Wgnu-array-member-paren-init
2187 -Wgnu-static-float-init
2190 -Widiomatic-parentheses
2191 -Wignored-attributes
2192 -Wimplicit-atomic-properties
2193 -Wimplicit-conversion-floating-point-to-bool
2194 -Wimplicit-exception-spec-mismatch
2195 -Wimplicit-fallthrough
2196 -Wimplicit-fallthrough-per-function
2197 -Wimplicit-retain-self
2198 -Wimport-preprocessor-directive-pedantic
2199 -Wincompatible-library-redeclaration
2200 -Wincompatible-pointer-types-discards-qualifiers
2201 -Wincomplete-implementation
2203 -Wincomplete-umbrella
2206 -Wint-to-void-pointer-cast
2212 -Winvalid-source-encoding
2213 -Winvalid-token-paste
2214 -Wknr-promoted-parameter
2215 -Wlarge-by-value-copy
2216 -Wliteral-conversion
2218 -Wlocal-type-template-args
2222 -Wmalformed-warning-check
2226 -Wmismatched-parameter-types
2227 -Wmismatched-return-types
2228 -Wmissing-field-initializers
2229 -Wmissing-format-attribute
2231 -Wmissing-selector-name
2233 -Wmissing-variable-declarations
2237 -Wnon-literal-null-conversion
2239 -Wnonportable-cfstrings
2245 -Wout-of-line-declaration
2247 -Woverlength-strings
2249 -Woverriding-method-mismatch
2250 -Wpointer-type-mismatch
2251 -Wpredefined-identifier-outside-function
2252 -Wprotocol-property-synthesis-ambiguity
2253 -Wreadonly-iboutlet-property
2254 -Wreadonly-setter-attrs
2256 -Wreceiver-forward-class
2258 -Wreinterpret-base-class
2259 -Wrequires-super-attribute
2260 -Wreserved-user-defined-literal
2261 -Wreturn-stack-address
2263 -Wselector-type-mismatch
2265 -Wserialized-diagnostics
2267 -Wshift-count-negative
2268 -Wshift-count-overflow
2269 -Wshift-negative-value
2271 -Wshift-sign-overflow
2273 -Wsizeof-array-argument
2274 -Wsource-uses-openmp
2277 -Wstatic-local-in-inline
2281 -Wstrlcpy-strlcat-size
2283 -Wsuggest-attribute=format
2284 -Wsuggest-attribute=noreturn
2285 -Wsuper-class-method-mismatch
2288 -Wtautological-constant-out-of-range-compare
2289 -Wtentative-definition-incomplete-type
2292 -Wtypedef-redefinition
2295 -Wundefined-internal
2296 -Wundefined-reinterpret-cast
2298 -Wunicode-whitespace
2299 -Wunknown-warning-option
2300 -Wunnamed-type-template-args
2301 -Wunneeded-member-function
2303 -Wunsupported-visibility
2304 -Wunused-but-set-parameter
2305 -Wunused-but-set-variable
2306 -Wunused-command-line-argument
2307 -Wunused-const-variable=2
2308 -Wunused-exception-parameter
2309 -Wunused-local-typedefs
2310 -Wunused-member-function
2311 -Wunused-sanitize-argument
2312 -Wunused-volatile-lvalue
2313 -Wuser-defined-literals
2316 -Wvector-conversions
2321 ], [ TOR_CHECK_CFLAGS([warning_flag]) ])
2323 dnl We should re-enable this in some later version. Clang doesn't
2324 dnl mind, but it causes trouble with GCC.
2325 dnl -Wstrict-overflow=2
2327 dnl These seem to require annotations that we don't currently use,
2328 dnl and they give false positives in our pthreads wrappers. (Clang 4)
2330 dnl -Wthread-safety-analysis
2331 dnl -Wthread-safety-attributes
2332 dnl -Wthread-safety-beta
2333 dnl -Wthread-safety-precise
2335 CFLAGS="$CFLAGS -W -Wfloat-equal -Wundef -Wpointer-arith"
2336 CFLAGS="$CFLAGS -Wstrict-prototypes -Wmissing-prototypes -Wwrite-strings"
2337 CFLAGS="$CFLAGS -Wredundant-decls -Wchar-subscripts -Wcomment -Wformat=2"
2338 CFLAGS="$CFLAGS -Wwrite-strings"
2339 CFLAGS="$CFLAGS -Wnested-externs -Wbad-function-cast -Wswitch-enum"
2340 CFLAGS="$CFLAGS -Waggregate-return -Wpacked -Wunused"
2341 CFLAGS="$CFLAGS -Wunused-parameter "
2342 # These interfere with building main() { return 0; }, which autoconf
2343 # likes to use as its default program.
2344 CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-declarations"
2346 if test "$tor_cv_cflags__Wnull_dereference" = "yes"; then
2347 AC_DEFINE([HAVE_CFLAG_WNULL_DEREFERENCE], 1, [True if we have -Wnull-dereference])
2349 if test "$tor_cv_cflags__Woverlength_strings" = "yes"; then
2350 AC_DEFINE([HAVE_CFLAG_WOVERLENGTH_STRINGS], 1, [True if we have -Woverlength-strings])
2352 if test "$tor_cv_cflags__warn_unused_const_variable_2" = "yes"; then
2353 AC_DEFINE([HAVE_CFLAG_WUNUSED_CONST_VARIABLE], 1, [True if we have -Wunused-const-variable])
2356 if test "x$enable_fatal_warnings" = "xyes"; then
2357 # I'd like to use TOR_CHECK_CFLAGS here, but I can't, since the
2358 # default autoconf programs are full of errors.
2359 CFLAGS="$CFLAGS -Werror"
2364 if test "$enable_coverage" = "yes" && test "$have_clang" = "no"; then
2367 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.])
2371 CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent $TOR_CPPFLAGS_openssl $TOR_CPPFLAGS_zlib"
2378 contrib/dist/suse/tor.sh
2379 contrib/operator-tools/tor.logrotate
2382 contrib/dist/tor.service
2383 src/config/torrc.sample
2384 src/config/torrc.minimal
2385 src/rust/.cargo/config
2386 scripts/maint/checkOptionDocs.pl
2387 scripts/maint/updateVersions.pl
2390 if test "x$asciidoc" = "xtrue" && test "$ASCIIDOC" = "none"; then
2391 regular_mans="doc/tor doc/tor-gencert doc/tor-resolve doc/torify"
2392 for file in $regular_mans ; do
2393 if ! [[ -f "$srcdir/$file.1.in" ]] || ! [[ -f "$srcdir/$file.html.in" ]] ; then
2394 echo "==================================";
2396 echo "Building Tor has failed since manpages cannot be built.";
2398 echo "You need asciidoc installed to be able to build the manpages.";
2399 echo "To build without manpages, use the --disable-asciidoc argument";
2400 echo "when calling configure.";
2402 echo "==================================";
2408 if test "$fragile_hardening" = "yes"; then
2412 Warning! Building Tor with --enable-fragile-hardening (also known as
2413 --enable-expensive-hardening) makes some kinds of attacks harder, but makes
2414 other kinds of attacks easier. A Tor instance build with this option will be
2415 somewhat less vulnerable to remote code execution, arithmetic overflow, or
2416 out-of-bounds read/writes... but at the cost of becoming more vulnerable to
2417 denial of service attacks. For more information, see
2418 https://trac.torproject.org/projects/tor/wiki/doc/TorFragileHardening