LLVM


1:Defining Fixups and Relocations

Within LLVM, fixups are used to represent information in instructions which is currently unknown. During instruction encoding, if some information is unknown (such as a memory location of an external symbol), it is encoded as if the value is equal to 0 and a fixup is emitted which contains information on how to rewrite the value when information is known.

The assembler goes through a stage of relaxation, applying fixups and modifying instruction values when they become known to the system. Once complete, any remaining fixups are converted to relocations and stored in the object file.

ELF Relocation types for a target are defined as an enum in the LLVM support header include/llvm/Support/ELF.h and are referred to as llvm::ELF::RELOCNAME.

fixups are defined in lib/Target/arch/MCTargetDesc/ archFixupKinds.h, with (in the general case) one fixup being created for each relocation type defined above, with the exception of the no relocation required reloc.

These go into an enum called Fixups. The enum has its first item set to the value of FirstTargetFixupKind and ends with a marker for LastTargetFixupKind. The total number of fixups is then defined as NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind. An example of the fixups used in the OpenRISC 1000  implementation is shown below.