<div dir="ltr">It has clear ownership semantics -- the writer always owns these object. I think it is more clear on that point than before because the ownership cannot be transferred by any means now.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 3, 2015 at 9:55 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed, Jun 3, 2015 at 12:44 PM, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
> Author: ruiu<br>
> Date: Wed Jun  3 11:44:00 2015<br>
> New Revision: 238936<br>
><br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238936-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aRX7cVWrg5v3BZu72EyO0WOkp7WaxnuxRvXfAhKrzUQ&s=Ux5WGH2dJ7iYLbynFO5-VmVi5b_jHGtEC1BgeEF5_ZA&e=" target="_blank">http://llvm.org/viewvc/llvm-project?rev=238936&view=rev</a><br>
> Log:<br>
> COFF: Change OutputSections' type from vector<unique_ptr<T>> to vector<T*>.<br>
><br>
> This is mainly for readability. OutputSection objects are still owned<br>
> by the writer using SpecificBumpPtrAllocator.<br>
<br>
</span>I think clear ownership semantics are more readable than naked<br>
pointers. If this is just for readability, it seems like a step in the<br>
wrong direction for maintenance. Am I simply missing something?<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> Modified:<br>
>     lld/trunk/COFF/Writer.cpp<br>
>     lld/trunk/COFF/Writer.h<br>
><br>
> Modified: lld/trunk/COFF/Writer.cpp<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Writer.cpp-3Frev-3D238936-26r1-3D238935-26r2-3D238936-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aRX7cVWrg5v3BZu72EyO0WOkp7WaxnuxRvXfAhKrzUQ&s=WbpBfJYJtWqL3WV-3QWzdAJrhaaDftOfajQA8RGEE1I&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=238936&r1=238935&r2=238936&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/Writer.cpp (original)<br>
> +++ lld/trunk/COFF/Writer.cpp Wed Jun  3 11:44:00 2015<br>
> @@ -117,14 +117,14 @@ void Writer::createSections() {<br>
>      StringRef SectionName = P.first;<br>
>      std::vector<Chunk *> &Chunks = P.second;<br>
>      std::stable_sort(Chunks.begin(), Chunks.end(), Comp);<br>
> -    auto Sec =<br>
> -        llvm::make_unique<OutputSection>(SectionName, OutputSections.size());<br>
> +    size_t SectIdx = OutputSections.size();<br>
> +    auto Sec = new (CAlloc.Allocate()) OutputSection(SectionName, SectIdx);<br>
>      for (Chunk *C : Chunks) {<br>
> -      C->setOutputSection(Sec.get());<br>
> +      C->setOutputSection(Sec);<br>
>        Sec->addChunk(C);<br>
>        Sec->addPermissions(C->getPermissions());<br>
>      }<br>
> -    OutputSections.push_back(std::move(Sec));<br>
> +    OutputSections.push_back(Sec);<br>
>    }<br>
>  }<br>
><br>
> @@ -210,9 +210,7 @@ void Writer::createImportTables() {<br>
>  // The Windows loader doesn't seem to like empty sections,<br>
>  // so we remove them if any.<br>
>  void Writer::removeEmptySections() {<br>
> -  auto IsEmpty = [](const std::unique_ptr<OutputSection> &S) {<br>
> -    return S->getVirtualSize() == 0;<br>
> -  };<br>
> +  auto IsEmpty = [](OutputSection *S) { return S->getVirtualSize() == 0; };<br>
>    OutputSections.erase(<br>
>        std::remove_if(OutputSections.begin(), OutputSections.end(), IsEmpty),<br>
>        OutputSections.end());<br>
> @@ -225,7 +223,7 @@ void Writer::assignAddresses() {<br>
>        HeaderSize + sizeof(coff_section) * OutputSections.size(), PageSize);<br>
>    uint64_t RVA = 0x1000; // The first page is kept unmapped.<br>
>    uint64_t FileOff = SizeOfHeaders;<br>
> -  for (std::unique_ptr<OutputSection> &Sec : OutputSections) {<br>
> +  for (OutputSection *Sec : OutputSections) {<br>
>      Sec->setRVA(RVA);<br>
>      Sec->setFileOffset(FileOff);<br>
>      RVA += RoundUpToAlignment(Sec->getVirtualSize(), PageSize);<br>
> @@ -320,7 +318,7 @@ void Writer::writeHeader() {<br>
>    // Name field in the section table is 8 byte long. Longer names need<br>
>    // to be written to the string table. First, construct string table.<br>
>    std::vector<char> Strtab;<br>
> -  for (std::unique_ptr<OutputSection> &Sec : OutputSections) {<br>
> +  for (OutputSection *Sec : OutputSections) {<br>
>      StringRef Name = Sec->getName();<br>
>      if (Name.size() <= COFF::NameSize)<br>
>        continue;<br>
> @@ -330,7 +328,7 @@ void Writer::writeHeader() {<br>
>    }<br>
><br>
>    // Write section table<br>
> -  for (std::unique_ptr<OutputSection> &Sec : OutputSections) {<br>
> +  for (OutputSection *Sec : OutputSections) {<br>
>      Sec->writeHeader(Buf);<br>
>      Buf += sizeof(coff_section);<br>
>    }<br>
> @@ -365,7 +363,7 @@ std::error_code Writer::openFile(StringR<br>
>  // Write section contents to a mmap'ed file.<br>
>  void Writer::writeSections() {<br>
>    uint8_t *Buf = Buffer->getBufferStart();<br>
> -  for (std::unique_ptr<OutputSection> &Sec : OutputSections) {<br>
> +  for (OutputSection *Sec : OutputSections) {<br>
>      // Fill gaps between functions in .text with INT3 instructions<br>
>      // instead of leaving as NUL bytes (which can be interpreted as<br>
>      // ADD instructions).<br>
> @@ -377,15 +375,15 @@ void Writer::writeSections() {<br>
>  }<br>
><br>
>  OutputSection *Writer::findSection(StringRef Name) {<br>
> -  for (std::unique_ptr<OutputSection> &Sec : OutputSections)<br>
> +  for (OutputSection *Sec : OutputSections)<br>
>      if (Sec->getName() == Name)<br>
> -      return Sec.get();<br>
> +      return Sec;<br>
>    return nullptr;<br>
>  }<br>
><br>
>  uint32_t Writer::getSizeOfInitializedData() {<br>
>    uint32_t Res = 0;<br>
> -  for (std::unique_ptr<OutputSection> &S : OutputSections)<br>
> +  for (OutputSection *S : OutputSections)<br>
>      if (S->getPermissions() & IMAGE_SCN_CNT_INITIALIZED_DATA)<br>
>        Res += S->getRawSize();<br>
>    return Res;<br>
> @@ -407,15 +405,16 @@ OutputSection *Writer::createSection(Str<br>
>                        .Default(0);<br>
>    if (!Perm)<br>
>      llvm_unreachable("unknown section name");<br>
> -  auto Sec = new OutputSection(Name, OutputSections.size());<br>
> +  size_t SectIdx = OutputSections.size();<br>
> +  auto Sec = new (CAlloc.Allocate()) OutputSection(Name, SectIdx);<br>
>    Sec->addPermissions(Perm);<br>
> -  OutputSections.push_back(std::unique_ptr<OutputSection>(Sec));<br>
> +  OutputSections.push_back(Sec);<br>
>    return Sec;<br>
>  }<br>
><br>
>  void Writer::applyRelocations() {<br>
>    uint8_t *Buf = Buffer->getBufferStart();<br>
> -  for (std::unique_ptr<OutputSection> &Sec : OutputSections)<br>
> +  for (OutputSection *Sec : OutputSections)<br>
>      for (Chunk *C : Sec->getChunks())<br>
>        C->applyRelocations(Buf);<br>
>  }<br>
><br>
> Modified: lld/trunk/COFF/Writer.h<br>
> URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_COFF_Writer.h-3Frev-3D238936-26r1-3D238935-26r2-3D238936-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=aRX7cVWrg5v3BZu72EyO0WOkp7WaxnuxRvXfAhKrzUQ&s=kWL4lGraM_tyUpNXvIUCdRbTmKH4LoGuIFyJ89fVt_8&e=" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.h?rev=238936&r1=238935&r2=238936&view=diff</a><br>
> ==============================================================================<br>
> --- lld/trunk/COFF/Writer.h (original)<br>
> +++ lld/trunk/COFF/Writer.h Wed Jun  3 11:44:00 2015<br>
> @@ -92,7 +92,8 @@ private:<br>
><br>
>    SymbolTable *Symtab;<br>
>    std::unique_ptr<llvm::FileOutputBuffer> Buffer;<br>
> -  std::vector<std::unique_ptr<OutputSection>> OutputSections;<br>
> +  llvm::SpecificBumpPtrAllocator<OutputSection> CAlloc;<br>
> +  std::vector<OutputSection *> OutputSections;<br>
>    Chunk *ImportAddressTable = nullptr;<br>
>    uint32_t ImportDirectoryTableSize = 0;<br>
>    uint32_t ImportAddressTableSize = 0;<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>