g++ 优化标志:-fuse-linker-plugin vs -fwhole-program [英] g++ Optimization Flags: -fuse-linker-plugin vs -fwhole-program

查看:39
本文介绍了g++ 优化标志:-fuse-linker-plugin vs -fwhole-program的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读:
http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

首先提示:
不应与使用此选项 (-fwhole-program) 的 -flto 结合使用.依赖链接器插件应该提供更安全、更精确的信息.

It first suggests:
In combination with -flto using this option (-fwhole-program) should not be used. Instead relying on a linker plugin should provide safer and more precise information.

然后,它建议:
如果程序不需要导出任何符号,则可以组合 -flto-fwhole-program 以允许过程间优化器使用更积极的假设,这可能导致改进的优化机会.当链接器插件处于活动状态时,不需要使用 -fwhole-program(参见 -fuse-linker-plugin).

And then, it suggests:
If the program does not require any symbols to be exported, it is possible to combine -flto and -fwhole-program to allow the interprocedural optimizers to use more aggressive assumptions which may lead to improved optimization opportunities. Use of -fwhole-program is not needed when linker plugin is active (see -fuse-linker-plugin).

这是否意味着理论上,使用 -fuse-linker-plugin-flto 总是比使用 -fwhole-program<获得更好的优化可执行文件/code> 与 -flto?

Does it mean that in theory, using -fuse-linker-plugin with -flto always gets a better optimized executable than using -fwhole-program with -flto?

我尝试使用 ld 分别与 -fuse-linker-plugin-fwhole-program 链接,以及可执行文件的大小至少是不同的.

I tried to use ld to link with -fuse-linker-plugin and -fwhole-program separately, and the executables' sizes at least are different.

附言我在 CentOS 6 上使用 gcc 4.6.2 和 ld 2.21.53.0.1.

P.S. I am using gcc 4.6.2, and ld 2.21.53.0.1 on CentOS 6.

推荐答案

更新:请参阅下面的 @PeterCordes 评论.基本上,不再需要 -fuse-linker-plugin.

UPDATE: See @PeterCordes comment below. Essentially, -fuse-linker-plugin is no longer necessary.

这些差异是微妙的.首先,了解 -flto 的实际作用.它本质上创建了一个可以稍后优化的输出(在链接时").

These differences are subtle. First, understand what -flto actually does. It essentially creates an output that can be optimized later (at "link-time").

-fwhole-program 所做的是假设当前编译单元代表正在编译的整个程序",无论实际情况是否如此.因此,GCC 将假定它知道调用特定函数的所有位置.正如它所说,它可能会使用更积极的过程间优化器.我稍后会解释.

What -fwhole-program does is assumes "that the current compilation unit represents the whole program being compiled" whether or not that is actually the case. Therefore, GCC will assume that it knows all of the places that call a particular function. As it says, it might use more aggressive inter-procedural optimizers. I'll explain that in a bit.

最后,-fuse-linker-plugin 实际上是在链接时执行优化,这通常会在执行每个编译单元时完成.所以,这个被设计成与 -flto 配对,因为 -flto 意味着保存足够的信息以供以后进行优化和 -fuse-linker-plugin意味着实际进行这些优化.

Lastly, what -fuse-linker-plugin does is actually perform the optimizations at link time that would normally be done as each compilation unit is performed. So, this one is designed to pair with -flto because -flto means save enough information to do optimizations later and -fuse-linker-plugin means actually do those optimizations.

那么,它们的区别在哪里?好吧,正如 GCC 文档所建议的那样,使用 -fwhole-program 原则上没有优势,因为该选项假定您必须确保正确.要打破它,只需在一个 .cpp 文件中定义一个函数并在另一个文件中使用它.您将收到链接器错误.

So, where do they differ? Well, as GCC doc suggests, there is no advantage in principle of using -fwhole-program because that option assumes something that you then have to ensure is true. To break it, simply define a function in one .cpp file and use it in another. You will get a linker error.

-fwhole-program 有什么优势吗?好吧,如果您只有一个编译单元,那么您可以使用它,但老实说,它不会更好.我能够通过使用等效程序获得不同大小的可执行文件,但是在检查实际生成的机器代码时,它们是相同的.事实上,我看到的唯一区别是带有调试信息的行号不同.

Is there any advantage to -fwhole-program? Well, if you only have one compilation unit then you can use it, but honestly, it won't be any better. I was able to get different sized executables by using equivalent programs, but when checking the actual generated machine code, they were identical. In fact, the only differences that I saw were that line numbers with debugging information were different.

这篇关于g++ 优化标志:-fuse-linker-plugin vs -fwhole-program的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆