What is the advantage of using the .bss section?

What is the advantage of the two sections -.data and .bss for process area variables. Why not just have it? I know what each section is used for. I am using gcc.

+6
source share
1 answer

.bss consumes "memory", but not a space inside the executable. Its sole purpose is to store zero initialized data (as you know).

.data (and related sections such as rodata) do occupy the space inside the executable and usually contain strings, integers, and possibly even whole objects.

A typical program has a lot of zero initialized data, so a significant advantage is that this data does not consume unnecessary space in the output file.

Regarding several sections *. data .... rodata / .data can be used as a hint to protect memory (prohibit overwriting .rodata, allow reading / writing to .data).

+7
source

Source: https://habr.com/ru/post/900103/


All Articles