Chapter 2 43
What Happens When You Compile and Link a Program
Linking Programs on HP-UX
The crt0.o Startup File
Notice in the example in “Compiler-Linker Interaction” that the first
object file on the linker command line is
/opt/langtools/lib/crt0.o, even though this file was not specified
on the compiler command line. This file, known as a startup file,
contains the program's entry point that is, the location at which the
program starts running after HP-UX loads it into memory to begin
execution. The startup code does such things as retrieving command line
arguments into the program at run time, and activating the dynamic
loader (dld.sl(5)) to load any required shared libraries. In the C
language, it also calls the routine _start in libc which, in turn, calls
the main program as a function.
The 64-bit linker uses the startup file,
/opt/langtools/lib/pa_64/crt0.o, when:
• The linker is in compatibility mode (+compat).
• The linker is in default standard mode (+std) with the -noshared
option.
If the -p profiling option is specified on the 32-bit mode compile line, the
compilers link with mcrt0.o instead of crt0.o. If the -G profiling option is
specified, the compilers link with gcrt0.o. In 64-bit mode with the -p
option, the linker adds -lprof before the -lc option. With the -G
option, the linker adds -lgprof.
If the linker option -I is specified to create an executable file with
profile-based optimization, in 32-bit mode icrt0.o is used, and in 64-bit
mode the linker inserts /usr/ccs/lib/pa20_64/fdp_init.o. If the
linker options -I and -b are specified to create a shared library with
profile-based optimization, in 32-bit mode scrt0.o is used, and in 64-bit
mode, the linker inserts /usr/ccs/lib/pa20_64/fdp_init_sl.o. In
64-bit mode, the linker uses the single 64-bit crt0.o to support these
option.
For details on startup files, see crt0(3).
The Program's Entry Point
In 32-bit mode and in 64-bit statically-bound (-noshared) executables,
the entry point is the location at which execution begins in the a.out
file. The entry point is defined by the symbol $START$ in crt0.o.