The difference between .bss section and .data and .rodata section

 

Understanding these is very helpful to optimize the time and space of the program.

 

BSS segment:

The bss segment (Block Started by Symbol) usually refers to a memory area used to store uninitialized or initialized global variables in the program.

The interpretation of .bss in "Programming ground up" is: There is another section called the .bss. This section is like the data section, except that it doesn't take up space in the executable.
Both text and data sections are available The executable file is loaded by the system from the executable file; the bss section is not in the executable file and is initialized by the system.

This section has no size information in the ELF file, and after it is loaded into memory, it will be allocated a memory space where all words are initialized to 0 (most operating systems will clear all bss global variables when loading programs. , There is no need for you to manually clear it. But to ensure the portability of the program, it is also a good practice to manually initialize these variables to 0).

The .bss section only has data at runtime (that is, there is no data at compile time), so instead of allocating data at compile time, it reserves memory space at runtime.

 

Rodata:
ro stands for read only, that is, read-only data (const).

 


Ref:

https://www.cnblogs.com/sigmahh/archive/2009/07/03/1516474.html

https://blog.csdn.net/Xzg_2017/article/details/81510271

Aoki Fenglang. "Homemade Compiler" People's Posts and Telecommunications Press.

Fan Zhidong; Zhang Qiongsheng. "Building a Compilation System by Oneself: Compilation, Compilation and Linking" Machinery Industry Press.

Published 374 original articles · 95 praises · 260,000+ views

Guess you like

Origin blog.csdn.net/qq_35865125/article/details/105333719