HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 24 (of 101)
Chapter 11 Software Development
October 29, 2013
Loading The Dynamic Loader
As mentioned in the linking section of the previous chapter, every executable starts with the
same object, crt0.o. It contains the startup code that is necessary to invoke the dynamic loader,
which is itself a shared library. The path to the dynamic loader is the same as the default path for
shared libraries, and is hardcoded into crt0.o:
Executable Type
Path of the Dynamic Loader
PA-RISC 32-bit
/usr/lib/dld.sl
PA-RISC 64-bit
/usr/lib/pa20_64/dld.sl
IA64 32-bit
/usr/lib/hpux32/dld.so
IA64 64-bit
/usr/lib/hpux64/dld.so
The code in crt0.o loads it and passes control to it:
open("/usr/lib/hpux32/dld.so", O_RDONLY, 0) .............. = 3
read(3, "7fE L F 0102010101\0\0\0\0\0\0\0".., 1024) ...... = 1024
mmap(NULL, 735056, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FILE|MAP_SHLIB, 3, 0) =
0xc001c000
sysconf(_SC_PAGE_SIZE) ................................... = 4096
mmap(NULL, 6760, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_SHLIB, -1,
0) = 0x79806000
mmap(0x79803000, 11480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FILE|MAP_SHLIB,
3, 786432) = 0x79803000
close(3) ................................................. = 0
Loading Libraries
The dynamic loader reads the shared library list of the executable and loads them one by one.
Each library can have a shared library list itself, so the dynamic loader checks if it has one and if
yes, it loads the listed libraries recursively.
In the HelloWorld program dld.so loads the following libraries:
open("/usr/lib/hpux32/libc.so.1", O_RDONLY, 0) ........... = 3
:
open("/usr/lib/hpux32/libdl.so.1", O_RDONLY, 0) .......... = 3
:
libc.so.1 and libdl.so.1 are loaded, although HelloWorld only has libc.so.1 in its shared
library list. libdl.so.1 is loaded because it is listed in the shared library list of libc.2: