gpt4 book ai didi

c - .data 和 .bss 的对齐方式是如何确定的

转载 作者:太空狗 更新时间:2023-10-29 17:26:26 26 4
gpt4 key购买 nike

.data和.bss的对齐有时是4字节,有时是32字节。示例 1:根据下面输出的最后一列,bss 和 data 的对齐方式为 32 字节

bash-3.00$ readelf --sections libmodel.so
There are 39 section headers, starting at offset 0x1908a63c:

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
...
[25] .data PROGBITS 01e221e0 1e211e0 26ca54 00 WA 0 0 32
[26] .bss NOBITS 0208ec40 208dc34 374178 00 WA 0 0 32
...

示例 2:根据下面的输出,对齐 os .data 和 .bss 是 4 个字节

bash-3.00$ readelf --sections ./a.out
There are 28 section headers, starting at offset 0x78c:

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
...
[22] .data PROGBITS 0804956c 00056c 000034 00 WA 0 0 4
[23] .bss NOBITS 080495a0 0005a0 000004 00 WA 0 0 4
...

什么决定了 .bss 和 .data 的对齐方式?为什么有时是 4 个字节,有时是 32 个字节?

最佳答案

我认为那些不同的对齐值是由各自的 ld 脚本决定的。

  • 对于 libmodel.so:section .data align=16, section .bss align=16
  • 对于a.out:section .data align=4, section .bss align=4

关于c - .data 和 .bss 的对齐方式是如何确定的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18181945/

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