Kenwood HP 9000 Personal Computer User Manual


 
74 Chapter 3
Linker Tasks
Using Linker commands
fprintf(stderr, “link failed: %s\n”, cmd_buf);
exit(ret_val);
}
/* ---------------------------------------------------------------
* STEP 2: Get the size of the module’s text, data, and bss segments
* from the auxiliary header for dest_file; add them together to
* determine size:
*/
if ((destfp = fopen(dest_file, “r”)) == NULL) {
fprintf(stderr, “error opening %s\n”, dest_file);
exit(1);
}
/*
* Must seek past SOM “header” to get to the desired
* “som_exec_auxhdr”:
*/
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);
}
/* allow for page-alignment of data segment */
space = aux_hdr.exec_tsize + aux_hdr.exec_dsize
+ aux_hdr.exec_bsize + 2 * PAGE_SIZE;
fclose(destfp); /* done reading from module file */
/* ---------------------------------------------------------------
* STEP 3: Call malloc(3C) to allocate the required memory and get
* its address; then return a pointer to the space:
*/
addr = (size_t) malloc(space);
/*
* Make sure allocated area is on page-aligned address:
*/
if (addr % PAGE_SIZE != 0) addr += PAGE_SIZE - (addr % PAGE_SIZE);
return((void *) addr);
}
The dyn_load Function . The dyn_load function dynamically links
and loads an object module into the space allocated by the
alloc_load_space function. In addition, it returns the address of the
entry point in the loaded module. Its syntax is:
void * dyn_load(const char * base_prog,
unsigned int addr,
const char * obj_files,
const char * dest_file,
const char * entry_pt)