Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Feb 2000 19:05:47 -0800
From:      "Jordan K. Hubbard" <jkh@zippy.cdrom.com>
To:        jdp@freebsd.org
Cc:        peter@freebsd.org, current@freebsd.org
Subject:   "Interesting" failure mode for static linking with shared libs.
Message-ID:  <32351.951188747@zippy.cdrom.com>

next in thread | raw e-mail | index | archive | help
root@zippy-> cc -fPIC -c stub.c
root@zippy-> ld -shared -o stub.so stub.o
root@zippy-> cc -static test.c -o test stub.so
root@zippy-> ./test 
ELF interpreter /usr/lib/libc.so.1 not found
Abort trap
root@zippy-> cc -static test.c -o test stub.o
root@zippy-> ./test 
Now in the client, calling doit()
You have reached the stub.  Please leave a message.

As you can see from the first case, linking against the shared library
succeeds but generates an executable with rather sub-optimal behavior
and a bogus diagnostic to boot (I tried grabbing an old libc.so.1 from
the compat dists and installing it in /usr/lib just to see what it
would do, it had no effect).

I ran across this as part of my continuing efforts to make the openssl
library pull in the rsaref code at runtime, something which now works
just peachy in the dynamic linking case but does not work in the
static linking case.  That is to say that if I want to link ssh
static, for whatever reason, and I compile it up in the following ways
(the names used for the libs aren't exactly correct, I'm just
illustrating a point):

    1. cc -static ${SSHOBJS} -o ssh -lrsaref -lrsaglue -lssl

    2. cc -static ${SSHOBJS} -o ssh -lrsaglue -lssl

Then in case #2 the expected happens, e.g. ssh bitches about needing
the rsa code and aborts since dlopen() is not available to the rsaglue
stub functions I wrote and I'd consider that correct.

However, case #1 also causes the very same behavior, and that just
mystifies me since I'd have expected the "strong" symbols in librsaref
to have been bound to in preference to the weak ones in librsaglue.
I've also tried referencing the .a file directly in the link line
(cc -static ${SSHOBJS} -o ssh /usr/local/lib/librsaref.a -lrsaglue -lssl)
in hopes that this would somehow get it preferred just on that 
basis alone, but no deal.  Urk!  Any ideas?

- Jordan



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?32351.951188747>