The man page of nm
here: MAN NM says that
The symbol type. At least the following types are used; others are, as well, depending on the object file format. If lowercase, the symbol is usually local; if uppercase, the symbol is global (external)
And underneath it has "b" and "B" for "uninitialized data section (known as BSS)" and "d" and "D" for "initialized data section"
But I thought local variables always goto Stack/Heap and not to "Data" or "BSS" sections. Then what local variables is nm talking about?
"local" in this context means file scope.
That is:
static int local_data = 1; /* initialised local data */
static int local_bss; /* uninitialised local bss */
int global_data = 1; /* initialised global data */
int global_bss; /* uninitialised global bss */
void main (void)
{
// Some code
}
Function-scope static variables go in the data or BSS (or text) sections, depending on initialization:
void somefunc(void)
{
static char array1[256] = ""; // Goes in BSS, probably
static char array2[256] = "ABCDEF…XYZ"; // Goes in Data
static const char string[] = "Kleptomanic Hypochondriac";
// Goes in Text, probably
…
}
Similar rules apply to variables defined at file scope, with or without the static
storage class specifier — uninitialized or zero-initialized data goes in the BSS section; initialized data goes in the Data section; and constant data probably goes in the Text section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With