Linkers, Loaders & Executables
Which describes position-independent code (PIC)?
- AMachine code that runs the same on any CPU
- BMachine code that keeps moving itself in memory while it runs
- CMachine code built to run correctly without modification wherever in memory it is loaded
Show answer and explanation
Answer: C. Machine code built to run correctly without modification wherever in memory it is loaded
A shared library may be loaded at a different address in each process. Position-independent code refers to functions and data not by fixed addresses but by distances from the PC or through a table of addresses (the GOT). Then the code pages need no patching when the load address changes, so one copy in physical memory can be shared by many processes.
- A. Machine code differs for each ISA.
- B. It does not keep relocating itself.
- C. Correct. Shared libraries depend on it.