When to generate PIC?

Ian Lance Taylor ian@airs.com
Wed Dec 14 01:00:00 GMT 2005


Erik Leunissen <e.leunissen@hccnet.nl> writes:

> I am developing a library that needs to be dynamically loaded into an
> application.
> 
> I am unsure whether or not to generate position independent code for
> this library. I just don't know which considerations are relevant for
> such a decision.
> 
> Could anybody enlighten me (or point me to information where I could
> enlighten myself)?

It is normally more efficient to use -fPIC when compiling any code
that is going to be linked into any shared library.  So you should use
-fPIC.

It is more efficient because with -fPIC code the dynamic linker
(including dlopen) has to apply fewer dynamic relocations at run time.

Ian



More information about the Gcc-help mailing list