[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 04:56:00 PDT 2017


jhenderson created this revision.
Herald added a subscriber: emaste.

This is an optional prerequisite to https://reviews.llvm.org/D38361. If it is not committed separately, it will be committed as part of that review.

The idea is to remove the dependency on OutSecOff when ordering SHF_LINK_ORDER sections. This is to allow no longer temporarily setting the OutSecOff field via updateOffset.


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,10 @@
   void sort(std::function<int(InputSectionBase *S)> Order);
   void sortInitFini();
   void sortCtorsDtors();
+
+private:
+  // The number of input sections assigned to this section.
+  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,7 @@
   OutputSection *BOut = LB->getParent();
   if (AOut != BOut)
     return AOut->SectionIndex < BOut->SectionIndex;
-  return LA->OutSecOff < LB->OutSecOff;
+  return LA->OutSecPos < LB->OutSecPos;
 }
 
 template <class ELFT>
Index: ELF/InputSection.h
===================================================================
--- ELF/InputSection.h
+++ ELF/InputSection.h
@@ -314,6 +314,10 @@
   // 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.
+  size_t OutSecPos = 0;
+
   static bool classof(const SectionBase *S);
 
   InputSectionBase *getRelocatedSection();


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


More information about the llvm-commits mailing list