Question:
When compiling with only -c
and viewing symbols with $nm ficheiro.o
, what does symbol C
mean and which section is assigned to it?
I have read that it means that the symbol is common and that it is a non-starting date, but in which cases is this symbol assigned and what is the difference to the B/b
symbol?
Answer:
Let's see…
Briefly, simplistic and considering Linux , C , GCC , Assembly and compilation phases:
- Uninitialized global and static data initialized to 0 is placed in the
.BSS
section; - Initialized data with non-zero values are allocated to section
.DATA
or.RODATA
in the case of constants; - When compiling to object (using
-c
in GCC), uninitialized data goes to theCOMMON
section – which exists in GCC for backwards compatibility . When linked ( linking ) to form the executable, they are dropped into the.BSS
section padded with zeros as needed;
Probably other compilers and OSes behave similarly but with some behavior differences. For example, completely zero-filling uninitialized data or even doing so at runtime as needed.
Responding
Thus, given the basis above, we have the following:
- The
b
symbol is assigned to uninitialized local data, zero-filled by the developer or program initiator. They are placed in.BSS
; - Symbol
B
is assigned to uninitialized global data, zero-filled by the developer or program initiator. They are placed in.BSS
; - Symbol
C
is assigned to uninitialized data when skipping the 'linking' phase. They are placed inCOMMON
as they can contain other similar references;