Re: When do I need PIC?

glen herrmannsfeldt <>
9 Aug 2006 00:00:18 -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: glen herrmannsfeldt <>
Newsgroups: comp.compilers
Date: 9 Aug 2006 00:00:18 -0400
Organization: Compilers Central
References: 06-07-092
Keywords: code, linker
Posted-Date: 09 Aug 2006 00:00:18 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.

I would expect only constant data to be referenced relative to the
program counter. There should be faster ways to reference other data,
at least on most machines around.

> 2) Whether or not the function calls any other functions because again
> the branches could be relative vs absolute.

As long as you move them together, it should be fine. I don't know if
any do that, though. If they do, the relocation information should be


> [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 remember from the SunOS 4.x days, the DLL for the C library, as supplied by sun didn't include routines to query a
nameserver. DLL's required PIC, but the static C library, libc.a,
didn't use PIC because it was slower. Sun then supplied a separate C
library that was PIC. One extracts all the entries as .o files,
replaces the desired files, and then creates a new from the

On most machines PIC is bigger and slower, and so is not used by
default. For any machine where it wasn't slower, it would probably be
used, to save the relocation time on program load.

-- glen

Post a followup to this message

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