[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
llvm-svn: 308207
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 84c9074..8bab0f9 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1084,7 +1084,7 @@
}
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];