107
votes

I've already read the gcc manpage, but I still can't understand the difference between -fpic and -fPIC. Can someone explain it, in a very simple and clear way?


Related questions:

2
Yes the answer isn't in man gccbut in info gcc, which have more documentation. - user2284570

2 Answers

21
votes

From the Gcc manual page:

When generating code for shared libraries, -fpic implies -msmall-data and -fPIC implies -mlarge-data.

Where:

 -msmall-data
 -mlarge-data
       When -mexplicit-relocs is in effect, static data is accessed via
       gp-relative relocations.  When -msmall-data is used, objects 8
       bytes long or smaller are placed in a small data area (the
       ".sdata" and ".sbss" sections) and are accessed via 16-bit
       relocations off of the $gp register.  This limits the size of the
       small data area to 64KB, but allows the variables to be directly
       accessed via a single instruction.

       The default is -mlarge-data.  With this option the data area is
       limited to just below 2GB.  Programs that require more than 2GB
       of data must use "malloc" or "mmap" to allocate the data in the
       heap instead of in the program's data segment.

       When generating code for shared libraries, -fpic implies
       -msmall-data and -fPIC implies -mlarge-data.