1
我已經看過所以這個答案,但沒有找到一個。我有一個很大的靜態庫 - 它的所有符號仍然很大。我想知道的是,當鏈接到應用並剝離時,它消耗的實際代碼大小。我們需要的是每個架構的代碼(即數據+文本)。如何測量靜態庫的代碼(即數據+文本)大小?
我已經看過所以這個答案,但沒有找到一個。我有一個很大的靜態庫 - 它的所有符號仍然很大。我想知道的是,當鏈接到應用並剝離時,它消耗的實際代碼大小。我們需要的是每個架構的代碼(即數據+文本)。如何測量靜態庫的代碼(即數據+文本)大小?
我之所以發佈這是因爲我很好奇,但客戶真的很想知道今天,所以我不得不挖。原來,有一個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:從This SO post
awk
腳本