Relocation information
Object files have one relocation entry for each
relocatable reference in the text or data.
The relocation information consists of entries with the format
described in
Table 7-8, ``Relocation section contents''.
Table 7-8 Relocation section contents
Bytes Declaration Name Description
--------------------------------------------------------
0-3 long int r_vaddr (Virtual) address of
reference
4-7 long int r_symndx Symbol table index
8-9 unsigned short r_type Relocation type
The first 4 bytes of the entry are the virtual address of the text or data to which this entry applies. The next field is the index, counted from 0, of the symbol table entry that is being referenced. The type field indicates the type of relocation to be applied.
As the link editor reads each input section and performs relocation, the relocation entries are read. They direct how references found within the input section are treated. The currently recognized relocation types are given in Table 7-9, ``Relocation types''.
Table 7-9 Relocation types
Mnemonic Flag Meaning
----------------------------------------------
R_ABS 0 Reference is absolute; no
relocation is necessary.
The entry will be
ignored.
R_DIR16 ∗ 01 Direct, 16-bit reference
to a symbol's virtual
address.
R_REL16 ∗ 02 ``PC-relative'', 16-bit
reference to a symbol's
virtual address.
Relative references occur
in instructions such as
jumps and calls.
R_DIR32 06 Direct 32-bit reference
to the symbol's virtual
address.
R_SEG12 ∗ 011 Direct, 16-bit reference
to the segment-selector
bits of a 32-bit virtual
address.
R_PCRLONG + 024 ``PC-relative'', 32-bit
reference to a symbol's
virtual address.
----------------------------------------------
∗ 80286 Computer only.
+ 80386 Computer only.
The structure declaration for relocation entries is shown below. This declaration may be found in the header file reloc.h.
struct reloc
{
long r_vaddr; /* virtual address of reference */
long r_symndx; /* index into symbol table */
unsigned short r_type; /* relocation type */
};
#define RELOC struct reloc
#define RELSZ 10