IT lexicon › Programming › Linker relaxation

Linker relaxation

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

The linker, the first tool to know final addresses, replacing pessimistic instruction sequences with shorter ones that suffice for the actual distance.

The compiler can't know how far away a function will end up, so it assumes the worst. On RISC-V a call becomes an auipc + jalr pair reaching ±2 GB. If the target turns out to be within ±1 MB, a single jal will do, and the linker deletes the first instruction. The same applies to globals reachable relative to the gp register. The catch is that the assembler may not resolve local branches itself: when code shrinks everything after it moves, so every branch has to stay a relocation until the very end.

x86-64 has a milder form. Since binutils 2.26 in 2016, the linker can rewrite an indirect load through the GOT into a direct lea once the symbol turns out to be local, without moving anything.

← Back to the lexicon