Symbols in compilation time

Asked

Viewed 87 times

6

When compiling only with -c and when displaying the symbols with $nm ficheiro.o, what the symbol means C and which section is assigned to it?

I have read that it means that the symbol is common and that the date is not started, but in which cases is this symbol assigned and what is the difference to the symbol B/b?

1 answer

2


Let’s see...

Succinctly, simplistically and considering Linux, the C, the GCC, Assembly and the compilation phases:

  • Global and static data not initialized and initialized with 0 are placed in the section .BSS;
  • Data initialized with non-zero values are allocated to the section .DATA or .RODATA in the case of constants;
  • When compiling into object (using -c in GCC), the uninitialized data goes to the section COMMON - which exists in the GCC by backward compatibility. When connected (linking) to form the executable, are played in the section .BSS filled with zero as required;

Probably other compilers and Sos behave similarly but with some behavioral differences. For example, fill a data not initialized completely with zeros or even do it at runtime as needed.

Responding

Thus, given the above basis, we have the following:

  • The symbol b is assigned to local data not initialized, populated from zero by the program developer or initializer. They are placed in .BSS;
  • The symbol B is assigned to uninitialized global data, filled from zero by the program developer or initializer. They are placed on .BSS;
  • The symbol C is assigned to uninitialized data when the 'link' (linking) phase is skipped. They are placed in COMMON as they may contain other similar references;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.