Chap7 dynamic link

libxxxx.so ... shared object

$nm libxx.so ... no symbol show
instead readelf -s /lib/libxxx.so .. this shows symbol informaion

gcc -l option ... -lc for libc.so and -lm for libm.so

crt1.o , crti.o , crtn.o (/usr/lib/crt1.o,crtio,crtn.o ..)

hirasawa@aspire-white:/usr/lib$ ls -l | grep crt
lrwxrwxrwx  1 root root           22 2011-05-17 19:46 Mcrt1.o -> i386-linux-gnu/Mcrt1.o
lrwxrwxrwx  1 root root           22 2011-05-17 19:46 Scrt1.o -> i386-linux-gnu/Scrt1.o
lrwxrwxrwx  1 root root           21 2011-05-17 19:46 crt1.o -> i386-linux-gnu/crt1.o
lrwxrwxrwx  1 root root           21 2011-05-17 19:46 crti.o -> i386-linux-gnu/crti.o
lrwxrwxrwx  1 root root           21 2011-05-17 19:46 crtn.o -> i386-linux-gnu/crtn.o
lrwxrwxrwx  1 root root           22 2011-05-17 19:46 gcrt1.o -> i386-linux-gnu/gcrt1.o
hirasawa@aspire-white:/usr/lib$ 

gcc runtime lib ... libgcc.a ( static lib only, no dynamic exits)

$ld /usr/lib/crt1.o /usr/lib/crti.o hello.o `gcc -print-libgcc-file-name` /usr/lib/crtn.o -lc ; echo $? ... a.out(executable,dynamically linked) but this a.out has imcomplete
"program header".

$readelf -l /bin/pwd
$readelf -l /lib/ld-linux.so.2 .. Dynamic linker/loader(a.k.a ELF loader)

$LD_DEBUG=help /bin/pwd .. show help msg
$/lib/ld-2.so --list /bin/pwd ... same as $ldd command

$LD_TRACE_LOADED_OBJECTS=1 /bin/ls

$ld /usr/lib/crt1.o /usr/lib/crti.o hello.o `gcc -print-libgcc-file-name` /usr/lib/crtn.o -lc -dynamic-linker /lib/ld-linux.so.2 ; echo $?

    • shared lib ( how do ELF-loader find shared-libs?)

how to make shared lib ... gcc -Wall -fPIC -shared -o libsharlib.so sharing.c

$file libsharelib.so ... $file command indicate this file is "shared object"

$ld --verbose command can check "linker scripts" ... great!


ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

test program ....

 inside this sharing_test.c there is ..
extern int sharing_function(void);

$gcc -Wall -o sharing_test sharing_test.c -l sharing
but this gcc op is not enought, can not find linkerlib path

$ld --verbose | grep SEARCH_DIR to check path

$gcc -Wall -o sharing_test sharing_test.c -l sharing -L./ ; echo $?

-L >> Library search path

$readelf -d ./sharing_test -d .. dynamic section

you can not execute ./sharing_test
@cause linker and ELFloader(library search path) are independent each other

$LD_TRACE_LOADED_OBJECT-1 ./sharing_test .. you can check

$LD_DEBUG=libs /bin/pwd

Finally you will find

LD_LIBRARY_PATH environment variable

1) /etc/ld.so cache
can check ldconfig -p to show cache contents
ldconfig to re-config cache