Kenwood HP 9000 Personal Computer User Manual


 
260 Chapter 7
Position-Independent Code
What Is Relocatable Object Code?
What Is Relocatable Object Code?
Relocatable object code is machine code that is generated by
compilers and assemblers and stored in relocatable object files, or .o
files. A relocatable object file contains symbolic references to locations
defined within the compilation unit as well as symbolic references to
locations defined outside the compilation unit. The object file also
contains relocation information. The linker uses this information to
replace the symbolic references with actual addresses.
For example, if you write a program that references the external variable
errno, the object code created by the compiler contains only a symbolic
reference to errno since errno is not defined in your program. Only
when the linker links this object code does the reference to errno change
(relocate) to an absolute address in virtual memory.
If your program defines a global variable, the compiler assigns a
relocatable address to that variable. The compiler also marks all
references to that variable as relocatable. The linker replaces the
references to the variable with the absolute address of the variable.