IT lexicon › Programming › Position-independent code (PIC)

Position-independent code (PIC)

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

Machine code that works at whatever address it's loaded, because it never hard-codes its own addresses.

The trick is to address things relative to the program counter rather than absolutely, and to look up global addresses through a table — the GOT — that can be fixed up at load time. GCC does it with -fPIC or -fPIE. On the desktop it's what makes shared libraries and ASLR possible, at the cost of a little extra indirection.

It's rarer in firmware, but it turns up exactly where the bootloader gets interesting. An application for dual-bank flash should ideally run from either bank without being built twice, and loadable modules should go wherever there's room. ARM's own compilers call the variants ROPI and RWPI — position independence for read-only and read-write data respectively. The vector table is the classic trap: it holds absolute addresses and must be patched or relocated, or the first interrupt jumps into the other bank.

← Back to the lexicon