[OTR-dev] Linking libgcrypt statically into gaim-otr.so

Ian Goldberg ian at cypherpunks.ca
Wed Mar 7 17:07:07 EST 2007


I figured out how to do this on Linux.  I have no idea how to do it on
other systems, or how to get libtool to do this on its own (possibly not
possible).

The problem, again: other gaim plugins, such as Jabber or ldap, use
libgcrypt (often in the guise of TLS).  libgcrypt uses global variables,
and assumes that it will only have one caller per address space.  The
various plugins initialize libgcrypt's global variables, and stomp all
over each other's (and gaim-otr's) initializations.  Badness ensues.

The "right" solution is for libgcrypt to stop using global variables,
and to pass handles around.  Back-compatibility can be easily arranged
by having the current routines do something like:

gcry_foo(int bar, char *baz)
{
    gcry_foo_r(&global_handle, bar, baz);
}

but callers "in the know" could call gcry_foo_r directly with a private
handle.

But until that happens, here's a workaround for gaim-otr to link
libgcrypt statically.  It's actually pretty tricky, since it seems calls
from one .o to another in a .so file are always looked up dynamically,
so if another copy of libgcrypt exists in the address space, you'll
still get that one.  So you have to put everything in a single .o, make
the libgcrypt symbols local, and turn the result into a .so.

Here's Makefile.static (for gaim-otr):

.libs/gaim-otr.so: FORCE
	# Build everything from the standard Makefile
	make
	# Link everything, including libotr and libgcrypt, together into
	# a single .o file
	ld -r  .libs/otr-plugin.o .libs/ui.o .libs/dialogs.o .libs/gtk-ui.o .libs/gtk-dialog.o /usr/lib/libotr.a /usr/lib/libgcrypt.a /usr/lib/libgpg-error.a -o .libs/gaim-otr-shared.o
	# Make all the libgcrypt references local to that .o file
	objcopy -w -L '*gcry*' .libs/gaim-otr-shared.o .libs/gaim-otr-static.o
	# Turn the .o into a .so
	gcc -shared .libs/gaim-otr-static.o -Wl,-soname -Wl,gaim-otr.so -o .libs/gaim-otr.so

FORCE:

   - Ian



More information about the OTR-dev mailing list