What is the difference between the `-fpic` and` -fPIC` gcc options?

I already read the gcc man page, but I still can not understand the difference between -fpic and -fpic . Can someone explain this in a very simple and understandable way?




Related questions:

  • What does -fPIC mean when creating a shared library?
  • What, if any, are the consequences of compiling objects with the gcc -fPIC flag if they are used in executable files?
+73
gcc fpic
Aug 23 2018-10-10T00:
source share
2 answers

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Use -fPIC or -fPIC to create position-independent code. Whether to use -fPIC or -fPIC to create position-independent code depends on the goal. Choosing -fPIC always works, but can generate larger code than -fPIC (mnenomic, to remember that PIC is in a larger case, so it can generate more code). Using the -fPIC option will usually generate smaller and faster code, but will have platform-specific restrictions, such as the number of characters displayed worldwide or the size of the code. The component will tell you if it is suitable when creating a shared library. When in doubt, I choose -fPIC because it always works.

+87
Aug 23 '10 at 1:33
source share

On the Gcc manual page:

When generating code for shared libraries, -fpic means -msmall-data and -fPIC means -large 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 data segment. 
+6
Jun 05 '17 at 18:26
source share



All Articles