“-print_statistics”链接器选项在 Xcode 中产生错误

'-print_statistics' linker option produces error in Xcode

我想分析我们大型 C++ 项目的链接阶段,因为使用 Xcode 或 xcodebuild.

链接 iOS 项目最多需要 30 分钟

$ man ld 表示可以使用 '-print_statistics' 命令行选项。但是在 Build Settings 中通过 "Other Linker Flags" 设置此选项会在 Ld:

期间产生错误

clang: error: unknown argument: '-print_statistics'

看起来 Xcode 构建系统如何检查 "Other Linker Flags" 并且不识别“-print_statistics”。

XCode 使用 Clang/LLVM,所以我猜它也会使用 lld 作为链接器,而不是 ld,后者是 GNU 链接器。 lld 没有 -print-statistics,因此出现错误。

正如@shaiba 猜测的那样 Xcode 使用 Clang/LLVM。在幕后,LLVM 使用 LLD 链接器指向

"LLD is a drop-in replacement for the GNU linkers. That accepts the same command line arguments and linker scripts as GNU"

作为主要功能之一。

您尝试直接传递链接器参数是错误的。它应该通过 clang

-Wl,<arg>,<arg2>...
Pass the comma separated arguments in <arg> to the linker

-X
-Xlinker <arg>, --for-linker <arg>, --for-linker=<arg>
Pass <arg> to the linker

尝试设置-Wl,-print_statistics