[lld] r259444 - Always initialize Out<ELFT> members.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 3 09:24:02 PST 2016


On Tue, Feb 2, 2016 at 10:15 PM, Sean Silva <chisophugis at gmail.com> wrote:

>
>
> On Mon, Feb 1, 2016 at 4:35 PM, Rui Ueyama via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: ruiu
>> Date: Mon Feb  1 18:35:49 2016
>> New Revision: 259444
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=259444&view=rev
>> Log:
>> Always initialize Out<ELFT> members.
>>
>> Instead of leave unused fields as is, set them to nullptr.
>> Currnetly this is NFC, but if you call writeResults more than
>> once, you should be able to see the difference.
>>
>
> This might be simpler if Out<ELFT> were a struct. Then you can just do
> `Out<ELFT> = OutTy<ELFT>();` to reset it in one statement. OutTy would just
> be a struct with appropriate default member initializers.
>

It needs the variable template which is a C++14 feature, no?


> -- Sean Silva
>
>
>>
>> Modified:
>>     lld/trunk/ELF/Writer.cpp
>>
>> Modified: lld/trunk/ELF/Writer.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259444&r1=259443&r2=259444&view=diff
>>
>> ==============================================================================
>> --- lld/trunk/ELF/Writer.cpp (original)
>> +++ lld/trunk/ELF/Writer.cpp Mon Feb  1 18:35:49 2016
>> @@ -114,6 +114,8 @@ template <class ELFT> void elf2::writeRe
>>    StringTableSection<ELFT> StrTab(".strtab", false);
>>    if (!Config->StripAll)
>>      Out<ELFT>::StrTab = &StrTab;
>> +  else
>> +    Out<ELFT>::StrTab = nullptr;
>>    StringTableSection<ELFT> DynStrTab(".dynstr", true);
>>    Out<ELFT>::DynStrTab = &DynStrTab;
>>    GotSection<ELFT> Got;
>> @@ -121,27 +123,37 @@ template <class ELFT> void elf2::writeRe
>>    GotPltSection<ELFT> GotPlt;
>>    if (Target->UseLazyBinding)
>>      Out<ELFT>::GotPlt = &GotPlt;
>> +  else
>> +    Out<ELFT>::GotPlt = nullptr;
>>    PltSection<ELFT> Plt;
>>    Out<ELFT>::Plt = &Plt;
>>    std::unique_ptr<SymbolTableSection<ELFT>> SymTab;
>>    if (!Config->StripAll) {
>>      SymTab.reset(new SymbolTableSection<ELFT>(*Symtab,
>> *Out<ELFT>::StrTab));
>>      Out<ELFT>::SymTab = SymTab.get();
>> +  } else {
>> +    Out<ELFT>::SymTab = nullptr;
>>    }
>>    SymbolTableSection<ELFT> DynSymTab(*Symtab, *Out<ELFT>::DynStrTab);
>>    Out<ELFT>::DynSymTab = &DynSymTab;
>>    HashTableSection<ELFT> HashTab;
>>    if (Config->SysvHash)
>>      Out<ELFT>::HashTab = &HashTab;
>> +  else
>> +    Out<ELFT>::HashTab = nullptr;
>>    GnuHashTableSection<ELFT> GnuHashTab;
>>    if (Config->GnuHash)
>>      Out<ELFT>::GnuHashTab = &GnuHashTab;
>> +  else
>> +    Out<ELFT>::GnuHashTab = nullptr;
>>    bool IsRela = shouldUseRela<ELFT>();
>>    RelocationSection<ELFT> RelaDyn(IsRela ? ".rela.dyn" : ".rel.dyn",
>> IsRela);
>>    Out<ELFT>::RelaDyn = &RelaDyn;
>>    RelocationSection<ELFT> RelaPlt(IsRela ? ".rela.plt" : ".rel.plt",
>> IsRela);
>>    if (Target->UseLazyBinding)
>>      Out<ELFT>::RelaPlt = &RelaPlt;
>> +  else
>> +    Out<ELFT>::RelaPlt = nullptr;
>>    DynamicSection<ELFT> Dynamic(*Symtab);
>>    Out<ELFT>::Dynamic = &Dynamic;
>>    EhFrameHeader<ELFT> EhFrameHdr;
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160203/3a2ed02f/attachment.html>


More information about the llvm-commits mailing list