在BSS 28额外的字节 [英] 28 extra bytes in bss
本文介绍了在BSS 28额外的字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
struct abc
{
char cc[32];
} mystruct;
int main()
{
}
当我运行上面的程序,.bss段有64个字节。我期待它是36个字节。 32字节MYSTRUCT并采取其他图书馆4个字节。
When I run the above program, the .bss section has 64 bytes. I was expecting it to be 36 bytes . 32 bytes for mystruct and 4 bytes which is taken by other libraries.
如果我更改字符CC [32]
到字符CC [31]
然后我得到了36个字节。 BSS。
If I change char cc[32]
to char cc[31]
then I get 36 bytes in .bss.
-bash-3.00$ g++ bssSize.cc
-bash-3.00$ readelf --sections ./a.out | grep bss
[23] .bss NOBITS 08049580 000578 000040 00 WA 0 0 32
-bash-3.00$
64是十六进制000040
64 is 000040 in hex
为什么.bss中这些额外的28个字节呢?
Why are these extra 28 bytes there in .bss ?
推荐答案
的 readelf
输出的最后一列是对齐,显示的数值确实是32。所以,BSS的尺寸被向上舍入到32字节的最接近倍数
The last column of the readelf
output is alignment, and the value shown is indeed "32". So, the BSS size is being rounded up to the nearest multiple of 32 bytes.
这篇关于在BSS 28额外的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文