<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 3, 2016 at 9:24 AM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, Feb 2, 2016 at 10:15 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Mon, Feb 1, 2016 at 4:35 PM, Rui Ueyama via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: ruiu<br>
Date: Mon Feb  1 18:35:49 2016<br>
New Revision: 259444<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259444&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=259444&view=rev</a><br>
Log:<br>
Always initialize Out<ELFT> members.<br>
<br>
Instead of leave unused fields as is, set them to nullptr.<br>
Currnetly this is NFC, but if you call writeResults more than<br>
once, you should be able to see the difference.<br></blockquote><div><br></div></span><div>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.</div></div></div></div></blockquote><div><br></div></span><div>It needs the variable template which is a C++14 feature, no?</div></div></div></div></blockquote><div><br></div><div>I believe we can do something like this to work around that:</div><div><br></div><div>template <typename ELFT><br>struct Out {</div><div>  static OutTy<ELFT> X;</div><div>}</div><div><br></div><div>In order to still be able to say `Out<ELFT>::Dynamic`, we need to add some extra members `<span class="">static</span><span class=""> DynamicSection<ELFT> *&Dynamic;` to Out.</span></div><div><br></div><div>I'm mostly concerned because it seems error-prone to duplicate the initialization of Out<ELFT> both in declaration of Out and also inside of Writer where we have to remember to reinitialize every field. Personally it seems like a less bug-prone approach to (until C++14) have the duplication be in the form of the `<span class="">static</span><span class=""> DynamicSection<ELFT> *&Dynamic;` helpers which are completely mechanical and will cause a compiler error if we forget one.</span></div><div><span class=""><br></span></div><div><span class="">In other words, the current status quo is we have information duplicated 3 times for each member of "out":</span></div><div><span class="">- `</span><span class="">static</span><span class=""> DynamicSection<ELFT> *Dynamic;` inside class Out</span></div><div><span class="">- `</span><span class="">template</span><span class=""> <</span><span class="">class</span><span class=""> ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;`</span></div><div><span class="">- (re)initialization code in Writer.cpp that hopefully doesn't forget a case.</span></div><div><span class=""><br></span></div><div><span class="">The alternative in the attachment would mean we still have 3 places, but they are all required for the program to even compile (i.e. cannot be forgotten/inconsistent):</span></div><div><span class="">- `</span><span class="">DynamicSection<ELFT> *Dynamic = </span><span class="">nullptr</span><span class="">;` as a non-static member of OutTy<ELFT></span></div><div><span class="">- `</span><span class="">static</span><span class=""> DynamicSection<ELFT> *&Dynamic;` inside Out<ELFT> as a convenience</span></div><div><span class="">- `</span><span class="">template</span><span class=""> <</span><span class="">typename</span><span class=""> ELFT> DynamicSection<ELFT> *&Out<ELFT>::Dynamic = Out<ELFT>::X.Dynamic;` to appease the compiler and initialize the static member of Out</span></div><div><span class=""><br></span></div><div><span class="">If `Out<ELFT>::X.Dynamic` (2 characters longer than `Out<ELFT>::Dynamic`) is acceptable for now, we can remove the last two duplications. But considering the frequent use of `Out<ELFT>`, it may be best to keep it shorter at the cost of the extra initialization code.</span></div>







































<div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><font color="#888888"><div>-- Sean Silva</div></font></span><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Modified:<br>
    lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259444&r1=259443&r2=259444&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259444&r1=259443&r2=259444&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Mon Feb  1 18:35:49 2016<br>
@@ -114,6 +114,8 @@ template <class ELFT> void elf2::writeRe<br>
   StringTableSection<ELFT> StrTab(".strtab", false);<br>
   if (!Config->StripAll)<br>
     Out<ELFT>::StrTab = &StrTab;<br>
+  else<br>
+    Out<ELFT>::StrTab = nullptr;<br>
   StringTableSection<ELFT> DynStrTab(".dynstr", true);<br>
   Out<ELFT>::DynStrTab = &DynStrTab;<br>
   GotSection<ELFT> Got;<br>
@@ -121,27 +123,37 @@ template <class ELFT> void elf2::writeRe<br>
   GotPltSection<ELFT> GotPlt;<br>
   if (Target->UseLazyBinding)<br>
     Out<ELFT>::GotPlt = &GotPlt;<br>
+  else<br>
+    Out<ELFT>::GotPlt = nullptr;<br>
   PltSection<ELFT> Plt;<br>
   Out<ELFT>::Plt = &Plt;<br>
   std::unique_ptr<SymbolTableSection<ELFT>> SymTab;<br>
   if (!Config->StripAll) {<br>
     SymTab.reset(new SymbolTableSection<ELFT>(*Symtab, *Out<ELFT>::StrTab));<br>
     Out<ELFT>::SymTab = SymTab.get();<br>
+  } else {<br>
+    Out<ELFT>::SymTab = nullptr;<br>
   }<br>
   SymbolTableSection<ELFT> DynSymTab(*Symtab, *Out<ELFT>::DynStrTab);<br>
   Out<ELFT>::DynSymTab = &DynSymTab;<br>
   HashTableSection<ELFT> HashTab;<br>
   if (Config->SysvHash)<br>
     Out<ELFT>::HashTab = &HashTab;<br>
+  else<br>
+    Out<ELFT>::HashTab = nullptr;<br>
   GnuHashTableSection<ELFT> GnuHashTab;<br>
   if (Config->GnuHash)<br>
     Out<ELFT>::GnuHashTab = &GnuHashTab;<br>
+  else<br>
+    Out<ELFT>::GnuHashTab = nullptr;<br>
   bool IsRela = shouldUseRela<ELFT>();<br>
   RelocationSection<ELFT> RelaDyn(IsRela ? ".rela.dyn" : ".rel.dyn", IsRela);<br>
   Out<ELFT>::RelaDyn = &RelaDyn;<br>
   RelocationSection<ELFT> RelaPlt(IsRela ? ".rela.plt" : ".rel.plt", IsRela);<br>
   if (Target->UseLazyBinding)<br>
     Out<ELFT>::RelaPlt = &RelaPlt;<br>
+  else<br>
+    Out<ELFT>::RelaPlt = nullptr;<br>
   DynamicSection<ELFT> Dynamic(*Symtab);<br>
   Out<ELFT>::Dynamic = &Dynamic;<br>
   EhFrameHeader<ELFT> EhFrameHdr;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div><br></div></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>