Kenwood HP 9000 Personal Computer User Manual


 
68 Chapter 3
Linker Tasks
Using Linker commands
Use an assembly language routine named flush_cache (see “The
flush_cache Function” in this chapter). You must assemble this routine
separately (with the as command) and link it with the main program.
Step 8: Get the addresses of routines and data that are
referenced in the module.
If the -e linker option was used, the
module's header will contain the address of the entry point. The entry
point's address is stored in the .exec_entry member of the
som_exec_auxhdr structure.
If the module contains multiple routines and data that must be accessed
from the main program, the main program can use the nlist(3C) function
to get their addresses.
Another approach that can be used is to have the entry point routine
return the addresses of required routines and data.
An Example Program
To illustrate dynamic linking concepts, this section presents an example
program, dynprog. This program loads an object module named
dynobj.o, which is created by dynamically linking two object files
file1.o and file2.o (see “file1.o and file2.o”).
The program allocates space for dynobj.o by calling a function named
alloc_load_space (see “The alloc_load_space Function” later in this
chapter). The program then calls a function named dyn_load to
dynamically link and load dynobj.o (see “The dyn_load Function” later
in this chapter). Both functions are defined in a file called dynload.c
(see “dynload.c”).
As a return value, dyn_load provides the address of the entry point in
dynobj.o — in this case, the function foo. To get the addresses of the
function bar and the variable counter, the program uses the nlist(3C)
function.
“The Build Environment” shows the example makefile used to create
the dynprog program.
“Source for dynprog” shows the C source code for the dynprog
program.
“Output of dynprog” shows the run time output of the dynprog
program.
“The flush_cache Function” provides example source code in assembly
language to flush text from the data cache.