Chapter 3 75
Linker Tasks
Using Linker commands
The base_prog, obj_files, and dest_file parameters are the same
parameters supplied to alloc_load_space. The addr parameter is the
address returned by alloc_load_space, and the entry_pt parameter
specifies a symbol name that you want to act as the entry point in the
module.
To dynamically link and load dest_file into base_prog, the dyn_load
function performs these steps:
1. Dynamically link base_prog with obj_files, producing dest_file. The
address at which dest_file will be loaded into memory is specified with
the -R addr option. The name of the entry point for the file is
specified with -e entry_pt.
2. Open dest_file and get its header information on the text, data, and
bss segments. Read this information into a som_exec_auxhdr
structure, which starts immediately after a header structure.
3. Read the text and data segments into the area allocated by
alloc_load_space. (The text and data segments are read
separately.)
4. Initialize (fill with zeros) the bss, which starts immediately after the
data segment.
5. Flush text from the data cache before execution, using the
flush_cache routine. (See “The flush_cache Function” later in this
chapter.)
6. Return a pointer to the entry point, specified by the -e option in Step
1.
C Source for dyn_load Function
void * dyn_load(const char * base_prog,
unsigned int addr,
const char * obj_files,
const char * dest_file,
const char * entry_pt)
{
char cmd_buf[256]; /* buffer holding linker command
*/
int ret_val; /* holds return value of library calls
*/
FILE * destfp; /* file pointer for destination file
*/
unsigned int bss_start; /* start address of bss in VM
*/
unsigned int bss_size; /* size of bss */
unsigned int entry_pt_addr; /* address of entry point