IT lexicon › Programming › Code model

Code model

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

The part of the ABI that decides how far apart code and data may sit, and therefore which addressing modes the compiler is allowed to use.

Most x86-64 instructions only carry 32-bit displacements, so an address more than ±2 GB away needs a separate 64-bit load. The default small model promises the whole program fits within 2 GB and can therefore use short RIP-relative addresses everywhere. kernel makes the same promise for the top 2 GB of the address space, where Linux lives. medium moves large data into sections of its own, and large assumes nothing at all, paying for it in longer, slower code.

It is selected with -mcmodel, and most people discover it exists when the linker says relocation truncated to fit: R_X86_64_PC32 — a sure sign someone has declared a three-gigabyte static array. AArch64 and RISC-V have models of their own built around the same problem.

← Back to the lexicon