提问人:rstr1112 提问时间:2/27/2023 最后编辑:rstr1112 更新时间:2/27/2023 访问量:198
简单的结构增加 C++ Android 二进制文件的大小
Simple struct increasing size of C++ Android binary
问:
为什么将以下结构添加到我的公共标头会导致我的 android 二进制大小 (libMyLibrary.so) 增加 4KB?
#define EXPORT __attribute__((visibility("default")))
struct EXPORT ITest
{
inline static const std::string TestString = "TestString";
};
使用 nm 不是很有帮助,因为它只给了我两个条目,对应于只增加了大约 32 字节的条目。 在使用 readelf 进一步调查时,很明显 .text 部分标题增加了 4KB。仅凭这些小代码行就已经很多了。 原因是什么,或者我将如何进一步调查?
下面是我使用的编译器和链接器标志:
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:RELEASE>: -g0
-Oz
-fvisibility=hidden
-fvisibility-inlines-hidden
-fno-rtti
-fno-unwind-tables
-fno-exceptions
-fno-omit-frame-pointer>
-Wno-null-conversion
)
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:RELEASE>: -g0
-Wl,--exclude-libs,ALL
-Wl,--gc-sections
-WX-,--icf=safe
-Wl,--strip-all>
)
readelf 的输出
There are 24 section headers, starting at offset 0xd5208:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .note.gnu.build-id NOTE 0000000000000200 000200 000024 00 A 0 0 4
[ 2] .gnu.hash GNU_HASH 0000000000000228 000228 000c58 00 A 3 0 8
[ 3] .dynsym DYNSYM 0000000000000e80 000e80 003048 18 A 4 3 8
[ 4] .dynstr STRTAB 0000000000003ec8 003ec8 008131 00 A 0 0 1
[ 5] .gnu.version VERSYM 000000000000bffa 00bffa 000406 02 A 3 0 2
[ 6] .gnu.version_r VERNEED 000000000000c400 00c400 000020 00 A 4 1 8
[ 7] .rela.dyn RELA 000000000000c420 00c420 00ead8 18 A 3 0 8
[ 8] .rela.plt RELA 000000000001aef8 01aef8 000df8 18 AI 3 19 8
[ 9] .plt PROGBITS 000000000001bcf0 01bcf0 000970 10 AX 0 0 16
[10] .text PROGBITS 000000000001c660 01c660 0acb14 00 AX 0 0 4
[11] .rodata PROGBITS 00000000000c9180 0c9180 004852 00 A 0 0 16
[12] .eh_frame_hdr PROGBITS 00000000000cd9d4 0cd9d4 000064 00 A 0 0 4
[13] .eh_frame PROGBITS 00000000000cda38 0cda38 0001c8 00 A 0 0 8
[14] .note.android.ident NOTE 00000000000cdc00 0cdc00 000098 00 A 0 0 4
[15] .init_array INIT_ARRAY 00000000000cf448 0ce448 000118 08 WA 0 0 8
[16] .fini_array FINI_ARRAY 00000000000cf560 0ce560 000010 08 WA 0 0 8
[17] .data.rel.ro PROGBITS 00000000000cf570 0ce570 006220 00 WA 0 0 8
[18] .dynamic DYNAMIC 00000000000d5790 0d4790 000200 10 WA 4 0 8
[19] .got PROGBITS 00000000000d5990 0d4990 000670 08 WA 0 0 8
[20] .data PROGBITS 00000000000d6000 0d5000 000040 00 WA 0 0 8
[21] .bss NOBITS 00000000000d6040 0d5040 0012c0 00 WA 0 0 8
[22] .comment PROGBITS 0000000000000000 0d5040 0000dc 01 MS 0 0 1
[23] .shstrtab STRTAB 0000000000000000 0d511c 0000e9 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
p (processor specific)
Symbol table '.dynsym' contains 515 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 000000000001c660 0 SECTION LOCAL DEFAULT 10
2: 00000000000cf570 0 SECTION LOCAL DEFAULT 17
3: 00000000000d6040 0 NOTYPE LOCAL DEFAULT ABS __bss_start__
4: 00000000000d7300 0 NOTYPE LOCAL DEFAULT ABS __end__
5: 00000000000d7300 0 NOTYPE LOCAL DEFAULT ABS __bss_end__
6: 00000000000d6040 0 NOTYPE LOCAL DEFAULT ABS __bss_start
7: 00000000000d7300 0 NOTYPE LOCAL DEFAULT ABS _bss_end__
8: 00000000000d7300 0 NOTYPE LOCAL DEFAULT ABS _end
9: 00000000000d6040 0 NOTYPE LOCAL DEFAULT ABS _edata
......
213: 0000000000042eb8 144 FUNC GLOBAL DEFAULT 10 <Hidden>
214: 00000000000d6248 24 OBJECT WEAK DEFAULT 21 _ZN9Namespace5ITest10TestStringE
215: 0000000000038a68 232 FUNC GLOBAL DEFAULT 10 <Hidden>
.....
327: 0000000000070728 60 FUNC WEAK DEFAULT 10 <Hidden>
328: 00000000000d6260 8 OBJECT WEAK DEFAULT 21 _ZGVN9Namespace5ITest10TestStringE
329: 00000000000ba8b8 156 FUNC GLOBAL DEFAULT 10 <Hidden>
.....
514: 0000000000040408 84 FUNC GLOBAL DEFAULT 10 <Hidden>
答: 暂无答案
评论
-S
-s