What are all local variables passed to the data segment / BSS?
The man page nm
here: MAN NM says that
Symbol type. At least the following types are used; others, as well, depending on the object file format. If the lowercase character is usually local; if the uppercase character is global (external)
And underneath there are "b" and "B" for "uninitialized data section (known as BSS)" and "d" and "D" for "initialized data section"
But I thought that local variables always have a stack / heap and not a Data or BSS section. Then what local variables is nm talking about?
source to share
"local" in this context means file scope.
I.e:
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
}
source to share
Static-function-scope variables go into 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 in the file scope, with or without a storage class specifier static
- uninitialized or null initialized data goes in the BSS section; initialized data goes in the "Data" section; and the constant data will probably end up in the "Text" section.
source to share