Is there a reason why not to use link-time optimiz

2019-01-17 14:00发布

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?

3条回答
家丑人穷心不美
2楼-- · 2019-01-17 14:45

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).

The only good, valid reason I can think of is that link time optimization may introduce subtle bugs, see Link-time optimization for the kernel. Assuming that you have appropriate tests to check the correctness of your software that you are about to ship, I see no reason why not to use LTO by default. (LTO is getting more mature with time, so let's hope those subtle bugs will be less and less frequent.)

查看更多
劳资没心,怎么记你
3楼-- · 2019-01-17 14:56

This recent question raises another possible (but rather specific) case in which LTO may have undesirable effects: if the code in question is instrumented for timing, and separate compilation units have been used to try to preserve the relative ordering of the instrumented and instrumenting statements, then LTO has a good chance of destroying the necessary ordering.

I did say it was specific.

查看更多
在下西门庆
4楼-- · 2019-01-17 14:56

If you have well written code, it should only be advantageous. You may hit a compiler/linker bug, but this goes for all types of optimisation, this is rare.

Biggest downside is it drastically increases link time.

查看更多
登录 后发表回答