[PATCH] D45222: ELF: Use a vector of pairs to sort sections ordered using --symbol-ordering-file.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 12:50:55 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD329106: ELF: Use a vector of pairs to sort sections ordered using --symbol-ordering… (authored by pcc, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D45222?vs=140843&id=140847#toc

Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D45222

Files:
  ELF/Writer.cpp


Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1092,21 +1092,23 @@
 sortISDBySectionOrder(InputSectionDescription *ISD,
                       const DenseMap<const InputSectionBase *, int> &Order) {
   std::vector<InputSection *> UnorderedSections;
-  std::vector<InputSection *> OrderedSections;
+  std::vector<std::pair<InputSection *, int>> OrderedSections;
   uint64_t UnorderedSize = 0;
 
   for (InputSection *IS : ISD->Sections) {
-    if (!Order.count(IS)) {
+    auto I = Order.find(IS);
+    if (I == Order.end()) {
       UnorderedSections.push_back(IS);
       UnorderedSize += IS->getSize();
       continue;
     }
-    OrderedSections.push_back(IS);
+    OrderedSections.push_back({IS, I->second});
   }
-  std::sort(OrderedSections.begin(), OrderedSections.end(),
-            [&](InputSection *A, InputSection *B) {
-              return Order.lookup(A) < Order.lookup(B);
-            });
+  std::sort(
+      OrderedSections.begin(), OrderedSections.end(),
+      [&](std::pair<InputSection *, int> A, std::pair<InputSection *, int> B) {
+        return A.second < B.second;
+      });
 
   // Find an insertion point for the ordered section list in the unordered
   // section list. On targets with limited-range branches, this is the mid-point
@@ -1147,10 +1149,12 @@
 
   std::copy(UnorderedSections.begin(),
             UnorderedSections.begin() + UnorderedInsPt, ISD->Sections.begin());
-  std::copy(OrderedSections.begin(), OrderedSections.end(),
-            ISD->Sections.begin() + UnorderedInsPt);
+  std::vector<InputSection *>::iterator SectionsPos =
+      ISD->Sections.begin() + UnorderedInsPt;
+  for (std::pair<InputSection *, int> P : OrderedSections)
+    *SectionsPos++ = P.first;
   std::copy(UnorderedSections.begin() + UnorderedInsPt, UnorderedSections.end(),
-            ISD->Sections.begin() + UnorderedInsPt + OrderedSections.size());
+            SectionsPos);
 }
 
 static void sortSection(OutputSection *Sec,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45222.140847.patch
Type: text/x-patch
Size: 2043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180403/857bcd50/attachment.bin>


More information about the llvm-commits mailing list