gpt4 book ai didi

ios - 如何测量静态库的代码(即数据+文本)大小?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:29 24 4
gpt4 key购买 nike

我已经在 SO 上寻找对此的答案,但没有找到。我有一个很大的静态库——它仍然有它的所有符号,所以它很大。我想知道的是链接到应用程序并剥离时它消耗的实际代码大小。

该库还将所有当前架构都嵌入其中,所以我真正需要的是每个架构的代码(即数据 + 文本)。

最佳答案

我发布这个最初是因为我很好奇,但今天一位客户真的很想知道所以我不得不挖掘。事实证明,有一个 CLI 命令 size 可以提供帮助:

$ size  -arch arm64 myLib.a
__TEXT __DATA __OBJC others dec hex
18436 7156 0 42642 68234 10a8a myLib.a(a.o)
1659 528 0 7209 9396 24b4 myLib.a(b.o)
...

哇——那个“其他”看起来真的很大。想知道里面有什么吗?嗯,试试 -m 选项,你会得到库中每个文件的非常长的输出,以及库中每个段的大小。

当我在我的库上使用 -m 选项时,我得到了一系列前缀名为“__debug”的段:

myLib.a(a.o):
Segment : 47665
Section (__TEXT, __text): 9832
Section (__DWARF, __debug_info): 9625
Section (__DWARF, __debug_abbrev): 867
Section (__DWARF, __debug_aranges): 64
Section (__DWARF, __debug_macinfo): 0
Section (__DWARF, __debug_line): 2142
Section (__DWARF, __debug_loc): 7237
Section (__DWARF, __debug_str): 4750
Section (__DWARF, __debug_ranges): 240
Section (__DATA, __data): 0
Section (__TEXT, __literal8): 16
...
Section (__DWARF, __apple_names): 2364
Section (__DWARF, __apple_objc): 196
Section (__DWARF, __apple_namespac): 36
Section (__DWARF, __apple_types): 1924
total 47652
total 47665

要获取此代码在最终应用程序中剥离时将消耗的值,我需要获取完整的段大小并减去所有带“__debug”前缀的段的大小。

# Get the full size of all object files in the library
$ size -m -arch arm64 *.a | grep '^.total' | sed -n -e 's/^.total //p' | awk '{s+=$1} END {print s}'
381423
$

# Get the size of the debugging sections:
$ size -m -arch arm64 *.a | grep __debug_ | sed -n -e 's/^.*: //p' | awk '{s+=$1} END {print s}'
212702
$

因此总数是 381423 - 212702 = 168721 # 或多或少

PS: awk 脚本来自 This SO post

关于ios - 如何测量静态库的代码(即数据+文本)大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22995744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com