Clang 在静态链接期间删除死代码(gcc 相当于 -Wl、--gc-sections) [英] Clang removing dead code during static linking (gcc equivalent of -Wl, --gc-sections)

查看:35
本文介绍了Clang 在静态链接期间删除死代码(gcc 相当于 -Wl、--gc-sections)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在链接一个静态库,我想知道应该如何处理 llvm/Clang 中死代码的剥离.我找不到任何暗示 Clang 具有 -Wl、--gc-section 或 -dead_strip 等价物的文档.

I'm linking against a static library and I wonder how one should handle stripping of dead code in llvm/Clang. I can't find any documentation that hints that Clang has some equivalent of -Wl, --gc-section or -dead_strip.

我假设在更高的优化级别会自动执行一些死代码消除,但在 gcc 中也是如此,对吧?然而,gcc 通过上述标志提供了一些明确的控制.Clang 没有提供,还是我遗漏了什么?

I assume that some dead code elimination is performed automatically at the higher optimisation levels, but that's the case in gcc too, right? Yet, gcc provides some explicit control of this via the above mentioned flags. Does Clang not provide that or am I missing something?

(系统是OSX)

推荐答案

Dead Stripping 是链接器功能,而不是编译器功能.因此,gcc 和 clang 都没有它.这就是您必须使用 -Wl 的原因 - 您正在将该标志传递给链接器.Mac OS X 链接器使用 -dead_strip.您可以将标志直接传递给您的 clang 调用,它会自动传递.

Dead stripping is a linker feature, not a compiler feature. Neither gcc nor clang have it, as a result. That's why you had to use -Wl - you're passing that flag to the linker. The Mac OS X linker uses -dead_strip. You can pass the flag directly to your clang invocation and it will pass it through automatically.

这篇关于Clang 在静态链接期间删除死代码(gcc 相当于 -Wl、--gc-sections)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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