how about .bss section not zero initialized

前端 未结 4 756
礼貌的吻别
礼貌的吻别 2021-01-03 04:53

as we know .bss contains un-initialized variables. if in c code, programer initialize the variables before using them. then .bss is not necessary to be zero before executing

4条回答
  •  我在风中等你
    2021-01-03 05:44

    The ELF specification says:

    .bss This section holds uninitialized data that contribute to the program’s memory image. By definition, the system initializes the data with zeros when the program begins to run. The section occupies no file space, as indicated by the section type, SHT_NOBITS.

    It therefore follows that a C global variable which has a value assigned to it cannot be put into the .bss section and will have to go into the .data section. The .data section contains the initial valued for all the variables assigned to it.

提交回复
热议问题