[parisc-linux] -fPIC position independent code on parisc

Randolph Chung Randolph Chung <randolph@tausq.org>
Sun, 27 Apr 2003 13:12:19 -0700

> but what exactly is position independent code?

it's exactly what it says, it will work no matter at what position
the code is loaded.


>     18          ldil LR'.LC0,%r19
>     19          ldo RR'.LC0(%r19),%r26
>     20          bl printf,%r2

This loads the address of .LC0 (your string) relative to a fixed address
into r26 (arg0). The address is resolved statically at link time, so
if the code is moved to a different starting address, the address will 
be wrong.

>     21          addil LT'.LC0,%r19
>     22          ldw RT'.LC0(%r1),%r1
>     23          copy %r1,%r26
>     24          bl printf,%r2

This calculates the offset of .LC0 relative to the linkage table pointer
(r19) by creating a GOT entry. The linkage table pointer is assigned 
value at runtime based on where the dynamic loader loads the code into 
memory, so the load will always point to the the right place wherever 
it is loaded. 

When you have a shared library, different programs that are linked
against the library may load it at different offsets, so the code must 
be position independent for it to work.

Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports