0

could you explain what these section mean when you collect memory footprint in c? I can see .text is source code and I assume .const and .data are global data and constants(but not too sure) and what does .bss mean?

| .text    | .const    | .data     | .bss      |
CBK
  • 15
  • 3

3 Answers3

1

Some answer you can find here. That covers also the run-time managed sections heap and stack (that was the original answer).

In short (an extended):

  • .bss is for uninitialized variables declared static and with global scope. This is not actually stored in the file, but just reserved and cleared at run-time right before `main() is called.
  • .data contains explicitly initialized variables.
  • .const contains const declared objects.
  • .text is where the program code is stored. Note that is not the source code, but the compiled program code!

There is also a plethora of other sections in normal "ELF" object files which contain debugging information, etc.

For more information, read about object file formats. One of the most widely used is ELF.

Community
  • 1
  • 1
too honest for this site
  • 12,050
  • 4
  • 30
  • 52
0

.bss is/are uninitialised static variables.

// foo ends up in bss (because it is not explicitly initialised)
// it's initial value is whatever the default 'zero' value for the type is.
static int foo;
// bar ends up in .data
// (because) it is initialised with the value 42. 
static int bar = 42;
// baz ends up in .const
// (because) it is initialised with a value (22) and the object is const.
// meaning that the value cannot be allowed to change, meaning the object
// can be safely mapped to read-only memory pages (if supported).
static const int baz = 22;
// code goes in .text:
int main() { return 0; }
user268396
  • 11,576
  • 2
  • 31
  • 26
0

bss(Block Started by Symbol) stores the zero-value initialised static-allocated variables (including global and static variables). If the initialised value of a static-allocated is not 0, e.g.:

int global = 5;

Then the global will be allocated in data section.

Nan Xiao
  • 16,671
  • 18
  • 103
  • 164