[C++ PATCH] Optimize C++ comdat ctors/dtors in classes without virtual bases (PR c++/3187, take 3)

Jakub Jelinek jakub@redhat.com
Tue Dec 1 21:20:00 GMT 2009


On Tue, Dec 01, 2009 at 04:03:25PM -0500, Daniel Jacobowitz wrote:
> On Mon, Nov 30, 2009 at 05:36:53PM -0500, Jakub Jelinek wrote:
> > Hi!
> > 
> > Here is the latest version of the cdtor optimization patch.
> > The comdat group name is *[CD]5* and if the dtor is virtual, deleting dtor
> > is emitted into that comdat group as well.
> > libstdc++ symbol version script has been adjusted, so that it exports
> > exactly what it used to export before this patch.
> > On x86_64-linux this patch saves 21KB of libstdc++.so's .text.
> 
> Can you explain how this patch is ABI-safe at the object (.o) level?
> 
> Suppose that some other or older compiler creates a C0 comdat group in
> first.o.  second.o references the C0 symbol.  Then suppose that GCC
> creates a C5 comdat group in third.o, and defines C0 and C1 in that
> group.  A reference to C1 will now pull in the group in third.o and
> we have two definitions of the global symbol for the C0 constructor.
> Neither can be discarded at this point.

That's why this is done only if the symbols are weak.  If you mix .o files
from different G++ versions (pre-4.5 and 4.5+), then worst case you'll
end up with some .text duplication, but as the symbols are weak, the linker
will just pick one of the definitions for the symbols.  When you don't mix
.o files from different G++ versions in one .so or executable, you on the
other side gain code size savings.

	Jakub



More information about the Gcc-patches mailing list