You copied the Doc URL to your clipboard.

Instructionand directive relocations

The assembler can embed relocation directives in object files to indicate labels with addresses that are unknown at assembly time. The assembler can relocate several types of instruction.

A relocation is a directive embedded in the object file thatenables source code to refer to a label whose target address isunknown or cannot be calculated at assembly time. The assembleremits a relocation in the object file, and the linker resolves thisto the address where the target is placed.

The assembler relocates the data directives DCB, DCW, DCWU, DCD,and DCDU if their syntax contains an externalsymbol, that is a symbol declared using IMPORT or EXTERN.This causes the bottom 8, 16, or 32 bits of the address to be usedat link-time.

The REQUIRE directive emits a relocationto signal to the linker that the target label must be present ifthe current section is present.

The assembler is permitted to emit a relocation for theseinstructions:

LDR (PC-relative)

All A32 and T32 instructions, except the T32 doubleword instruction, can be relocated.

PLD, PLDW, and PLI

All A32 and T32 instructions can be relocated.

B, BL, and BLX

All A32 and T32 instructions can be relocated.

CBZ and CBNZ

All T32 instructions can be relocated but this is discouraged because of the limited branch range of these instructions.

LDC and LDC2

Only A32 instructions can be relocated.

VLDR

Only A32 instructions can be relocated.

The assembler emits a relocation for these instructions ifthe label used meets any of the following requirements, as appropriatefor the instruction type:

  • The label is WEAK.
  • The label is not in the same AREA.
  • The label is external to the object (IMPORT or EXTERN).

For B, BL, and BX instructions, the assembler emits a relocation also if:

  • The label is a function.
  • The label is exported using EXPORT or GLOBAL.

Note

You can use the RELOC directive tocontrol the relocation at a finer level, but this requires knowledgeof the ABI.

Example

    IMPORT sym   ; sym is an external symbol    DCW sym      ; Because DCW only outputs 16 bits, only the lower                 ; 16 bits of the address of sym are inserted at                  ; link-time.

Related information