[PATCH] Also optimize DECL_ONE_ONLY cdtors (PR c++/3187)

Jakub Jelinek jakub@redhat.com
Wed Nov 18 09:53:00 GMT 2009


On Tue, Nov 17, 2009 at 05:18:08PM -0500, Jason Merrill wrote:
> Remind me why we can't just leave them in the same COMDAT groups they  
> have now?  Is there a problem with an alias from one group to another,  
> or is the concern about one compiler choosing to alias 1 to 2 and  
> another compiler doing the reverse?

There is no such thing as alias from one section to another, alias in ELF
is just another symbol for the same thing as certain symbol, so it always
has the same section and value as the other symbol.
We used to emit
_ZN1CD1Ev symbol in .text._ZN1CD1Ev section in _ZN1CD1Ev comdat group and
_ZN1CD2Ev symbol in .text._ZN1CD2Ev section in _ZN1CD2Ev comdat group,
furthermore not all CUs emitted both.
Now, if we know both functions have the same body, we'd like to emit just
_ZN1CD2Ev and
.set    _ZN1CD1Ev,_ZN1CD2Ev
If we emit _ZN1CD2Ev in .text._ZN1CD2Ev section in _ZN1CD2Ev comdat group,
it means the _ZN1CD1Ev alias is also in .text._ZN1CD2Ev section in _ZN1CD2Ev
comdat group.  We then either don't emit _ZN1CD1Ev comdat group at all,
or emit it empty.

If we emit it empty (where empty would mean the comdat group contains
empty .text._ZN1CD1Ev section):
  a.o let be g++ 4.3 compiled object that has just _ZN1CD2Ev comdat group
  (with just _ZN1CD2Ev symbol), b.o let be g++ 4.5 compiled object with
  _ZN1CD2Ev comdat group containing _ZN1CD2Ev symbol and _ZN1CD1Ev alias to
  it and empty _ZN1CD1Ev comdat group, c.o let be g++ 4.3 compiled object
  that has just _ZN1CD1Ev comdat group (with just _ZN1CD1Ev symbol).
  g++ -o prg a.o b.o c.o would mean _ZN1CD2Ev group is picked from
  a.o (thus defines _ZN1CD2Ev symbol), _ZN1CD1Ev group is picked from
  b.o (empty section), nothing is picked from c.o.  If both
  _ZN1CD1Ev and _ZN1CD2Ev are needed, this doesn't link.

If we don't emit the second comdat group at all:
  Let a.o be as above, d.o be g++ 4.5 compiled object
  with just _ZN1CD2Ev comdat group, containing both aliases, but where
  actually only _ZN1CD1Ev symbol is needed by that object.
  g++ -o prg a.o d.o would mean _ZN1CD2Ev is taken from a.o, not d.o and
  thus _ZN1CD1Ev symbol isn't defined.

Both the above cases assume that in g++ 4.5 we always emit both aliases,
even when only one of them is needed.  But if we don't do that, it means
that we hardly ever save any .text bytes.  The only case would be when all
of CUs either don't need any of _ZN1CD1Ev/_ZN1CD2Ev, or need both of them.
That's quite unlikely in a larger program.

	Jakub



More information about the Gcc-patches mailing list