- #1
Marmoteer
- 8
- 0
Hello! I was reading this excellent article about position independent code and it's implementation for shared libraries. I'm still confused about one part though. My current understanding is that the offset between the code section and data section is known at compile time. Since this offset never changes, variable references can be reassigned as the position of the currently executing instruction address plus the known offset to the data section. This is where I get confused. The author states that the variable is indirectly addressed via the Global Offset table which resides in the beginning of the DS. The addresses in the GOT are assigned at runtime. What I'm wondering is that if the data section's address is known relative to the current instruction why not just add the offset to the variable instead of going through the Global Offset Table?
To summarize if the GOT address is known relative to the code section and its offset is encoded into each variable/function reference why not just encode the relative variable address instead?
Is it that the the data section is scrambled for some reason and the GOT has the only consistent address? (0x0 I believe in the DS)
Anyway I hope my question isn't too confusing and thanks for the help.
Here's the article referred to in my question - http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/
Some relevant information:
Relocations - http://en.wikipedia.org/wiki/Relocation_(computing )
Data Segment - http://en.wikipedia.org/wiki/Data_segment
Position Independent Code - http://www.gentoo.org/proj/en/hardened/pic-guide.xml
To summarize if the GOT address is known relative to the code section and its offset is encoded into each variable/function reference why not just encode the relative variable address instead?
Is it that the the data section is scrambled for some reason and the GOT has the only consistent address? (0x0 I believe in the DS)
Anyway I hope my question isn't too confusing and thanks for the help.
Here's the article referred to in my question - http://eli.thegreenplace.net/2011/11/03/position-independent-code-pic-in-shared-libraries/
Some relevant information:
Relocations - http://en.wikipedia.org/wiki/Relocation_(computing )
Data Segment - http://en.wikipedia.org/wiki/Data_segment
Position Independent Code - http://www.gentoo.org/proj/en/hardened/pic-guide.xml
Last edited by a moderator: