8 Writing and Generating Position-Independent Code
This chapter is useful mainly to programmers who want to write
•“What is a Relocatable Object Code?” (page 185)
•“What is a Absolute Object Code?” (page 185)
•“What is a
•“Generating
NOTE: This chapter is applicable to only
http://devresource.hp.com/drc/STK/docs/archive/pa64rt.pdf
For the corresponding information for IPF applications, see Itanium Software Conventions and Runtime Architecture available at:
What is a 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 because 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.
What is a Absolute Object Code?
Absolute object code is a machine code that contains references to actual addresses within the program's address space. When the linker combines relocatable object files to build a program file or a.out file, it writes absolute object code into the file. Thus, when the program is executed, its routines and data reside at the addresses determined by the linker.
Note that absolute object code does not contain physical addresses. Physical addresses refer to exact locations in physical memory. Instead, absolute object code contains virtual addresses within a process's address space. These virtual addresses are mapped to physical addresses by the
Program files contain absolute virtual addresses. Hence exec the
What is a Relocatable Object Code? 185