简体   繁体   English

gcc -fPIC似乎捣乱了优化标志

[英]gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization , I noticed that using gcc with -fPIC seems to destroy this optimization. 从这个问题开始: 如何执行i-check-if-gcc-is-perform-tail-recursion-optimization ,我注意到使用带有-fPIC的gcc似乎会破坏这种优化。 I am creating a shared library, but I doesn't seem to need the -fPIC option. 我正在创建一个共享库,但我似乎不需要-fPIC选项。

Well, my question is, why does -fPIC change gcc optimizations ? 好吧,我的问题是,为什么-fPIC会改变gcc优化? Do I need to keep -fPIC for any reason ? 我是否需要以任何理由保留-fPIC?

In absence of details such as target architecture and compiler version, a possible explanation is this: 在缺少目标体系结构和编译器版本等细节的情况下,可能的解释如下:

In position-dependent code, the tail-recursion optimization is essentially to reuse the current stack frame, and to replace the considered call by a jump . 在依赖于位置的代码中,尾递归优化本质上是重用当前的堆栈帧,并通过jump替换所考虑的call The syntax may be call function replaced by jmp <small offset of function> . 语法可以是由jmp <small offset of function>替换的call function

In position-independent code, the call may be written call function@PLT if the instruction set allows it (this example is amd64). 在与位置无关的代码中,如果指令集允许,则调用可以写成call function@PLT (这个例子是amd64)。 It could perfectly well be replaced by jmp <small offset of function>@PLT , but the two settings do interfere and perhaps gcc developers did not get around to implementing tail-call optimization in the latter mode. 它可以很好地被jmp <small offset of function>@PLT ,但是这两个设置确实会干扰,并且gcc开发人员可能没有在后一种模式中实现尾调用优化。

In ia32 linux, use of fpic means that you don't have ebx available for general purpose use, which will surely impact optimization. 在ia32 linux中,使用fpic意味着您没有可用于通用目的的ebx,这肯定会影响优化。 Perhaps the compiler decided against the tail recursion optimization due to register scheduling pressure. 由于寄存器调度压力,编译器可能决定不进行尾递归优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM