Linux PARISC architecture development
 help / color / mirror / Atom feed
From: Randolph Chung <randolph@tausq.org>
To: Alexander Gabert <pappy@nikita.ath.cx>
Cc: parisc-linux@parisc-linux.org
Subject: Re: [parisc-linux] -fPIC position independent code on parisc
Date: Sun, 27 Apr 2003 13:12:19 -0700	[thread overview]
Message-ID: <20030427201219.GE25257@tausq.org> (raw)
In-Reply-To: <20030427200418.GA30929@nikita.ath.cx>

> 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.

e.g.:

non-PIC
>     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.

PIC:
>     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.

HTH
randolph
-- 
Randolph Chung
Debian GNU/Linux Developer, hppa/ia64 ports
http://www.tausq.org/

  reply	other threads:[~2003-04-27 21:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-27 20:04 [parisc-linux] -fPIC position independent code on parisc Alexander Gabert
2003-04-27 20:12 ` Randolph Chung [this message]
     [not found]   ` <20030427231210.GA31520@nikita.ath.cx>
2003-04-27 22:34     ` Randolph Chung

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030427201219.GE25257@tausq.org \
    --to=randolph@tausq.org \
    --cc=pappy@nikita.ath.cx \
    --cc=parisc-linux@parisc-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox