Page 2 of 2

Posted: Wed Feb 07, 2007 2:44 am
by Combuster
The linker doesnt change opcodes, so position independent code remains PIC, and the same goes for position dependent code.

What the linker can do is to keep some of the data in the object files to allow the application loader to manually adjust the addresses in the executable image (these are called relocations), and then provide standard offsets for the application, so that it can run normally at one predefined location.
The result is a position-independent executable, which can either be loaded at its normal address without hassle, or loaded and executed at any other address if the loader is intelligent enough to replace all the addresses with the correct values for the new location in memory.

Note that relocatable executables need more work from your side compared to PIC code.

You may want to look at my ELF relocator here (Its not the best code, but it is heavily commented)