This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: V3 static data in classes vs AIX
>>>>> "Gabriel" == Gabriel Dos Reis <gdr@codesourcery.com> writes:
Gabriel> | Do weak symbols specifically allow this type of use?
Gabriel> Or is this | specific to late binding? I still do not
Gabriel> understand the differences | between the semantics of
Gabriel> COMMON and WEAK very well.
Gabriel> I would like to be educated on this issue as well :-)
Well, it's pretty complicated. COMMON symbols are a COFF concept
designed to handle Fortran and the C thing where you can do:
int i;
in multiple files. This usually accomplished through the bss section,
which is just zero-initialized storage. The storage isn't actually
present in the objects, but by the time the program runs the storage
is there, and it's arranged (either by the static or dynamic linker)
that the storage is all full of zeros. Multiple COMMON symbols with
the same name end up getting merged to the same location in the BSS --
but note that none of the instances can actually be an initialized
definition.
Weak symbols are an ELF thing, I think going back to SVR4 #pragma
weak. Originally, they meant "treat this symbol as having value zero,
unless you see a definition somewhere else". That allow this kind of
code:
#pragma weak f
extern void f();
if (&f) { /* Oh, look, someone defined `f'! */ }
I think that weakness was originally only for functions, but maybe the
same thing worked for variables, too.
COMDAT is also an ELF thing. The linker will merge multiple
definitions of COMDAT groups (think sections) with the same name.
Here, merge means "throw out all but one instance". The GNU linker
treats weak data definitions essentially like COMDAT -- which is what
we should really use on ELF systems to handle templates, now that it
exists.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com