[PATCH] D35473: [ELF] compareByFilePosition requires stable_sort

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 00:04:26 PDT 2017


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

The comment at the top of compareByFilePosition indicates that it relies
on stable_sort to preserve the order of synthetic sections. We were
using sort instead of stable_sort, however, leading to incorrect
synthetic section ordering.


https://reviews.llvm.org/D35473

Files:
  ELF/LinkerScript.cpp


Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1084,7 +1084,8 @@
       }
 
   if ((Sec->Flags & SHF_LINK_ORDER)) {
-    std::sort(Sections.begin(), Sections.end(), compareByFilePosition);
+    // compareByFilePosition requires stable_sort (see comment in it).
+    std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);
     for (int I = 0, N = Sections.size(); I < N; ++I)
       *ScriptSections[I] = Sections[I];
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35473.106836.patch
Type: text/x-patch
Size: 541 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170717/62ccda20/attachment.bin>


More information about the llvm-commits mailing list