首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >`-fpic`和`-fPIC` gcc参数有什么区别?

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

Stack Overflow用户
提问于 2010-08-23 08:24:13
回答 2查看 34.8K关注 0票数 110

我已经阅读了gcc手册页,但我仍然不能理解-fpic-fPIC之间的区别。有人能用一种简单明了的方式解释一下吗?

相关问题:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-08-23 09:33:02

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

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

票数 122
EN

Stack Overflow用户

发布于 2017-06-06 02:26:32

Gcc manual page

在为共享库生成代码时,-fpic表示-M小数据,-fPIC表示-M大数据。

其中:

代码语言:javascript
复制
 -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.
票数 21
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3544035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档