Re: When do I need PIC?

Vincent Zweije <vzweije@sense.net>
29 Jul 2006 14:08:49 -0400

          From comp.compilers

Related articles
When do I need PIC? josh.curtz@gmail.com (joshc) (2006-07-28)
Re: When do I need PIC? vzweije@sense.net (Vincent Zweije) (2006-07-29)
Re: When do I need PIC? josh.curtz@gmail.com (joshc) (2006-07-31)
Re: When do I need PIC? kym@otaku.freeshell.org (russell kym horsell) (2006-08-03)
Re: When do I need PIC? josh.curtz@gmail.com (joshc) (2006-08-04)
Re: When do I need PIC? gah@ugcs.caltech.edu (glen herrmannsfeldt) (2006-08-09)
| List of all articles for this month |

From: Vincent Zweije <vzweije@sense.net>
Newsgroups: comp.compilers
Date: 29 Jul 2006 14:08:49 -0400
Organization: Zoft Structural
References: 06-07-092
Keywords: code, linker
Posted-Date: 29 Jul 2006 14:08:49 EDT

<josh.curtz@gmail.com> wrote:


|| So I'm pretty sure there's probably no standard that dictates this,
|| but with regards to the majority of compilers when does one need to
|| compile a function to be PIC? What I'm interested in is having the
|| ability to relocate functions from the address they were linked to and
|| executing these functions from their new locations. I know this
|| probably depends a lot on processor architecture and compiler, but
|| what sort of things would dictate whether or not I need to compile
|| this function to be PIC?


|| Some things that I think would dictate when I need PIC:
||
|| 1) Whether or not the function references any global data because the
|| variables might be accessed relative to the program counter.
|| 2) Whether or not the function calls any other functions because again
|| the branches could be relative vs absolute.


|| [The whole point of PIC is so you can move code from one place to another
|| without having to modify it. If you want to be able to relocate the code,
|| use PIC, if you don't, don't. -John]


I imagine that sharing a piece of code (shared library) between processes
would be facilitated by position independence, because then you wouldn't
have to map that code to the same virtual address in all processes.


You might hit some other snags though - linking, updating references to
other pieces of code. Don't know if that can be worked around.


Ciao. Vincent.
--
Vincent Zweije <zweije@xs4all.nl> | "If you're flamed in a group you
<http://www.xs4all.nl/~zweije/> | don't read, does anybody get burnt?"
[Xhost should be taken out and shot] | -- Paul Tomblin on a.s.r.
[All the problems involved in position-independent shared libraries have
been solved many times. Two familiar examples are Unix and Linux ELF
libraries and Windows DLLs. See my linker book for more details. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.