[Patch][pr19848] Produce explicit comdats in clang

David Majnemer david.majnemer at gmail.com
Sat Dec 20 16:13:30 PST 2014


On Fri, Dec 19, 2014 at 5:43 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> On Fri, Dec 19, 2014 at 12:51 PM, Rafael EspĂ­ndola <
> rafael.espindola at gmail.com> wrote:
>>
>> There is quiet a bit of history behind this.
>>
>> The llvm IR until very recently had no support for comdats. This was a
>> problem when targeting C++ on ELF/COFF as just using weak linkage
>> would cause quiet a bit of dead bits to remain on the executable
>> (unless -ffunction-sections, -fdata-sections and --gc-sections were
>> used).
>>
>> To fix the problem, llvm's codegen will just assume that any weak or
>> linkonce that is not in an explicit comdat should be output in one
>> with the same name as the global.
>>
>> This unfortunately breaks cases like pr19848 where a weak symbol is
>> not expected to be part of any comdat.
>>
>> Now that we have explicit comdats in the IR, we can finally get both
>> cases right.
>>
>> This first patch just makes clang give explicit comdats to
>> GlobalValues where it is allowed to.
>>
>> A followup patch to llvm will then stop implicitly producing comdats.
>>
>
> I'm not sure this is the right direction, but if it is, this change looks
> reasonable to me.
>

I think this patch is fine, what are your reservations?


>
> Assuming we want to go in this direction, I think we should also consider
> switching from a weak linkage to a strong linkage for entities governed by
> the ODR; using weak linkage is a hack, since these symbols are really not
> weak in the usual sense.
>

Maybe but I think that can be considered separately from this change.


> That exposes a hole in our comdat support: we should have the ability to
> define a discardable comdat (which need not be emitted if none of its
> symbols are used in the current TU); a discardable comdat with an external
> function definition seems like the right representation for an inline
> function.
>

I don't think that we want to abuse linkage like that.  We really need to
sit down untangle this mess.  Before comdats, there was never a way to say
"give me a global, stick it in a COMDAT but *don't* make it weak",
COMDAT-ness and weak-ness came hand in hand.

Now we have COMDATs and the world of linkage is unchanged, I don't think
that this is a good place to be.

We really need to kill linkage and replace it with several things, each of
which individually control the behavior of the global.  Things like
@llvm.used are a hack to work around the lack of flexibility linkage has to
offer.

I'm more than happy to help out with this if we can get consensus on a
design.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141220/1dcec932/attachment.html>


More information about the cfe-commits mailing list