Re: When do I need PIC?

"joshc" <>
31 Jul 2006 23:36:42 -0400

          From comp.compilers

Related articles
When do I need PIC? (joshc) (2006-07-28)
Re: When do I need PIC? (Vincent Zweije) (2006-07-29)
Re: When do I need PIC? (joshc) (2006-07-31)
Re: When do I need PIC? (russell kym horsell) (2006-08-03)
Re: When do I need PIC? (joshc) (2006-08-04)
Re: When do I need PIC? (glen herrmannsfeldt) (2006-08-09)
| List of all articles for this month |

From: "joshc" <>
Newsgroups: comp.compilers
Date: 31 Jul 2006 23:36:42 -0400
References: 06-07-092
Keywords: architecture
Posted-Date: 31 Jul 2006 23:36:42 EDT

joshc wrote:
> 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
> system.
> Thanks.
> [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]

Post a followup to this message

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