www.delorie.com/djgpp/doc/coff/reloc.html   search  
COFF: Relocation Directives

typedef struct {
  unsigned long  r_vaddr;   /* address of relocation      */
  unsigned long  r_symndx;  /* symbol we're adjusting for */
  unsigned short r_type;    /* type of relocation         */

Warning: This structure's size is not a multiple of four. When reading from file, it is strongly recommended that either (1) you read each entry in a loop, reading RELSZ bytes each time, or allocate a block of memory and calculate a pointer to each entry you need by multiplying by RELSZ. In no case should you assume that array addressing or sizeof(RELOC) will be useful.

There are only two types of relocations that you will encounter in a normal DJGPP COFF object.

RELOC_ADDR32 6 Relocate a 32-bit absolute reference
RELOC_REL32 20 Relocate a 32-bit relative reference

For any relocation, you must determine the new address of the relocated symbol that we are adjusting for. If the symbol is in another object (external), the symbol table will contain a reference to that external symbol, and the relocation will refer to that symbol table entry. If the symbol is in the same object, the symbol table will have entries that refer to the sections themselves (always there and always private) that will be referred to. When you relocate the section itself, these symbols will reflect its new location.


To do this relocation, you must perform the following steps:


This relocation happens normally only in executable sections, and refers only to external symbols. To do this relocation, you must perform the following steps:

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 1996   by DJ Delorie     Updated Oct 1996