Subject: Re: How to make a shared lib from static one
To: VaX#n8 <vax@ccwf.cc.utexas.edu>
From: Zdenek Salvet <salvet@nyx.fi.muni.cz>
List: current-users
Date: 09/14/1995 21:07:19
VaX#n8 wrote:
> 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.
 
Why you don't use source files ?  Hacking binary is more difficult.
"read", "write", "sbrk" have no source files, they are gen. on the fly.
See src/lib/lic/sys/Makefile.inc for instructions on "read", "write", "sbrk"
object file generation. ( Basically 
   printf '#include "SYS.h"\nRSYSCALL(read)\n' | \
     cpp -DPIC |as -k -o read.so
)

> 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?)

The right command is
  ld -Bshareable -o libc.so.12.3 *.o
or
  ld -Bshareable -Bforcearchive -o libc.so.12.3 libc_pic.a

---
Zdenek Salvet
salvet@nyx.fi.muni.cz