Linking Programs on HP-UX

“The crt0.o Startup File” (page 21)

“The a.out File” (page 22)

“Magic Numbers (PA-RISC ONLY)” (page 22)

“File Permissions” (page 23)

The HP-UX linker (ld) creates an executable file, shared library, or combines the object files to create another relocatable object file. In doing so, it matches external references to global definitions contained in other object files or libraries. It revises code and data to reflect new addresses. This process is known as relocation. If the input files contain debugger information, ld updates this information appropriately. The linker places the resulting executable code in a file named, by default, a.out.

In the C program example, (see “Compiling Programs on HP-UX: An Example” (page 16) ) main.o contains an external reference to sum_n, which has a global definition in func.o.

The linker (ld) matches the external reference to the global definition, allowing the main program code in a.out to access sum_n (see Figure 3 (page 21)).

Figure 3 Matching the External Reference to sum_n

If the linker (ld) cannot match an external reference to a global definition, it displays a message to standard error output. If, for instance, you compile main.c without func.c, the linker (ld) cannot match the external reference to sum_n and displays this output:

$ cc -Aa main.c

ld: Unsatisfied symbol "func1" in file main.o 1 errors.

The crt0.o Startup File

Notice that in the PA32 example in “Compiler-Linker Interaction” (page 19) 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. The program's entry point is 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 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.

Linking Programs on HP-UX 21