gpt4 book ai didi

gcc - 使用 flto 的要求

转载 作者:行者123 更新时间:2023-12-04 01:51:13 24 4
gpt4 key购买 nike

如果我想用 -flto 编译我的项目用 --enable-gold 构建 gcc 就够了吗?或者我还需要建立黄金并用它替换 ld 吗?我还需要其他标志吗?即我正在做这个

gcc -flto one.c two.c

最佳答案

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

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 documentation-fuse-linker-plugin说:

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即使您想使用特殊的“链接器插件”功能从库文件中的目标文件中获取优化信息。

-flto documentation中有使用示例.任何一个
      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用于链接:

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 :

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

关于gcc - 使用 flto 的要求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31688069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com