Object file 2026-11-05
An object file stores program components produced by a compiler or assembler, together with information needed to combine or load them. A relocatable object file commonly contains machine instructions and data divided into sections, named symbols, and relocation records for references whose final locations are not yet known.[ref]
Sections and Relocation in the GNU Assembler manual. §4.1 Background: sections and address adjustments; assembler relocation information
For example, compiling a file that calls
square can produce an object file containing the call-site instruction and an unresolved reference to that symbol. The linker (computing) later supplies its definition from another input. The file thus contains more than the bytes of a self-contained runnable program: its metadata describes how incomplete components fit together. Relocation (computing) 2026-11-05
Relocation (computing) adjusts references in program components to match the addresses assigned during linking or loading. A relocation record identifies a place to patch, a target symbol and an architecture-dependent rule for computing the replacement. Moving a section changes the addresses associated with its contents, even when their relative arrangement stays fixed.[ref]
Sections and Relocation in the GNU Assembler manual. §4.1 Background: assigning section addresses and adjusting references
In an illustrative absolute-address rule, a symbol address and addend produce . In a relative rule defined using reference address , they may produce . If , and , the latter gives an offset of . Actual instruction encodings specify the precise reference point, scaling and allowed range, so a linker (computing) must apply the relocation type's rule rather than blindly adding one constant everywhere.