This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: -fPIC and shared object
- From: Andrew Haley <aph-gcc at littlepinkcloud dot COM>
- To: "Olivier Delannoy" <olivier dot delannoy at gmail dot com>
- Cc: gcc <gcc-help at gcc dot gnu dot org>
- Date: Thu, 28 Jun 2007 11:19:49 +0100
- Subject: Re: -fPIC and shared object
- References: <2b9a46b30706280307t21c1ae7er3e4089116158f4bc@mail.gmail.com>
Olivier Delannoy writes:
> Hello,
>
> I am using linux and I would like to understand the role of -fPIC. I
> understand that it generate code where function address can be
> calculated indirectly after relocation of the .so in applications
> using it. My questions are :
>
> - Is it required to compile with -fPIC every object file packed in a
> dynamic shared object ?
Yes. (Well, kinda: there is a platform that allows relocation to be
performed on shared objects after loading, but it's inefficient and is
purely a backawards compatibility hack.)
> - Is is possible to integrate a static library in a .so safely
> (assuming the static library is not compiled using -fPIC)
No.
> - Is the answer to the previous question the same if the library is
> used only within the boundary of the .so (hidden to the rest of the
> application) ?
Yes.
Andrew.