-fpic和gf参数有什么区别?

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

我已经阅读了gcc联机帮助页,但是我仍然不明白-fpic-fpic之间的区别。 有人可以用非常简单明了的方式解释它吗?

相关问题:

  • -fPIC在构建共享库时是什么意思?
  • 如果将gcc -fPIC标志用于可执行文件,编译它们的含义是什么?


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

使用-fPIC-fPIC生成与位置无关的代码。 使用-fPIC还是-fPIC生成与位置无关的代码取决于目标。 -fPIC选项始终有效,但可能会产生比-fPIC大的代码(要记住,这是因为PIC在较大的情况下,因此可能会产生大量的代码)。 使用-fPIC选项通常会生成更小,更快的代码,但是将具有与平台有关的限制,例如全局可见符号的数量或代码的大小。 创建共享库时,链接器将告诉您是否适合。 如有疑问,我选择-fPIC,因为它始终有效。


从Gcc手册页:

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

哪里:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 -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.