यह आसान एक विशिष्ट संकलक के लिए परीक्षण करने के लिए काफी है:
$ cat bss.c
int global_no_value;
int global_initialized = 0;
int main(int argc, char* argv[]) {
return 0;
}
$ make bss
cc bss.c -o bss
$ readelf -s bss | grep global_
32: 0000000000400420 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
40: 0000000000400570 0 FUNC LOCAL DEFAULT 13 __do_global_ctors_aux
55: 0000000000601028 4 OBJECT GLOBAL DEFAULT 25 global_initialized
60: 000000000060102c 4 OBJECT GLOBAL DEFAULT 25 global_no_value
हम 0000000000601028
और 000000000060102c
के स्थान की तलाश कर रहे:
$ readelf -S bss
There are 30 section headers, starting at offset 0x1170:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
...
[24] .data PROGBITS 0000000000601008 00001008
0000000000000010 0000000000000000 WA 0 0 8
[25] .bss NOBITS 0000000000601018 00001018
0000000000000018 0000000000000000 WA 0 0 8
ऐसा लगता है कि दोनों मूल्यों की तरह .bss
में जमा हो जाती मेरे सिस्टम पर अनुभाग: gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4)
।
कोई विकल्प (परोक्ष
-fzero-initialized-in-bss
) के साथ संकलन क्या हुआ जब आप इसे आजमाते हैं? आप देख सकते हैं कि 'objdump -x' का उपयोग करके '.o' फ़ाइल में क्या है। –मैंने ए से नीचे की कोशिश की)। Int globalvar = 0; objdump -x परीक्षण> 1.txt बी) .for ==> int globalvar; objdump -x परीक्षण> 2.txt और diff है: - 2 .bss 00000004 00000000 00000000 00000058 2 ** 2 + 2 .bs 00000000 00000000 00000000 00000058 2 ** 2 -00000000 जी ओ।बीएसएस 00000004 globalvar +00000004 ओ * COM * 00000004 globalvar –
@ लूनर मशरूम अपडेट पोस्ट * अहम * :) –