[lld] r308207 - [ELF] Use stable_sort for compareByFilePosition

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 12:42:19 PDT 2017


Author: smeenai
Date: Mon Jul 17 12:42:19 2017
New Revision: 308207

URL: http://llvm.org/viewvc/llvm-project?rev=308207&view=rev
Log:
[ELF] Use stable_sort for compareByFilePosition

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.

Differential Revision: https://reviews.llvm.org/D35473

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=308207&r1=308206&r2=308207&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Jul 17 12:42:19 2017
@@ -1084,7 +1084,7 @@ template <class ELFT> void OutputSection
       }
 
   if ((Sec->Flags & SHF_LINK_ORDER)) {
-    std::sort(Sections.begin(), Sections.end(), compareByFilePosition);
+    std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);
     for (int I = 0, N = Sections.size(); I < N; ++I)
       *ScriptSections[I] = Sections[I];
 




More information about the llvm-commits mailing list