This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: When to generate PIC?
- From: Ian Lance Taylor <ian at airs dot com>
- To: Erik Leunissen <e dot leunissen at hccnet dot nl>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 13 Dec 2005 16:59:50 -0800
- Subject: Re: When to generate PIC?
- References: <439F0877.7020606@hccnet.nl>
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