cc -g -c prog.c mod1.c mod2.c mod3.c
cc -g -o prog_nolib prog.o mod1.o mod2.o mod3.o
strip(1) - discard symbols from object files.
Static lib:
ar r libdemo.a mod1.o mod2.o mod3.o
ar tv libdemo.a
# rw-rw-r-- 1000/1000 1003352 Apr 14 11:24 2014 mod1.o
# rw-rw-r-- 1000/1000 403352 Apr 14 11:24 2014 mod2.o
# rw-rw-r-- 1000/1000 43352 Apr 14 11:24 2014 mod3.o
cc -g -o prog prog.o libdemo.a
# or
cc -g -o prog prog.o -Lmylibdir -ldemo
./prog
Dinamic lib:
gcc -g -c -fPIC -Wall mod1.c mod2.c mod3.c
gcc -g -shared -o libfoo.so mod1.o mod2.o mod3.o
# or
gcc -g -fPIC -Wall mod1.c mod2.c mod3.c -shared -o libfoo.so
gcc -g -Wall -o prog prog.c libfoo.so
LD_LIBRARY_PATH=. ./prog
nm(1) - list symbols from object files
readelf(1) - displays information about ELF files
objdump(1) - display information from object files
ldd(1) - print shared library dependencies
ldconfig(1) - configure dynamic linker run-time bindings
nm mod1.o
readelf -s mod1.o
objdump --all-headers libfoo.so
readelf -d libfoo.so
Process shared libs:
cat /proc/PID/maps
Shared libs that prog required:
ldd /usr/sbin/tcpdump
# linux-vdso.so.1 => (0x00007fffe17ff000)
# libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007ff285828000)
# libpcap.so.0.8 => /usr/lib/x86_64-linux-gnu/libpcap.so.0.8 (0x00007ff2855ed000)
# libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff285224000)
# libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff285020000)
# libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff284e07000)
# /lib64/ld-linux-x86-64.so.2 (0x00007ff28606f000)
Where function defined:
nm -A /usr/lib/lib*.so 2> /dev/null | grep ' crypt$'
All system shared libs:
ldconfig –p
#1768 libs found in cache `/etc/ld.so.cache'
# libzvbi.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libzvbi.so.0
# libzvbi-chains.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libzvbi-chains.so.0
# libzltext.so.0.13 (libc6,x86-64) => /usr/lib/libzltext.so.0.13
# libzlcore.so.0.13 (libc6,x86-64) => /usr/lib/libzlcore.so.0.13
# libzip.so.2 (libc6,x86-64) => /usr/lib/libzip.so.2
#...
Path: LD_LIBRARY_PATH, DT_RPATH, DT_RUNPATH, $ORIGIN
gcc -Wl,-rpath,'$ORIGIN'/lib ...
Run-time symbol resolution:
gcc -g -c -fPIC -Wall -c foo.c
gcc -g -shared -o libfoo.so foo.o
gcc -g -o prog prog.c libfoo.so
LD_LIBRARY_PATH=. ./prog
# main-xyz
Monitoring dynamic linker:
LD_DEBUG=help ./prog
LD_DEBUG=all ./prog
No comments:
Post a Comment