`-fpic`和`-fPIC` gcc参数有什么区别?

Den*_*aia 89 gcc fpic

我已经阅读了gcc手册页,但我还是不明白之间的差别-fpic-fPIC.有人可以用一种非常简单明了的方式解释它吗?


相关问题:

Any*_*orn 104

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

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

  • 更重要的是:我在这里进行了一些实验(在x86_64平台上),`-fPIC`和`-fpic`似乎生成了相同的代码.它们似乎只在m68k,PowerPC和SPARC上生成不同的代码. (33认同)
  • 一个实验,一个版本的gcc以一种方式编译为某个目标.拿出一粒盐的结果,期望结果随着时间的推移而改变,特别是像GCC这样的工具. (3认同)

Ale*_*ira 15

Gcc手册页:

在为共享库生成代码时,-fpic意味着-msmall-data和-fPIC意味着-mlarge-data.

哪里:

 -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.
Run Code Online (Sandbox Code Playgroud)