Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the advantage of having a .bss section?

Tags:

c

What is the benefit of having 2 sections - .data and .bss for process scope variables. Why not just have one? I know what each section is used for. I am using gcc.

like image 402
Bruce Avatar asked Oct 26 '11 04:10

Bruce


People also ask

What is the use of .bss section?

The . bss section is used by the compiler for global and static variables. It is one of the default COFF sections that is used to reserve a specified amount of space in the memory map that can later be used for storing data. It is normally uninitialized.

What information does the .bss section header hold?

In computer programming, the block starting symbol (abbreviated to . bss or bss) is the portion of an object file, executable, or assembly language code that contains statically allocated variables that are declared but have not been assigned a value yet. It is often referred to as the "bss section" or "bss segment".

What is significance of data section .BSS and text?

'text' is my code, vector table plus constants. 'data' is for initialized variables, and it counts for RAM and FLASH. The linker allocates the data in FLASH which then is copied from ROM to RAM in the startup code. 'bss' is for the uninitialized data in RAM which is initialized with zero in the startup code.

What does .data section contain?

The data section defines the data of the rowset along with any pending updates, insertions, or deletions. The data section may contain zero or more rows. It may only contain data from one rowset where the row is defined by the schema.


1 Answers

.bss consumes "memory" but not space within the executable file. Its sole purpose is to hold zero-initialized data (as you know).

.data (and related sections such as rodata) do actually consume space within the executable file, and usually holds strings, integers, and perhaps even entire objects.

There is a lot of zero-initialized data in a typical program, so having that data not consume extra space in the output file is a significant bonus.

As for the multiple .*data sections... .rodata/.data can be used as a hint for memory protection (disallow overwriting .rodata, allow read/write to .data).

like image 81
Matthew Iselin Avatar answered Oct 14 '22 03:10

Matthew Iselin