Making Fedora a contributer friendly environment (Re: Selinux and package guidelines)

Jakub Jelinek jakub at
Wed May 9 13:40:10 UTC 2007

On Wed, May 09, 2007 at 02:56:32PM +0200, Hans de Goede wrote:
> Jakub Jelinek wrote:
> >
> >DT_TEXTREL shared libraries are (almost always) a packaging bug which
> >should be fixed, not worked around by setting SELinux contexts.
> >In most cases that just means compiling all the objects that are linked
> >into the shared library with -fpic resp. -fPIC (for very large shared
> >libraries).
> >
> Sorry for going offtopic, but I've always wondered what the difference was 
> between -fpic resp. -fPIC, any good docs on this?

It differs from arch to arch.  On some architectures it is identical
(e.g. i386 or x86_64), elsewhere -fpic creates faster code that is usable
only in smaller shared libraries while -fPIC creates somewhat slower code
that can be used even in bigger shared libraries.  What actually means
small and large here is arch dependent.  E.g. on SPARC most load
instructions have signed 13-bit immediate offsets.  So, -fpic shared
libraries can load GOT entries with ld[%l7 + offset], %reg
(one instruction), but only if .got size is at most 8KB (if
_GLOBAL_OFFSET_TABLE_ points in the middle of .got, otherwise 4KB), i.e.
2048(1024) pointers for 32-bit and 1024(512) pointers for 64-bit.
-fPIC generates slower code, as load from GOT needs to be done with
3 instructions:
sethi %hi(offset), %regX	! load high 22 bits of offset
or %regX, %lo(offset), %regX	! low 10 bits ored into it
ld[%l7 + %regX], %reg		! load the GOT entry
On other arches the exact details are different, but in essence the
problem is the same.

So, the rules for using -f{pic,pie,PIC,PIE,no-pic} are:
1) use -fno-pic (the default) only for code that is linked into
   normal executables (not PIEs, not shared libraries)
2) use -f{pie,PIE} for code that is only linked into executables
   (normal ones and PIEs)
3) use -f{pic,PIC} otherwise

4) use -f{PIC,PIE} for code you put into .a libraries and you expect
   some other package will link things from that .a library into
   their shared libraries (or PIEs)
5) otherwise use -f{pic,pie}, if the shared library (PIE) links
6) if linking fails on some architecture due to relocation overflows,
   retry with -f{PIC,PIE} (ideally only on that architecture)


More information about the fedora-devel-list mailing list