|When do I need PIC? firstname.lastname@example.org (joshc) (2006-07-28)|
|Re: When do I need PIC? email@example.com (Vincent Zweije) (2006-07-29)|
|Re: When do I need PIC? firstname.lastname@example.org (joshc) (2006-07-31)|
|Re: When do I need PIC? email@example.com (russell kym horsell) (2006-08-03)|
|Re: When do I need PIC? firstname.lastname@example.org (joshc) (2006-08-04)|
|Re: When do I need PIC? email@example.com (glen herrmannsfeldt) (2006-08-09)|
|Date:||31 Jul 2006 23:36:42 -0400|
> 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.
> Are the above two points correct, and what else do I need to worry
> about? As you can probably tell this is in the context of an embedded
> [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]
The point of my question was that there are some cases where you can
get away with not compiling code as position independent because due
to the function's nature the compiler generates no code that is
position-relative for that function. In fact, I have done this with
some code that I am currently using and am able to relocate it without
specifically compiling it as position independent.
In my situation it is a bit of a pain if I have to compile my one
particular function as position independent so I was just looking for
things that would force me to have to compile the function as PIC to
be able to relocate it. I know I could just try not to compile it as
PIC and look at the assembly emitted by the compiler but was looking
for input from compiler gurus.
[This is entirely dependent on your target machine's architecture.
If it uses base register for data references and jumps are either
relative or also off base registers, a lot of code is probably PIC
without making special efforts. If the instruction set has a lot
of direct addresses, it's not. -John]
Return to the
Search the comp.compilers archives again.