[Patch] Use comdats for linkonce_odr constructors/destructors

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Oct 9 06:44:44 PDT 2014


The attached patch makes clang use comdats for linkonce_odr structors.
This matches the gcc behavior and there are two potential advantages
that I can think off

* Avoid a bit of code bloat when mixing gcc and clang compiled code
since they will have the same COMDATs.
* Avoid pain to users that developed a dependency on the gcc behavior,
but it might be a bit late for that
(http://llvm.org/devmtg/2014-04/PDFs/Talks/NickRefactoring.pdf).

I was hoping this wouldn't have a noticeable code quality impact, but
I have seen at least two issues

* Putting D0 in the D5 comdat is an ABI bug IMHO since it is never
equal to D1 or D2 and doing so with linkonce_odr can bloat the code a
bit by causing us to keep more functions then we need (keep D1/D2 if
they get inlined into D0 for example).
* Using a COMDAT for the destructors of a class bar prevents D2 from
being replaced with D2 of the base class. That means we end up with

define linkonce_odr void @_ZN3fooIiED2Ev(%struct.foo* %this)
unnamed_addr #1 comdat $_ZN3fooIiED5Ev align 2 {
entry:
  %0 = bitcast %struct.foo* %this to %struct.bar*
  tail call void @_ZN3barD2Ev(%struct.bar* %0)
  ret void
}

Instead of rauw of _ZN3fooIiED2Ev with _ZN3barD2Ev. We could teach
LLVM to do this, but we are not there yet.

So it is not clear if this is worth it having it upstream. What do you
guys think?

Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: text/x-patch
Size: 7610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141009/22f647f0/attachment.bin>


More information about the cfe-commits mailing list