Opened 8 years ago

Closed 8 years ago

Last modified 3 years ago

#2698 closed defect (fixed)

Tor static build issues with libevent

Reported by: ioerror Owned by: nickm
Priority: High Milestone:
Component: Core Tor/Tor Version:
Severity: Normal Keywords: tor-client
Cc: nickm Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

When attempting to configure Tor with a static libevent, I find that Tor incorrectly bitches about the following:

checking for u_int8_t... yes
checking for libevent directory... (system)
checking whether we need extra options to link libevent... (none)
checking for event_get_version... yes
checking for event_get_version_number... no
checking for event_get_method... yes
checking for event_set_log_callback... yes
checking for evdns_set_outgoing_bind_address... no
checking for event_base_loopexit... yes
checking for struct event.min_heap_idx... yes
checking event2/event.h usability... no
checking event2/event.h presence... no
checking for event2/event.h... no
checking event2/dns.h usability... no
checking event2/dns.h presence... no
checking for event2/dns.h... no
checking event2/bufferevent_ssl.h usability... no
checking event2/bufferevent_ssl.h presence... no
checking for event2/bufferevent_ssl.h... no
configure: error: "You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent"

I configured with this configure switch:

./configure --enable-static-libevent --with-libevent-dir=/tmp/static-tor/libevent/usr/local

There are two problems.

First it declares that libevent is satisfied with the system libs:

checking for libevent directory... (system)

Secondly it complains that we didn't give a directory:

 --with-libevent-dir=/path/to/libevent/stuff

Configure stops here and we're unable to proceed normally. However, we hacked our way past this and discovered that configure may find include files but will not find the library files for libevent.

Child Tickets

Change History (24)

comment:1 Changed 8 years ago by ioerror

It appears that part of the issue is that when we test against the supplied libevent directory, we're failing because we failed to add '-lrt' to our test:

configure:6070: result: yes
configure:6106: checking for libevent directory
configure:6168: gcc -o conftest -g -O2 -I/tmp/static-tor/libevent/usr/local/include  -I${top_srcdir}/src/common -L/tmp/static-tor/libevent/usr/local/include  conftest.c -lpthread -ldl  -levent  >&5
/tmp/static-tor/libevent/usr/local/include/libevent.a(event.o): In function `gettime':
/tmp/static-tor/libevent-1.4.14b-stable/event.c:150: undefined reference to `clock_gettime'
/tmp/static-tor/libevent/usr/local/include/libevent.a(event.o): In function `detect_monotonic':
/tmp/static-tor/libevent-1.4.14b-stable/event.c:133: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
configure:6168: $? = 1

comment:2 Changed 8 years ago by ioerror

I've got a patch and I'll create a git branch with this and some other stuff in it shortly.

comment:3 Changed 8 years ago by ioerror

Success!

Configure and build:

/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

Now we have a mostly static build:

ldd src/or/tor
	linux-vdso.so.1 =>  (0x00007fff59bff000)
	libm.so.6 => /lib/libm.so.6 (0x00007f1c3cbdc000)
	librt.so.1 => /lib/librt.so.1 (0x00007f1c3c9d4000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00007f1c3c7b6000)
	libdl.so.2 => /lib/libdl.so.2 (0x00007f1c3c5b2000)
	libc.so.6 => /lib/libc.so.6 (0x00007f1c3c22f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f1c3ce83000)

comment:4 Changed 8 years ago by ioerror

Here's my git branch with the fix:
https://gitweb.torproject.org/ioerror/tor.git/commitdiff/7d82a51960efda4c02244fc24912356208afb795

Credit for this fix goes to John Gilmore and myself

comment:5 Changed 8 years ago by ioerror

Owner: set to nickm
Status: newassigned

comment:6 Changed 8 years ago by ioerror

Status: assignedneeds_review

comment:7 Changed 8 years ago by ioerror

It's probably also fair to consider this a bug in libevent or a bug in how we detect autoconf failures - we fail and fall back to system libraries, suggesting that the user never gave us a possible directory at all...

comment:8 Changed 8 years ago by nickm

That fix doesn't look right: Libevent only uses librt on platforms where librt exists. It doesn't exist everywhere. If the libevent-detection code searches for librt, I think that will make it it will fail everywhere that doesn't have a librt.

comment:9 Changed 8 years ago by ioerror

I've fixed up the patch with a new wip to address your concerns:
https://gitweb.torproject.org/ioerror/tor.git/commitdiff/92fc260c7c5b952b0b9a4db51586c9b895e6a10d

comment:11 Changed 8 years ago by nickm

Looks like it should work. Let me know when there's a cleaned-up static-tor branch to look at?

comment:12 Changed 8 years ago by ioerror

Ok - I'll squash up my two commits into two clean, different commits and update this ticket later tonight.

comment:13 Changed 8 years ago by ioerror

Ok, I'm a week later than I thought because of Comodogate. In any case, I've squished up the commits into two clean commits.

add --enable-static-tor to our configure script:
https://gitweb.torproject.org/ioerror/tor.git/commit/60a3b863d8e35fdc15b47ea2ff2f391983507c95

Fix libevent autoconf bug #2698 static-tor:
https://gitweb.torproject.org/ioerror/tor.git/commit/03b42c30fa573905b007d893f4151a5aed406389

comment:15 Changed 8 years ago by nickm

I'm not seeing the rebase action here: the branch static-tor still has a bunch of unmerged TLS stuff in it.

(In the future, btw, instead of linking to a single commit, it's easier to link to the branch or name it if you can, so I don't need to guess the branch name.)

comment:16 Changed 8 years ago by ioerror

Ah. There are two commits after a merge from master in my static-tor branch:
https://gitweb.torproject.org/ioerror/tor.git/shortlog/refs/heads/static-tor

They are "add --enable-static-tor to our configure script static-tor" and "Fix libevent autoconf bug #2698"

Those two commits have nothing to do with any previous work in the branch. If you'd like, I'll cherry pick those into a totally clean branch.

comment:17 Changed 8 years ago by ioerror

Ok, I've created a totally clean branch with two cherry picked commits:
https://gitweb.torproject.org/ioerror/tor.git/shortlog/refs/heads/static-work

comment:18 Changed 8 years ago by Sebastian

I've pushed a branch bug2698 that contains only the 2698 part of your branch, and a cleanup commit. I think we should merge it, and close this bug, then we can see what to do about 2702.

comment:19 Changed 8 years ago by Sebastian

I also put this on top of 0.2.2.x, because it seems like a bugfix that belongs there.

comment:20 Changed 8 years ago by ioerror

Sounds good - I'll let you and nickm handle the rest of this.

comment:21 Changed 8 years ago by nickm

Resolution: fixed
Status: needs_reviewclosed

Merging sebastian's bug2698 branch into maint-0.2.2.

comment:22 Changed 7 years ago by nickm

Keywords: tor-client added

comment:23 Changed 7 years ago by nickm

Component: Tor ClientTor

comment:24 Changed 3 years ago by rajhanschinmay

Severity: Normal

I am getting the same error.
Kindly let me know what can be wrong.
Could not find the solution above.
Tried changing the command with some affixes, but still the same error.
Thank you.

Note: See TracTickets for help on using tickets.