Contents    Page-10    Prev    Next    Page+10    Index   

Position Independent Code

Position independent code (PIC) or a position independent executable (PIE) is code that can run correctly at an arbitrary memory location.

Ordinary absolute code specifies a full absolute address for operands, so that the code will not work if moved to another location in memory:


100240:      load pi       -->    LOAD 100260
        ...
100260:  pi: 3.1415

Position independent code uses an address relative to the current instruction pointer (IP) or program counter (PC):


100240:      load pi(rip)  -->    LOAD 20 (rip)
            ...
100260:  pi: 3.1415
This code would work if moved to another location. The address field is also smaller, which might save memory and make it faster.