[PATCH] D30463: [ELF] - Reset output section size when assigning offsets.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 28 08:23:17 PST 2017


grimar created this revision.

In many places we reset Size to 0 before calling assignOffsets()
manually. Sometimes we don't do that. 
It looks we can just always do that inside.

Previous code had:

  template <class ELFT> void OutputSection::assignOffsets() {
    uint64_t Off = Size;

And tests feels fine with Off = 0. I think Off = Size make no sence.


https://reviews.llvm.org/D30463

Files:
  ELF/OutputSections.cpp
  ELF/Relocations.cpp
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1025,7 +1025,6 @@
   for (SyntheticSection *SS : Sections)
     if (SS && SS->OutSec && !SS->empty()) {
       SS->finalizeContents();
-      SS->OutSec->Size = 0;
       SS->OutSec->template assignOffsets<ELFT>();
     }
 }
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -886,7 +886,6 @@
   std::merge(OS->Sections.begin(), OS->Sections.end(), Thunks.begin(),
              Thunks.end(), std::back_inserter(Tmp), MergeCmp);
   OS->Sections = std::move(Tmp);
-  OS->Size = 0;
   OS->assignOffsets<ELFT>();
 }
 
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -121,7 +121,6 @@
 template <class ELFT> void OutputSection::finalize() {
   if ((this->Flags & SHF_LINK_ORDER) && !this->Sections.empty()) {
     std::sort(Sections.begin(), Sections.end(), compareByFilePosition<ELFT>);
-    Size = 0;
     assignOffsets<ELFT>();
 
     // We must preserve the link order dependency of sections with the
@@ -162,7 +161,7 @@
 // This function is called after we sort input sections
 // and scan relocations to setup sections' offsets.
 template <class ELFT> void OutputSection::assignOffsets() {
-  uint64_t Off = this->Size;
+  uint64_t Off = 0;
   for (InputSection *S : Sections) {
     Off = alignTo(Off, S->Alignment);
     S->OutSecOff = Off;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30463.90041.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170228/60c90ec9/attachment.bin>


More information about the llvm-commits mailing list