Position Independent and Position Dependent Code

When a machine wants to run a piece of software it first has to load it into memory. Code that can run regardless of where it is loaded is called position independent code, while code that has to be loaded at a certain location is called position dependent code. 

It used to be that all code was position dependent. Because of that, programs had to be scheduled to run in such a way that two programs would never need the same address space. To deal with the inconveniences that came with position dependent code, position independent programs were created. These days there is a memory management unit which allows each process to have its on address space, making it possible to run multiple position dependent programs which technically would use the same space at once. 

Position independent code is common if you want to write libraries for others to use. You want the code to be able to be loaded at any given space and still be able to run. Memory is allocated to whom every is there first, so the library has to work regardless of when and where it is loaded into memory.

There is also the concept of position independent and dependent executable files. It follows the same logic, where an executable file that is position dependent has to be loaded to a certain location in order to run. There is a security benefit to using position independent executable because it is harder for an attacker to find out where the program will run.

In essence, position independent code is more flexible but also a bit slower because the addresses have to be calculated as it goes. Position dependent code is less flexibly but a little faster as all the address are known in advance.