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

117

1
是的,答案不在 man gcc 中,而是在 info gcc 中,那里有更详细的文档。 - user2284570
2个回答

132

43
此外,我在x86_64平台上做了一个小实验,发现-fPIC-fpic生成的代码是一样的。似乎只有在m68k、PowerPC和SPARC上才会生成不同的代码。 - Denilson Sá Maia
7
一项使用某个特定编译方式编译GCC的单次实验,针对某个目标进行测试。请谨慎对待该结果,并预计该结果会随着时间的推移而发生变化,特别是在使用GCC等工具时。 - old_timer
我可以问一个问题吗?_全局可见符号_是什么意思? - Константин Ван
@DenilsonSáMaia 小更新:根据 man gcc 的说明,这也会对 ARM64 产生影响。 - iFreilicht

33

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.

1
链接的手册页面已经更新,请记得查看。 - youfu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接