[patch] Add support for comdats to the gold plugin

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Aug 22 15:32:59 PDT 2014


Duh, now with the attached patch.

On 22 August 2014 18:32, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
>>> What gets things a bit more complicated is that gold only seems
>>> symbols. In particular, if A is an alias to B, it only see the symbols
>>> A and B. It can then ask us to keep symbol A but drop symbol B. What
>>> we have to do instead is to create an internal version of B and make A
>>> an alias to that.
>>>
>>
>> Why not just give B internal (or private?) linkage?
>
> Because in general, some uses might need to see it mapped. Consider
>
> $c2 = comdat any
> @v1 = weak global i32 41, comdat $c2
> @r21 = global i32* @v1
> @a21 = alias i32* @v1
>
> If @v1 gets replaced with so other @v1 in another file (is in the
> Dropped set) the correct (matching native file) semantics are that
> @r21 will point to the new position (it uses a relocation) but @a21
> should still point to a position with a value of 41 (that is all there
> there is on the object file, no relocations)
>
>> s/Droped/Dropped/
>
> Fixed.
>
>>> +static Constant *mapConstanToLocalCopy(Constant *C, ValueToValueMapTy &VM,
>>> +                                       LocalValueMaterializer *Materializer) {
>>
>> s/mapConstanToLocalCopy/mapConstantToLocalCopy/
>
> Fixed.
>
>
>>> +  ValueToValueMapTy VM;
>>> +  LocalValueMaterializer Materializer(Drop);
>>> +  for (GlobalAlias *GA : KeptAliases) {
>>> +    // Gold told us to keep GA. It is possible that a GV usied in the aliasee
>>> +    // expression is being dropped. If that is the case, that GV must be copied.
>>> +    Constant *Aliasee = GA->getAliasee();
>>> +    Constant *Replacement = mapConstanToLocalCopy(Aliasee, VM, &Materializer);
>>> +    if (Aliasee != Replacement)
>>> +      GA->setAliasee(Replacement);
>>
>> This seems funny to me.  I'm probably missing something, but why don't
>> you just remove the referenced values from `Drop` and change their
>> linkage to `Internal`?
>
> This would sometimes be a possible optimization. Hopefully the above
> example shows why it is not always valid.
>
> Cheers,
> Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: text/x-patch
Size: 10403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140822/235f5b82/attachment.bin>


More information about the llvm-commits mailing list