问题描述
GCC、MSVC、LLVM 和可能的其他工具链支持链接时(整个程序)优化,以允许优化编译单元之间的调用.
GCC, MSVC, LLVM, and probably other toolchains have support for link-time (whole program) optimization to allow optimization of calls among compilation units.
编译生产软件时是否有理由不启用此选项?
Is there a reason not to enable this option when compiling production software?
推荐答案
我假设 生产软件"是指您交付给客户/投入生产的软件.为什么不总是使用编译器优化?(由 Mankarse) 主要适用于您想要调试代码(因此该软件仍处于开发阶段 - 未投入生产).
I assume that by "production software" you mean software that you ship to the customers / goes into production. The answers at Why not always use compiler optimization? (kindly pointed out by Mankarse) mostly apply to situations in which you want to debug your code (so the software is still in the development phase -- not in production).
自从我写下这个答案已经过去了 6 年,需要更新.早在 2014 年,问题是:
6 years have passed since I wrote this answer, and an update is necessary. Back in 2014, the issues were:
- 链接时间优化偶尔会引入微妙的错误,例如参见链接时间优化内核.我认为这在 2020 年不再是一个问题.防范这些类型的编译器和链接器错误:进行适当的测试以检查您即将发布的软件的正确性.
- 增加编译时间.有人声称自 2014 年以来情况已显着改善,例如由于 slim对象.
- 大量内存使用.这篇文章声称近年来情况有了很大改善,感谢分区.
- Link time optimization occasionally introduced subtle bugs, see for example Link-time optimization for the kernel. I assume this is less of an issue as of 2020. Safeguard against these kinds of compiler and linker bugs: Have appropriate tests to check the correctness of your software that you are about to ship.
- Increased compile time. There are claims that the situation has significantly improved since 2014, for example thanks to slim objects.
- Large memory usage. This post claims that the situation has drastically improved in recent years, thanks to partitioning.
从 2020 年开始,我将尝试在我的任何项目中默认使用 LTO.
As of 2020, I would try to use LTO by default on any of my projects.
这篇关于是否有理由不使用链接时优化 (LTO)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!