Subject: How to make a shared lib from static one
To: None <current-users@NetBSD.ORG>
From: VaX#n8 <vax@ccwf.cc.utexas.edu>
List: current-users
Date: 09/14/1995 00:05:34
I'm just curious about this:

I'm trying to make an libc.so.12.3 or equivalent shared libc by modifying
the "normal" version.  This modification involves adding my own functions
write(), read(), sbrk() etc., and renaming the old versions of write()
read() sbrk() to write_VMT() read_VMT() sbrk_VMT() etc.

My first attempt was similar to how I made the static versions:
1) extract "read", "write", "sbrk", etc. from libc_pic.a
2) use this program I inherited, binwrap, to modify the symbol "write"
   to "write_VMT" in write.so, and repeat for read, sbrk, etc.
3) add them back into the libc_pic.a
4) add my own wrappers (for "read", "write", "sbrk", etc.) into libc_pic.a

But this fails on step 2.  Binwrap, you see, uses bfdutils from GNU, which
gives:
binwrap writev.so writev_VMT.so _writev _writev_VMT
bfd assertion fail aoutx.h:2189

My second attempt was to compile the static version using -fPIC and then
extract all object files into a dir and link them using:
ld -Bdynamic -o libc.so.12.3 *
(This worked in SunOS).  It complains of no "__DYNAMIC" symbol.
(What the heck is that?)

Then I used:
ld -Bshareable -Bdynamic -o libc.so.12.3 *
Which worked but gave hundreds of errors like:
ld: yplib.o: RRS text relocation at 0x3ed6f for "_clnt_perror"
ld: yplib.o: RRS text relocation at 0x3ed9d for "_strdup"

Hmm... now that I think about it, perhaps I should have used libc_pic.a
as the basis rather than libc.a...

...but any tips on getting the first technique to work would be appreciated.
(Or any pointers on creating shared libs overall)
-- 
VaX#n8 (vak-sa-nate) - n, CS senior++ and Unix junkie - vax@ccwf.cc.utexas.edu
Deal with evil through strength, yet encourage good through trust.    - PGP me