The relocation value
A relocation directive either refers to the value of a symbol, or to the base address of an AOF area in the same object file as the AOF area containing the directive. This value is called the relocation value, and the subject field is modified by it, as described in the following subsections.
A special case of PC-relative relocation occurs when the relocation value is specified to be the base of the area containing the subject field. In this case, the relocation value is not added and:
subject-field = subject-field + relocation-value
- base-of-area-containing (subject-field)
which caters for a PC-relative branch to a fixed location, for example.
subject-field = subject-field - base-of-area-containing
(subject-field)
Forcing use of an inter-link-unit entry point
A second special case of PC-relative relocation (specified by REL_B being set in the rel_flags field - see ARM Object Format for details) applies when the relocation value is the value of a code symbol. It requests that the inter-link-unit value of the symbol be used, rather than the intra-link-unit value. Unless the symbol is marked with the SYM_LEAFAT attribute (by a compiler or via the assembler's EXPORT directive), the inter-link-unit value will be 4 bytes beyond the intra-link-unit value.
This directive allows the tail-call optimisation to be performed on reentrant code. For more information about tail call continuation see Function entry-Introduction.
subject-field = subject-field + relocation-value
Based area relocation
A based area relocation directive relocates a subject field by the offset of the relocation value within the consolidated area containing it:
For example, when compiling reentrant code, the C compiler places address constants in an adcon area called sb$$adcons based on register sb, and generates code to load them using sb-relative LDRs. At link time, separate adcon areas are merged, so sb no longer points where presumed at compile time (except for the first area in the consolidated group). The offset field of each LDR (other than those in the first area) must be modified by the offset of the base of the appropriate adcon area in the consolidated group:
subject-field = subject-field + relocation-value
- base-of-area-group-containing (relocation-value)
LDR-offset = LDR-offset + base-of-my-sb$$adcons-area
- sb$$adcons$$Base
with value V = V1+V2+V3.
ADD Rb, rx, #V1
ADD Rb, Rb, #V2
LDR ry, [Rb, #V3]
The length of sequence recognised may be further restricted to 1, 2 or 3 instructions only by the relocation directive itself (see Relocation directives).
After relocation, the new value of V is split between the instructions as follows:
If there is a following LDR or STR, then any value remaining is assigned to it as an immediate offset. If this value is greater than 4095, then the relocation has overflowed.
In the relocation of a B or BL instruction, word offsets are converted to and from byte offsets. A B or BL is always relocated by itself, never in conjunction with any other instruction.