Chap6 static link

xxx.o ... relocatable, not executable. (diff is "program header")
executables has "program header", on the other hand relocatable not.

readelf -l /bin/pwd .. to see "program header"

/usr/bin/ld

nm hello.o (to find "symbol informaion" inside hello.o)

libc.a .. archive file

gcc -print-file-name=libc.a ... /usr/lib/libc.a

file /usr/lib/libc.a

ar t /usr/lib/libc.a

ar x /usr/lib/libc.a printf.o ... to extract

nm /usr/lib/libc.a 2>/dev/null | grep -C 5 "T printf$"
step1 nm /usr/lib/libc.a
step2 nm /usr/lib/libc.a 2> /dev/null
step3 grep -C ... Context option
T .. .text


nm /usr/lib/libc.a 2>/dev/null | grep -B 70 "T vfprintf$" (B.. Before)

nm /usr/lib/libc.a 2>/dev/null | grep -B 10 "D stdout$"
D .. .data

ld hello.o /usr/lib/libc.a

ld hello.o /usr/lib/libc.a -t ( -t option for Trace)

nm -u longdiv.o .. -u (undefined option)

libgcc.a ... gcc run time library

gcc -print-libgcc-file-name ... to find the path

nm `gcc -print-libgcc-file-name` 2> /dev/null | grep -C 5 "T --udivdif3$"


libgcc.a .. only static (.a) exists, there is no dynamic lib.


ldd hello.o /usr/lib/libc.a `gcc -print-libgcc-file-name` ; echo $?
.. this causing warning "cannot find entry symbol _start"

.. but this build execuable anyway.

crt files .. crt.o crti.o crtn.o crtbegin.o crtend.o
gcc -print-file-name=crt1.o
gcc -print-file-name=crti.o
gcc -print-file-name=crtn.o
gcc -print-file-name=crtbegin.o
gcc -print-file-name=crtend.o

$(cd /usr/lib; nm crt1.o crti.o crtn.o )

ld /usr/lib/crt1.o /usr/lib/crti.o hello.o /usr/lib/libc.a `gcc -print-libgcc-file-name` /usr/lib/crtn.o ; echo $?