Skip to content

Relocation Set

Bedrock ELF objects use RELA relocation entries with explicit addends. The Bedrock ABI defines how each relocation type patches instruction or data fields.

Expression Model

Every static relocation starts with the canonical expression symbol + addend, where the symbol and explicit RELA addend are interpreted in the address space of the relocation family. Ordinary relocations use ABI symbol addresses, and TLS relocations use GS0-relative offsets.

Absolute and section-relative results are permitted when the selected relocation type defines them. PC-relative address materialization subtracts place, the address of the patched field. Direct branch and call payloads subtract next_pc, the address of the instruction following the patched instruction. An out-of-range result for the signedness and width stated in the relocation table is a link error, and the linker rejects the relocation.

For a PC-relative address-materialization relocation, let I be the address of byte zero of the containing instruction and let \(\delta=\texttt{place}-\texttt{I}\) be the relocation field’s byte offset. Let \(A_{\mathrm{src}}\) be the addend in the source expression before field-offset bias. The encoded value shall equal the target plus \(A_{\mathrm{src}}\) minus I. Because the relocation-table expressions subtract place, the assembler records the ELF addend as \(\texttt{addend}=A_{\mathrm{src}}+\delta\) for PCREL, GOTPCREL, GOT_BASE_PCREL, and TLSDESC_GOTPCREL relocations. The assembler supplies every field offset through the addend. The PLT addend described in Section 7.3 is one instance of this general rule.

Relocation Metasyntax Vocabulary

Relocation Metasyntax Vocabulary

Identifier or function Meaning
symbol Runtime byte address of the symbol named by the relocation after symbol resolution.
addend Explicit addend stored in the ELF64 Rela entry.
place Runtime byte address of the relocation field being patched.
next_pc Runtime byte address of the next instruction after the instruction being patched.
section_base Runtime byte address of the beginning of the symbol’s defining section.
symbol_size Byte size of the resolved symbol.
load_base Runtime load base address of the loaded object that owns the relocation.
got_base Runtime byte address of the global offset table base for the loaded object.
got(symbol) Runtime byte address of the GOT slot allocated for symbol.
plt(symbol) Runtime byte address of the PLT entry allocated for symbol.
tls(symbol) Byte offset of the TLS symbol from the ABI TLS base in GS0.
tlsdesc(symbol) Runtime byte address of the TLSDESC entry allocated for the TLS symbol.
resolver(x) Runtime byte address returned by calling the resolver function at address x.
copy(symbol, symbol_size) Copy operation over the resolved symbol’s bytes.
tls_descriptor(symbol) Adjacent function and argument words selected for the TLS symbol.

GOT and PLT Model

The ordinary GOT stores 64-bit addresses for position-independent code and dynamic binding. A GOT relocation allocates or references the symbol’s slot in the loaded object. The PLT contains executable near-call entries; a PLT relocation names that entry as its callable target. Every ordinary PLT slot is resolved before application entry or constructors execute.

GOT and PLT function addresses stay inside the ABI-visible near-call linkage domain.

Relocations

Bedrock ELF Relocation Types

Type Name Size Calculation
0 R_BEDROCK_NONE 0 0
1 R_BEDROCK_ABS8 8-bit unsigned symbol + addend
2 R_BEDROCK_ABS16 16-bit unsigned symbol + addend
3 R_BEDROCK_ABS32S 32-bit signed symbol + addend
4 R_BEDROCK_ABS64 64-bit unsigned symbol + addend
5 R_BEDROCK_IMM8S 8-bit signed symbol + addend
6 R_BEDROCK_IMM16S 16-bit signed symbol + addend
7 R_BEDROCK_IMM32S 32-bit signed symbol + addend
8 R_BEDROCK_IMM64 64-bit unsigned symbol + addend
9 R_BEDROCK_DISP8S 8-bit signed symbol + addend
10 R_BEDROCK_DISP16S 16-bit signed symbol + addend
11 R_BEDROCK_DISP32S 32-bit signed symbol + addend
12 R_BEDROCK_DISP64 64-bit unsigned symbol + addend
13 R_BEDROCK_PCREL8S 8-bit signed symbol + addend - place
14 R_BEDROCK_PCREL16S 16-bit signed symbol + addend - place
15 R_BEDROCK_PCREL32S 32-bit signed symbol + addend - place
16 R_BEDROCK_PCREL64 64-bit signed symbol + addend - place
17 R_BEDROCK_BRDISP8S 8-bit signed symbol + addend - next_pc
18 R_BEDROCK_BRDISP16S 16-bit signed symbol + addend - next_pc
19 R_BEDROCK_BRDISP32S 32-bit signed symbol + addend - next_pc
20 R_BEDROCK_CALL16S 16-bit signed symbol + addend - next_pc
21 R_BEDROCK_CALL32S 32-bit signed symbol + addend - next_pc
22 R_BEDROCK_SECTION_REL32 32-bit unsigned symbol + addend - section_base
23 R_BEDROCK_SECTION_REL64 64-bit unsigned symbol + addend - section_base
24 R_BEDROCK_GOT64 64-bit unsigned got(symbol) + addend
25 R_BEDROCK_GOTPCREL32S 32-bit signed got(symbol) + addend - place
26 R_BEDROCK_GOTPCREL64 64-bit signed got(symbol) + addend - place
27 R_BEDROCK_GOTOFF32S 32-bit signed symbol + addend - got_base
28 R_BEDROCK_GOTOFF64 64-bit signed symbol + addend - got_base
29 R_BEDROCK_GOT_BASE_PCREL32S 32-bit signed got_base + addend - place
30 R_BEDROCK_GOT_BASE_PCREL64 64-bit signed got_base + addend - place
31 R_BEDROCK_PLT16S 16-bit signed plt(symbol) + addend - next_pc
32 R_BEDROCK_PLT32S 32-bit signed plt(symbol) + addend - next_pc
33 R_BEDROCK_PLT64 64-bit unsigned plt(symbol) + addend
34 R_BEDROCK_RELATIVE 64-bit unsigned load_base + addend
35 R_BEDROCK_GLOB_DAT 64-bit unsigned symbol + addend
36 R_BEDROCK_JUMP_SLOT 64-bit unsigned symbol + addend
37 R_BEDROCK_COPY variable-size copy(symbol, symbol_size)
38 R_BEDROCK_IRELATIVE 64-bit unsigned resolver(load_base + addend)
39 R_BEDROCK_TLS_OFFSET32S 32-bit signed tls(symbol) + addend
40 R_BEDROCK_TLS_OFFSET64 64-bit signed tls(symbol) + addend
41 R_BEDROCK_TLSDESC_GOTPCREL32S 32-bit signed tlsdesc(symbol) + addend - place
42 R_BEDROCK_TLSDESC_GOTPCREL64 64-bit signed tlsdesc(symbol) + addend - place
43 R_BEDROCK_TLSDESC_CALL 0 0
44 R_BEDROCK_TLSDESC 128-bit pair tls_descriptor(symbol)

Relocation Families and Additional Constraints

Relocations 1–12 write absolute data, immediate, or effective-address payloads. Relocations 13–23 write PC-relative, next-instruction-relative, or section-relative results. Relocations 24–33 address GOT slots, the GOT base, symbols relative to that base, and PLT entries. Relocations 34–38 are ordinary dynamic-loader operations. Relocations 39–44 implement GS0 local-exec and TLSDESC TLS. The table defines widths and calculations; the dynamic-linking and TLS sections supply additional rules.