tags:

views:

225

answers:

4

I'm trying to learn the details behind how the compiler works and I was wondering what the symbol B means when using nm. I tried to follow std::cout into libstdc++, but it ends with

nm -DC /usr/lib/libstdc++.so.6 | grep cout
000e8da0 B std::cout
000e9020 B std::wcout

Where is the link to the actual function and what does the B mean?

+1  A: 

That means the symbol is global and in the uninitialized data section (historically named BSS hence the 'B'). More nm info here:

http://linux.die.net/man/1/nm

Also likely available if you type "man 1 nm".

And what about the function? Well, "cout" is an object instance, not a function. Its class will have functions, mostly operator overloads in this particular case.

George Phillips
So is cout << "whatever" being instantiated as a std::cout object and then calling the std::operator<< to print it?
victor
std::cout is probably being a global object, and thus placed in the global(bss) secion. Somewhere before your programs 'main' is called there platform will run a consttructor and initialize std::cout (and other globals).
nos
A: 

From the nm manual page:

   B       The symbol is in the uninitialized data section (known as BSS).
Chris Dodd
A: 

"Uninitialized" data, the BSS section, is actually initialized by the OS loader to all-zeros. It doesn't take up space in the image on disk, since the content is known to be all-zeros - just the size is stored in the image.

Global variables are normally allocated in the BSS section. This is also the reason that global variables are generally zero-initialized.

Barry Kelly
A: 

Isn't there a possibility when dynamically loading stuff from the BSS that it does not get initialised to only 0? It seems I'm experiencing such an unorthodox behaviour.

Guillaume Yziquel