"i" 8 , BSS, 4 , ?
First, why 4 bytes in data segment?
- .data , . 4 , int i=10;.
Now, why 8 bytes in .bss segment?
- script GNU linker GNU ld. script .
GNU linker (GNU ld) script.
script .bss.
script, , -
gcc -Wl,-verbose main.c
gcc :
using internal linker script:
==================================================
==================================================
script .bss:
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
. = ALIGN(. != 0 ? 64 / 8 : 1);, 8 .
:
#include <stdio.h>
int i;
void main()
{
}
script, 'i' 8 BSS - 8 :
text data bss dec hex filename
1040 484 24 1548 60c a.out
[bss = 24 (16 + 8)]
GNU linker script, script script.
, script script GNU ld:
gcc -Xlinker -T my_linker_script main.c
script, .
.bss . = ALIGN(. != 0 ? 64 / 8 : 1); . = ALIGN(. != 0 ? 32 / 8 : 1);. 8 4 . script .
:
text data bss dec hex filename
1040 484 20 1544 608 a.out
bss size is 20 bytes (16 + 4) - 4 .
, .