Position-independent code
wikipedia Position-independent code
In computing, position-independent code[1] (PIC[1]) or position-independent executable (PIE) is a body of machine code that, being placed somewhere in the primary memory, executes properly regardless of its absolute address (无论其绝对地址如何,它都被放置在主存储器中的某个位置). PIC is commonly used for shared libraries, so that the same library code can be loaded in a location in each program address space where it will not overlap any other uses of memory (for example, other shared libraries). PIC was also used on older computer systems lacking an MMU,[2] so that the operating system could keep applications away from each other even within the single address space of an MMU-less system.
Position-independent code can be executed at any memory address without modification. This differs from absolute code,[1] which must be loaded at a specific location to function correctly,[1] and load-time locatable (LTL) code,[1] in which a linker or program loader modifies a program before execution so it can be run only from a particular memory location.[1] Generating position-independent code is often the default behavior for compilers, but they may place restrictions on the use of some language features, such as disallowing use of absolute addresses (position-independent code has to use relative addressing). Instructions that refer directly to specific memory addresses sometimes execute faster, and replacing them with equivalent relative-addressing instructions may result in slightly slower execution, although modern processors make the difference practically negligible.[3]