[comp.unix.aix] rebuilding the shared libc

forsyth@minster.york.ac.uk (06/05/91)

has anyone worked out precisely what ld options, and import and
export files to use to build a new version of the C library,
with some functions replaced?
(we are running rs6000 aix version 3003.)

everything i have tried yields undefined symbols, redefinitions,
or an implausibly small shr.o (much smaller than the original)

perhaps someone else has already worked through all this (eg, the aix developers)
and could either post the details or tell me where to find them!

shaggy@kleikamp.austin.ibm.com (David J. Kleikamp) (06/07/91)

In article <676126057.15477@minster.york.ac.uk> forsyth@minster.york.ac.uk writes:
>has anyone worked out precisely what ld options, and import and
>export files to use to build a new version of the C library,
>with some functions replaced?
>(we are running rs6000 aix version 3003.)

This has worked for me:

First extract shr.o from libc.a:
	ar x /lib/libc.a shr.o
	mv shr.o shr.o.orig

Next create an exports file:
	dump -Tv shr.o.orig | awk '$$4 == "EXP" {print $$8}' > libc.exp

now the bind:
   ld -bh:4 -D0 -bnso -H512 -T512 -bM:SRE -o shr.o {your files} shr.o.orig \
   /lib/libs.a -bI:/lib/syscalls.exp -bE:libc.exp -bE:/lib/syscalls.exp

Of course, you can add exports to libc.exp as you so desire.
-- 
---------------------------------------------------------------------------
David J. "Shaggy" Kleikamp	dave@kleikamp.austin.ibm.com
The content of this posting is independent of official IBM position.
External: uunet!cs.utexas.edu!ibmaus!auschs!kleikamp.austin.ibm.com!dave

marc@watson.ibm.com (Marc Auslander) (06/07/91)

You need a file called libc.exp.  But its not shipped!  So you have to
hack one.  

Extract the old shr.o from libc.a.  Then dump -n shr.o.  The output is
a list of all the imported and/or exported symbols for the object.
In general, you need to reduce this to a list of exported symbols.
The IMEX field is supposed to tell you this, but its coding is
apparently funny.  It should correspond to the l_smtype field in
/usr/include/loader.h, but the bits appear scrambled.  BUT, for
libc.a[shr.o] all the symbols are in fact exported, so just take them
all.  Then, to replace a program, for example malloc.o, do:

ld malloc.o shr.o -o newshr.o -bE:libc.exp -bI:/lib/syscalls.exp

and put the new shr.o (named shr.o) into libc.a.

You can test the new libc.a first by setting
LIBPATH=mydir:/lib:/usr/lib where mydir contains the new libc.a and
running stuff.  If that looks good, you can (as root) mount
mydir/libc.a /lib/libc.a 
which will override all subsequent uses in the system until you reboot or unmount.

To replace libc.a, you should, as root:

cp mydir/libc.a /lib/newlibc.a
cp -p /lib/libc.a /lib/libc.a.orig  (only do this once)
mv /lib/newlibc.a /lib/libc.a

mv is atomic, so you don't risk winding up with no libc.a at all.  

If the new libc.a breaks the system, you will have to boot from
diskette to fix it!
--


Marc Auslander       (IBM)<marc@marc.watson.ibm.com>  (Internet)<marc@watson.ibm.com>