IT lexicon › Programming › Small data area

Small data area

Programming På svenska → Updated: 2026-11-05

A section for small global variables reached relative to a reserved register, so every access takes one instruction instead of two.

On RISC architectures a full address doesn't fit in one instruction; reading a global normally takes a pair, such as lui followed by a load. The MIPS ABI therefore reserved $gp to point into the middle of the .sdata and .sbss sections. Anything in there is reachable with a 16-bit offset, giving a 64 KB window. What counts as small is set with -G, 8 bytes by default.

PowerPC's embedded ABI uses the same idea with two registers. RISC-V is craftier: the compiler emits the long instruction pair and the linker, knowing where everything ended up, shrinks it to a single gp-relative instruction when the target lies within ±2 KB of the __global_pointer$ symbol. The classic link failure comes from two object files built with different -G values, one expecting a variable inside the window that the other never put there.

← Back to the lexicon