Tor link against static zlib broken by -pie switch
Build environment: CentOS v5.8/x86_64 with GCC v4.4.6.
I'm linking Tor against staticly-built versions of zlib (v1.2.7) and OpenSSL (v1.0.1c). This has always worked correctly with the 0.2.2.x versions of Tor. With version 0.2.3-20-rc the final link fails with this error:
$ gcc44 -m64 -O2 -g -march=native -mno-avx -D_FORTIFY_SOURCE=2 -fstack-protector-all -Wstack-protector -fwrapv --param ssp-buffer-size=1 -fPIE -Wall -fno-strict-aliasing -L/home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib -pie -z relro -z now -o tor tor_main.o ./libtor.a ../common/libor.a ../common/libor-crypto.a ../common/libor-event.a /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libz.a -lm /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libevent.a /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libssl.a /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libcrypto.a /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libz.a -ldl -lrt /usr/bin/ld: /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libz.a(deflate.o): relocation R_X86_64_32S against `_length_code' can not be used when making a shared object; recompile with -fPIC /home/rpmbuild/BUILD/tor-0.2.3.20-rc/dependencies/lib/libz.a: could not read symbols: Bad value
Removing that -pie switch allows the link to complete successfully.
The GCC doc suggests that the linking error is due to not having used -pie during compilation. This seems to be true as neither zlib nor openssl nor libevent are compiled with this switch (or with -fPIC). Not even the Tor source is compiled with -pie. It is used nowhere until that final link.
The offending symbol is defined in zlib's deflate.c, which is compiled with this command line:
gcc44 -m64 -O2 -g -march=native -mno-avx -c -o deflate.o deflate.c
Do we really need this -pie switch when linking Tor? What is the adverse impact if I just remove it from the linker input?
Trac:
Username: tmpname0901