启用LTO并检查是否使用LTO

发布于 2025-01-15 07:05:20 字数 1001 浏览 3 评论 0原文

我一直在尝试在我拥有的一些代码上启用 LTO,并且正在尝试找出执行此操作的说明。 GCC 是我正在使用的

我看到这里提到的一些说明: https://johnysswlab.com/link-time- optimizations-new-way-to-do-compiler-optimizations/

这基本上是上面链接中的设置: 要启用 LTO,请按照以下简单步骤操作:

将选项 -flto 添加到编译器的调用中。 将选项 -flto 添加到链接器的调用中。此外,您需要将编译器调用中的所有选项添加到链接器的调用中。因此,如果您使用“-march=i486 -O3 -fno-stack-protector”调用编译器,则需要将相同的选项传递给链接器。 现在您可以像平常一样编译程序。除非您使用的是非常旧版本的编译器,否则您不应该期望这里出现任何问题。

我也看到了这个,其中以 AR 切换到 gcc-ar 为例:

How编写支持 LTO 的代码?

问题:

  1. 此链接中的指令集足够吗? https://johnysswlab.com/link-time- optimizations-new-way-to-do-compiler-optimizations/ 还是我需要做一些额外的事情?静态和动态库编译相同吗?

  2. 在最终构建后如何验证是否确实使用了 LTO?

I have been trying to enable LTO on some code I have, and am trying to figure out the instructions to do it. GCC is what I am using

I see some instructions mentioned here:
https://johnysswlab.com/link-time-optimizations-new-way-to-do-compiler-optimizations/

This is basically the set in the link above:
To enable LTO, follow these simple steps:

Add option -flto to the invocation of compiler.
Add option -flto to the invocation of the linker. Additionally, you need to add all options from the compiler invocations to the invocation of the linker. So if you called your compiler with “-march=i486 -O3 -fno-stack-protector“, you will need to pass the same options to the linker.
Now you compile your program as regular. Unless you are using a very old version of the compiler, you shouldn’t expect any problems here.

I see this as well which talks about AR being switched to gcc-ar as an example:

How to write LTO-enabled code?

Questions:

  1. Is the set of instructions in this link enough? https://johnysswlab.com/link-time-optimizations-new-way-to-do-compiler-optimizations/ or is there something additional I need to do? Same for static and dynamic library compiles?

  2. How do I verify after my final build that LTO indeed was used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2025-01-22 07:05:20

此链接中的说明集是否足够?

是的。

我还需要做些什么吗?

不。

静态和动态库编译相同吗?

是的。

在最终构建之后,如何验证是否确实使用了 LTO?

如何检测使用 LTO 编译的代码?

Clang:如何检查是否执行了 LTO

Is the set of instructions in this link enough?

Yes.

is there something additional I need to do?

No.

Same for static and dynamic library compiles?

Yes.

How do I verify after my final build that LTO indeed was used?

How to detect code compiled with LTO?

Clang: How to check if LTO was performed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文