|When do I need PIC? email@example.com (joshc) (2006-07-28)|
|Re: When do I need PIC? firstname.lastname@example.org (Vincent Zweije) (2006-07-29)|
|Re: When do I need PIC? email@example.com (joshc) (2006-07-31)|
|Re: When do I need PIC? firstname.lastname@example.org (russell kym horsell) (2006-08-03)|
|Re: When do I need PIC? email@example.com (joshc) (2006-08-04)|
|Re: When do I need PIC? firstname.lastname@example.org (glen herrmannsfeldt) (2006-08-09)|
|From:||Vincent Zweije <email@example.com>|
|Date:||29 Jul 2006 14:08:49 -0400|
|| 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.
Vincent Zweije <firstname.lastname@example.org> | "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]
Return to the
Search the comp.compilers archives again.