[PATCH] D38687: [ELF] Make section order rely on explicit member

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 08:08:58 PDT 2017


jhenderson updated this revision to Diff 118206.
jhenderson added a comment.

Updated comments to make clear that the OutSecPos field is not set for thunk sections. Also made it an Optional type, to better indicate that it might not always be set, and assert if attempting to use for SHF_LINK_ORDER when not set.


https://reviews.llvm.org/D38687

Files:
  ELF/InputSection.h
  ELF/OutputSections.cpp
  ELF/OutputSections.h


Index: ELF/OutputSections.h
===================================================================
--- ELF/OutputSections.h
+++ ELF/OutputSections.h
@@ -113,6 +113,11 @@
   void sort(std::function<int(InputSectionBase *S)> Order);
   void sortInitFini();
   void sortCtorsDtors();
+
+private:
+  // The number of input sections assigned to this section excluding
+  // late-inserted sections, such as thunk sections.
+  size_t InputSectionCount = 0;
 };
 
 int getPriority(StringRef S);
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -87,6 +87,7 @@
   Live = true;
   S->Parent = this;
   this->updateAlignment(S->Alignment);
+  S->OutSecPos = InputSectionCount++;
 
   // The actual offsets will be computed by assignAddresses. For now, use
   // crude approximation so that it is at least easy for other code to know the
@@ -427,7 +428,9 @@
   OutputSection *BOut = LB->getParent();
   if (AOut != BOut)
     return AOut->SectionIndex < BOut->SectionIndex;
-  return LA->OutSecOff < LB->OutSecOff;
+  assert(LA->OutSecPos && LB->OutSecPos &&
+         "Cannot compare late-inserted section positions.");
+  return LA->OutSecPos < LB->OutSecPos;
 }
 
 template <class ELFT>
Index: ELF/InputSection.h
===================================================================
--- ELF/InputSection.h
+++ ELF/InputSection.h
@@ -314,6 +314,11 @@
   // to. The writer sets a value.
   uint64_t OutSecOff = 0;
 
+  // The order in which the section was added to its output section. This is
+  // used when ordering SHF_LINK_ORDER sections. It is not set for sections
+  // inserted late, such as thunk sections.
+  llvm::Optional<size_t> OutSecPos;
+
   static bool classof(const SectionBase *S);
 
   InputSectionBase *getRelocatedSection();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38687.118206.patch
Type: text/x-patch
Size: 1875 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171009/dcbb4d05/attachment.bin>


More information about the llvm-commits mailing list