ELF and General Executables

Programming, for all ages and all languages.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply