reloc(4) — File Formats
Digital
NAME
reloc − relocation information for an object file
SYNOPSIS
#include <reloc.h>
DESCRIPTION
Object files have one relocation entry for each relocatable reference in the text or data. If relocation information is present, it will be in the following format.
structreloc
{
longr_vaddr ;/∗ (virtual) address of reference ∗/
longr_symndx ;/∗ index into symbol table ∗/
ushortr_type ;/∗ relocation type ∗/
unsignedr_symndx:24,/∗ index into symbol table ∗/
r_reserved:3,
r_type:4,/∗ relocation type ∗/
r_extern:1;/∗ if 1 symndx is an index into the external
symbol table, else symndx is a section # ∗/
} ;
/∗ Relocation types ∗/
#defineR_ABS0
#defineR_REFHALF1
#defineR_REFWORD2
#defineR_JMPADDR3
#defineR_REFHI4
#defineR_REFLO5
#defineR_GPREL6
#defineR_LITERAL7
/∗ Section numbers ∗/
#defineR_SN_NULL0
#defineR_SN_TEXT1
#defineR_SN_RDATA2
#defineR_SN_DATA3
#defineR_SN_SDATA4
#defineR_SN_SBSS5
#defineR_SN_BSS6
#defineR_SN_INIT7
#defineR_SN_LIT88
#defineR_SN_LIT49
The link editor reads each input section and performs relocation. The relocation entries direct how references found within the input section are treated.
If r_extern is zero then it is a local relocation entry and then r_symndex is a section number (R_SN_∗). For these entries the starting address for the section referenced by the section number is used in place of an external symbol table entry’s value. The assembler and loader always use local relocation entries if the item to be relocated is defined in the object file.
For every external relocation (except R_ABS) a signed constant is added to the symbol’s virtual address that the relocation entry refers to. This constant is assembled at the address being relocated.
R_ABS The reference is absolute and no relocation is necessary. The entry will be ignored.
R_REFHALF A 16-bit reference to the symbol’s virtual address.
R_REFWORD A 32-bit reference to the symbol’s virtual address.
R_JMPADDR A 26-bit jump instruction reference to the symbol’s virtual address.
R_REFHI A reference to the high 16-bits of the symbol’s virtual address. The next relocation entry must be the corresponding R_REFLO entry so the proper value of the constant to be added to the symbol’s virtual address can be reconstructed.
R_REFLO A reference to low 16-bits to the symbol’s virtual address.
R_GPREL A 16-bit offset to the symbol’s virtual address from the global pointer register.
R_LITERAL A 16-bit offset to the literal’s virtual address from the global pointer register.
Relocation entries are generated automatically by the assembler and automatically used by the link editor. Link editor options exist for both preserving and removing the relocation entries from object files.
The number of relocation entries for a section is found in the s_nreloc field of the section header. This field is a ‘C’ language short and can overflow with large objects. If this field overflows the section header s_flags field has the S_NRELOC_OVFL bit set. In this case the true number of relocation entries is found in the r_vaddr field of the first relocation entry for that section. That relocation entry has a type of R_ABS so it is ignored when the relocation takes place. This is a kluge.