使用flto的要求 [英] Requirements to use flto

查看:657
本文介绍了使用flto的要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想用-flto编译我的项目,用--enable-gold构建gcc是否足够?还是我还需要构建gold并用它替换ld?我还需要其他标志吗?即我正在这样做

If I want to compile my project with -flto is it enough to have built gcc with --enable-gold or do I also need to build gold and replace ld with it? And do I need any other flags? Ie I'm doing this

gcc -flto one.c two.c

推荐答案

根据 https://gcc.gnu.org/wiki/LinkTimeOptimization#Requirements

尽管名称为"链接时间",但LTO 不需要使用任何特殊的链接器功能.所需的基本机制是检测目标文件中的GIMPLE节.当前在collect2中实现.因此,LTO将在GCC已支持的任何链接器上工作.

Despite the "link time" name, LTO does not need to use any special linker features. The basic mechanism needed is the detection of GIMPLE sections inside object files. This is currently implemented in collect2. Therefore, LTO will work on any linker already supported by GCC.

此外, GCC文档表示-fuse-linker-plugin:

当启用了GCC中的LTO支持并且将GCC配置为与支持插件的链接器(GNU ld 2.21或更高版本)一起使用时,默认情况下启用此选项.

This option is enabled by default when LTO support in GCC is enabled and GCC was configured for use with a linker supporting plugins (GNU ld 2.21 or newer or gold).

因此,即使您想使用特殊的链接器插件"功能从库档案中的目标文件中获取优化信息,也根本不需要gold.

So you don't need gold at all, even if you want to use the special "linker plugin" feature to pick up optimization information from object files in library archives.

-flto文档中有一些用法示例.要么

There are usage examples in the -flto documentation. Either

      gcc -o myprog -flto -O2 foo.c bar.c

      gcc -c -O2 -flto foo.c
      gcc -c -O2 -flto bar.c
      gcc -o myprog -flto -O2 foo.o bar.o

将起作用.

截至 GCC 4.9 ,您甚至不需要-flto进行链接:

As of GCC 4.9, you don't even need -flto for linking:

唯一要记住的是,要启用链接时间优化,您需要使用GCC驱动程序来执行链接步骤.然后,如果使用-flto编译了涉及的任何对象,则GCC会自动执行链接时优化.

The only important thing to keep in mind is that to enable link-time optimizations you need to use the GCC driver to perform the link-step. GCC then automatically performs link-time optimization if any of the objects involved were compiled with the -flto.

并且自 GCC 5 :

与早期的GCC版本相反,链接命令行上传递的优化和目标选项将被忽略.

Contrary to earlier GCC releases, the optimization and target options passed on the link command line are ignored.

这篇关于使用flto的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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