Kenwood HP 9000 Personal Computer User Manual


 
72 Chapter 3
Linker Tasks
Using Linker commands
glorp(“foo”);
(*counter_ptr) ++; /* update counter indirectly with global
pointer */
}
void bar()
{
glorp(“bar”);
counter ++; /* update counter directly */
}
/****************************************************************
* file2.c - Global counter variable referenced by dynprog.c
* and file1.c.
****************************************************************/
int counter = 0;
Output of dynprog . Now that you see how the main program and
the module it loads are organized, here is the output produced when
dynprog runs:
glorp called from main
glorp called from foo
glorp called from bar
counter = 3
dynload.c . The dynload.c file contains the definitions of the
functions alloc_load_space and dyn_load. “Include Directives for
dynload.c” shows the #include directives must appear at the start of
this file.
Include Directives for dynload.c
#include <stdio.h>
#include <stdlib.h>
#include <nlist.h>
# include <filehdr.h>
# include <aouthdr.h>
# define PAGE_SIZE 4096 /* memory page size */
The alloc_load_space Function . The alloc_load_space
function returns a pointer to space (allocated by malloc) into which
dynprog will load the object module dynobj.o. It syntax is:
void * alloc_load_space(const char * base_prog,
const char * obj_files,
const char * dest_file)
base_prog The name of the program that is calling the routine. In
other words, the name of the program that will
dynamically link and load dest_file.