[llvm-commits] [lld] r172553 - in /lld/trunk: lib/ReaderWriter/ELF/ReaderELF.cpp test/elf/check.objtxt
Michael Spencer
bigcheesegs at gmail.com
Tue Jan 15 15:53:33 PST 2013
On Tue, Jan 15, 2013 at 3:42 PM, Nick Kledzik <kledzik at apple.com> wrote:
> But you do want content for weak symbols that are C++ out-of-line copies.
> I thought it was just weak aliases that needed this (or at least the use of
> weak aliases in the runtime sample you had).
>
> -Nick
Unless a weak symbol is the only symbol in a section, there is no way
to know that it should own the content. .gnu.linkonce solves this for
some cases.
- Michael Spencer
>
> On Jan 15, 2013, at 1:13 PM, Michael J. Spencer wrote:
>> Author: mspencer
>> Date: Tue Jan 15 15:13:02 2013
>> New Revision: 172553
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=172553&view=rev
>> Log:
>> [ELF] Never allocate content to weak symbols as they may be merged away.
>>
>> This is done by creating a new non-weak anonymous symbol and creating
>> an atom with content for that symbol. This is added after the weak symbol
>> so that they have the same address.
>>
>> Modified:
>> lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
>> lld/trunk/test/elf/check.objtxt
>>
>> Modified: lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp
>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp?rev=172553&r1=172552&r2=172553&view=diff
>> ==============================================================================
>> --- lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp (original)
>> +++ lld/trunk/lib/ReaderWriter/ELF/ReaderELF.cpp Tue Jan 15 15:13:02 2013
>> @@ -215,6 +215,22 @@
>> : (*(si + 1))->st_value - (*si)->st_value;
>> }
>>
>> +
>> + // Don't allocate content to a weak symbol, as they may be merged away.
>> + // Create an anonymous atom to hold the data.
>> + ELFDefinedAtom<ELFT> *anonAtom = nullptr;
>> + if ((*si)->getBinding() == llvm::ELF::STB_WEAK && contentSize != 0) {
>> + // Create a new non-weak ELF symbol.
>> + auto sym = new (_readerStorage.Allocate<Elf_Sym>()) Elf_Sym;
>> + *sym = **si;
>> + sym->setBinding(llvm::ELF::STB_GLOBAL);
>> + anonAtom = createDefinedAtomAndAssignRelocations(
>> + "", sectionName, sym, i.first,
>> + ArrayRef<uint8_t>(
>> + (uint8_t *)sectionContents.data() + (*si)->st_value, contentSize));
>> + contentSize = 0;
>> + }
>> +
>> ArrayRef<uint8_t> symbolData = ArrayRef<uint8_t>(
>> (uint8_t *)sectionContents.data() + (*si)->st_value, contentSize);
>>
>> @@ -223,6 +239,8 @@
>>
>> _definedAtoms._atoms.push_back(newAtom);
>> _symbolToAtomMapping.insert(std::make_pair((*si), newAtom));
>> + if (anonAtom)
>> + _definedAtoms._atoms.push_back(anonAtom);
>> }
>> }
>>
>>
>> Modified: lld/trunk/test/elf/check.objtxt
>> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/check.objtxt?rev=172553&r1=172552&r2=172553&view=diff
>> ==============================================================================
>> --- lld/trunk/test/elf/check.objtxt (original)
>> +++ lld/trunk/test/elf/check.objtxt Tue Jan 15 15:13:02 2013
>> @@ -13,9 +13,9 @@
>>
>> ELF-i386: - name: weak_func
>> ELF-i386: scope: global
>> -ELF-i386: content: [ 55, 89, E5, 83, EC, 18, C7, 04, 24, 0E, 00, 00,
>> -ELF-i386: 00, E8, FC, FF, FF, FF, C9, C3 ]
>> ELF-i386: merge: as-weak
>> +ELF-i386: content: [ 55, 89, E5, 83, EC, 18, C7, 04, 24, 0E, 00, 00,
>> +ELF-i386: 00, E8, FC, FF, FF, FF, C9, C3 ]
>>
>> ELF-i386: - name: hidden_func
>> ELF-i386: scope: hidden
>> @@ -65,9 +65,9 @@
>>
>> ELF-hexagon: - name: weak_func
>> ELF-hexagon: scope: global
>> -ELF-hexagon: content: [ 00, C0, 9D, A0, 00, 40, 00, 00, 00, C0, 00, 78,
>> -ELF-hexagon: 00, C0, 00, 5A, 1E, C0, 1E, 96 ]
>> ELF-hexagon: merge: as-weak
>> +ELF-hexagon: content: [ 00, C0, 9D, A0, 00, 40, 00, 00, 00, C0, 00, 78,
>> +ELF-hexagon: 00, C0, 00, 5A, 1E, C0, 1E, 96 ]
>>
>> ELF-hexagon: - name: hidden_func
>> ELF-hexagon: scope: hidden
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list