Skip to content
Latchkey

What Is Position-Independent Code (PIC)?

Position-independent code is machine code that executes correctly no matter where in memory it is placed, because it references addresses relative to the program counter or through indirection tables. It avoids hard-coded absolute addresses that would break when the load location changes. Shared libraries are normally compiled this way so they can be mapped at any address.

Why it matters

PIC is what lets one shared library be loaded at different addresses in different processes and underpins address-space layout randomization. Without it, libraries could not be relocated freely at load time.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →