He said that the Independent Position Code uses only a relative position instead of absolute positions, how is this implemented in c and assembly, respectively?
Take, char test[] = "string";for example, how to refer to it at a relative address?
char test[] = "string";
In C, position-independent code is a part of a compiler implementation. See the compiler guide to determine if it is supported and how.
. , , ( ), , .
, . , .
x86 :
call 1f 1: popl %ebx
ebx , popl.
ebx
popl
, PIC thunk:
load_ebx: movl 4(%esp),%ebx addl $some_offset,%ebx ret
, thunk ebx / ( ), ebx - .
, . pc ip .
pc
ip
:
lea str1(pc), r0 ; load address of string relative to the pc (assuming constant strings, maybe) st r0, test ; save the address in test (test could also be PIC, in which case it could be relative ; to some register)
, . - (-PIC -S gcc) , .