PIC information

From Free Pascal wiki
Revision as of 09:37, 7 August 2004 by FPK (talk | contribs)
Jump to navigationJump to search

The linker/loader maintain a global offset table, which consists of an array of pointers to exported variables. All access to those variables is supposed to go through these pointers, if the variable could reside within another dynamic object.

If 'variable' is an exported symbol, then 'variable@GOT' is replaced by the linker with a constant: the offset of the GOT slot containing the pointer to variable. So, if the %ebx register contains the start address of the GOT, you can retrieve this pointer via

movl variable@GOT(%ebx), %eax

If you want the value of the variable, you need another indirection:

movl (%eax), %eax

If you know, however, that the variable in question must reside in the same dynamic object as the user, then you can avoid that double indirection, by using the GOTOFF facility. 'variable@GOTOFF' is replaced by the linker with another constant: the difference between the absolute address of the variable and the address of the global offset table (of the current dynamic object). Thus, you can retrieve the value of the variable in one step using:

movl variable@GOTOFF(%ebx), %eax

(source unknown)