From fe051a43c1fc5d8528ed46deaa818031b16a79eb Mon Sep 17 00:00:00 2001 From: Jacob Appelbaum Date: Thu, 10 Mar 2011 01:22:32 -0800 Subject: [PATCH] add --enable-static-tor to our configure script This implements the feature request in bug #2702 --- INSTALL | 39 +++++++++++++++++++++++++++++++++++++++ changes/bug2702 | 5 +++++ configure.in | 25 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 changes/bug2702 diff --git a/INSTALL b/INSTALL index 5da50a62f..1007b431f 100644 --- a/INSTALL +++ b/INSTALL @@ -23,3 +23,42 @@ If it doesn't build for you: Lastly, check out https://www.torproject.org/docs/faq#DoesntWork +An example of how to build a mostly static Tor: + +Libevent should be built with: +% ./configure --disable-shared --enable-static --with-pic + +An example of how to build a mostly static Tor: +./configure --enable-static-libevent \ + --enable-static-openssl \ + --enable-static-zlib \ + --with-libevent-dir=/tmp/static-tor/libevent-1.4.14b-stable \ + --with-openssl-dir=/tmp/static-tor/openssl-0.9.8r/ \ + --with-zlib-dir=/tmp/static-tor/zlib-1.2.5 + +An example of how to build an entirely static Tor (no Mac OS X support, sorry): +./configure --enable-static-tor \ + --enable-static-libevent \ + --enable-static-openssl \ + --enable-static-zlib \ + --with-libevent-dir=/tmp/static-tor/libevent-1.4.14b-stable \ + --with-openssl-dir=/tmp/static-tor/openssl-0.9.8r/ \ + --with-zlib-dir=/tmp/static-tor/zlib-1.2.5 + +This currently does not work with --enable-gcc-hardening because of libevent issues: + +configure:6176: gcc -o conftest -D_FORTIFY_SOURCE=2 -fstack-protector-all -fwrapv -fPIE -Wstack-protector +--param ssp-buffer-size=1 -I/tmp/static-tor/libevent-1.4.14b-stable -I${top_srcdir}/src/common - +L/tmp/static-tor/libevent-1.4.14b-stable -pie conftest.c -lpthread -ldl -levent -lrt >&5 +/usr/bin/ld: /tmp/static-tor/libevent-1.4.14b-stable/libevent.a(event.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC +/tmp/static-tor/libevent-1.4.14b-stable/libevent.a: could not read symbols: Bad value + collect2: ld returned 1 exit status + configure:6176: $? = 1 + +This produces the following Tor binaries on Gnu/Linux x86-64: + +% file src/or/tor +src/or/tor: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.15, not stripped + +% ldd src/or/tor + not a dynamic executable diff --git a/changes/bug2702 b/changes/bug2702 new file mode 100644 index 000000000..cd004f555 --- /dev/null +++ b/changes/bug2702 @@ -0,0 +1,5 @@ + o Minor enhancement + - Implements --enable-static-tor for configure time. Closes bug 2702. + Idea, general hackery and thoughts from Alexei Czeskis, John Gilmore, + Jacob Appelbaum. + diff --git a/configure.in b/configure.in index 83fd0449b..f7875df71 100644 --- a/configure.in +++ b/configure.in @@ -32,6 +32,17 @@ AC_ARG_ENABLE(static-libevent, AS_HELP_STRING(--enable-static-libevent, Link against a static libevent library. Requires --with-libevent-dir)) AC_ARG_ENABLE(static-zlib, AS_HELP_STRING(--enable-static-zlib, Link against a static zlib library. Requires --with-zlib-dir)) +AC_ARG_ENABLE(static-tor, + AS_HELP_STRING(--enable-static-tor, Create an entirely static Tor binary. Requires --static-openssl + --static-libevent and --static-zlib)) + +if test "$enable_static_tor" = "yes"; then + enable_static_libevent="yes"; + enable_static_openssl="yes"; + enable_static_zlib="yes"; + AC_MSG_NOTICE("We're attempting to build a static Tor.") + CFLAGS="$CFLAGS -static" +fi if test x$enable_buf_freelists != xno; then AC_DEFINE(ENABLE_BUF_FREELISTS, 1, @@ -516,6 +527,20 @@ else fi AC_SUBST(TOR_ZLIB_LIBS) +if test "$enable_static_tor" = "yes"; then + if test "$enable_static_libevent" = "no"; then + AC_MSG_ERROR("You must configure with --enable-static-libevent") + fi + if test "$enable_static_openssl" = "no"; then + AC_MSG_ERROR("You must configure with --enable-static-openssl") + fi + if test "$enable_static_zlib" = "no"; then + AC_MSG_ERROR("You must configure with --enable-static-zlib") + fi + AC_MSG_NOTICE("We're attempting to build a static Tor.") + CFLAGS="$CFLAGS -static" +fi + dnl Make sure to enable support for large off_t if available.