I've produced a working static Tor binary but creating this causes a few warnings:
Making all in ormake[3]: Entering directory `/tmp/tor/src/or'gcc -g -O2 -static -Wall -g -O2 -fno-strict-aliasing -L/tmp/static-tor/zlib-1.2.5 -L/tmp/static-tor/openssl-0.9.8r/ -L/tmp/static-tor/libevent-1.4.14b-stable -o tor tor_main.o ./libtor.a ../common/libor.a ../common/libor-crypto.a ../common/libor-event.a /tmp/static-tor/zlib-1.2.5/libz.a -lm /tmp/static-tor/libevent-1.4.14b-stable/libevent.a -lrt /tmp/static-tor/openssl-0.9.8r//libssl.a /tmp/static-tor/openssl-0.9.8r//libcrypto.a -lpthread -ldl /tmp/static-tor/openssl-0.9.8r//libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':dso_dlfcn.c:(.text+0x5b4): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking../common/libor.a(compat.o): In function `get_user_homedir':/tmp/tor/src/common/compat.c:1502: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking./libtor.a(control.o): In function `getinfo_helper_misc':/tmp/tor/src/or/control.c:1379: warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking../common/libor.a(address.o): In function `tor_addr_lookup':/tmp/tor/src/common/address.c:171: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linkingmake[3]: Leaving directory `/tmp/tor/src/or'
This produces a "working" Tor binary:
% file src/or/torsrc/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
Anything interacting with PAM or dlopen will cause serious failures.
We shouldn't merge this as-is I believe: static builds on OS X don't work generally, and some of the help text is duplicated/slightly wrong. I'll work on a followup patch for the things I noticed.
Then, before I forget: What is the usecase here? I can see how statically linking libevent, zlib and openssl can help, but how does an explicit -static make us better?
We shouldn't merge this as-is I believe: static builds on OS X don't work generally, and some of the help text is duplicated/slightly wrong. I'll work on a followup patch for the things I noticed.
I think it's fine that it doesn't work for Mac OS X - we should just explain that as a limitation or encourage them to build the required Mac OS X module.
We could hack up the autoconf to complain about using this flag when building on Mac OS X. Is what you think think would make for a reasonable compromise?
Then, before I forget: What is the usecase here? I can see how statically linking libevent, zlib and openssl can help, but how does an explicit -static make us better?
There are many uses of a fully static Tor:
We'll have a very small, stripped down binary to be used for bootstrapping
This will give us a very small option for GetTor to be used with mail providers that have strict limits
Debugging OpenSSL/zlib/libevent hacks on the client side during censorship events
Allowing people to easily have a single Tor binary for academic projects
Easy tests of Tor on strange platforms with a cross compiler (build & scp over)
Tor Browser deployments where the system libraries are wonky or perhaps even bad
A user requested it and I was surprised it wasn't so easy to build statically
I'm still not fully convinced, it seems that a most of your points are perfectly achievable without an entirely static tor. I think we should definitely merge the first patch in your branch (to answer nickm's question, it is a bugfix on 0.2.1.23/0.2.2.8-alpha, where statically linking libevent was introduced), but consider whether we really want entirely static builds of Tor.
I'm still not fully convinced, it seems that a most of your points are perfectly achievable without an entirely static tor.
How would you begin to expect to say, survive a backdoored libc (think RedFlag Linux) without a totally static Tor?
A user requested this feature in the first place for a project on Linux where they expect a static build to work but they don't want to open any libraries or do anything on the system other than exec().
I'm not totally convinced that the redflag use case is a great idea, but I'm not opposed to merging this code: people come up with weird applications for build flags all the time!
Having this work on all platforms also isn't necessarily a requirement.
Eh, forgot to update this. Cleanup patch is in static-work in my repo. I still wonder if this static Tor works on a different computer than the one it was built on, the warnings during make seem to indicate to me that it might well fail. I haven't tested that yet, but will do that test.
You'll have to build Tor on a system that is very similar to the system where you want it to run. I don't think you'll find it easy to run 64bit binaries on 32bit machines, etc.