Skip to content

Commit

Permalink
[ELF] Use stable_sort for compareByFilePosition
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smeenai committed Jul 17, 2017
1 parent f9dc3de commit e1d7776
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lld/ELF/LinkerScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ template <class ELFT> void OutputSectionCommand::finalize() {
}

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];

Expand Down

0 comments on commit e1d7776

Please sign in to comment.