Kenwood HP 9000 Personal Computer User Manual


 
76 Chapter 3
Linker Tasks
Using Linker commands
*/
struct som_exec_auxhdr aux_hdr; /* som file auxiliary header
*/
unsigned int tdb_size; /* size of text, data, and bss
combined*/
/*
-----------------------------------------------------------------
* STEP 1: Dynamically link the module to be loaded:
*/
sprintf(cmd_buf,
“/bin/ld -a archive -A %s -R %x -N %s -o %s -lc -e %s”,
base_prog, addr, obj_files, dest_file, entry_pt);
if (ret_val = system(cmd_buf))
{
fprintf(stderr, “link command failed: %s\n”, cmd_buf);
exit(ret_val);
}
/*
-----------------------------------------------------------------
* STEP 2: Open dest_file. Read its auxiliary header for text,
data,
* and bss info:
*/
if ((destfp = fopen(dest_file, “r”)) == NULL)
{
fprintf(stderr, “error opening %s for loading\n”, dest_file);
exit(1);
}
/*
* Get auxiliary header information from “som_exec_auxhdr”
struct,
* which is after SOM header.
*/
if (fseek(destfp, sizeof(struct header), 0))
{
fprintf(stderr, “error seeking past header in %s\n”,
dest_file);
exit(1);
}
if (fread(&aux_hdr, sizeof(aux_hdr), 1, destfp) <= 0)
{
fprintf(stderr, “error reading som aux header from %s\n”,
dest_file);
exit(1);
}
/*
-----------------------------------------------------------------
* STEP 3: Read the text and data segments into the buffer area:
*/
/*
* Read text and data separately. First load the text:
*/