Difference between data section and the bss section in C

后端 未结 2 1124
忘了有多久
忘了有多久 2020-12-23 10:45

When checking the disassembly of the object file through the readelf, I see the data and the bss segments contain the same offset address. The data section will contain the

2条回答
  •  鱼传尺愫
    2020-12-23 11:01

    By definition, the bss segment takes some place in memory (when the program starts) but don't need any disk space. You need to define some variable to get it filled, so try

    int bigvar_in_bss[16300];
    int var_in_data[5] = {1,2,3,4,5};
    

    Your simple program might not have any data in .bss, and shared libraries (like libc.so) may have "their own .bss"

    File offsets and memory addresses are not easily related.

    Read more about the ELF specification, also use /proc/ (eg cat /proc/self/maps would display the address space of the cat process running that command). Read also proc(5)

提交回复
热议问题