Index: COFF/ICF.cpp =================================================================== --- COFF/ICF.cpp +++ COFF/ICF.cpp @@ -279,10 +279,9 @@ // From now on, sections in Chunks are ordered so that sections in // the same group are consecutive in the vector. - std::stable_sort(Chunks.begin(), Chunks.end(), - [](SectionChunk *A, SectionChunk *B) { - return A->Class[0] < B->Class[0]; - }); + llvm::stable_sort(Chunks, [](const SectionChunk *A, const SectionChunk *B) { + return A->Class[0] < B->Class[0]; + }); // Compare static contents and assign unique IDs for each static content. forEachClass([&](size_t Begin, size_t End) { segregate(Begin, End, true); }); Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -642,10 +642,9 @@ return 0; }; - std::stable_sort(Chunks.begin(), Chunks.end(), - [=](const Chunk *A, const Chunk *B) { - return GetPriority(A) < GetPriority(B); - }); + llvm::stable_sort(Chunks, [=](const Chunk *A, const Chunk *B) { + return GetPriority(A) < GetPriority(B); + }); } // Sort concrete section chunks from GNU import libraries. @@ -683,10 +682,9 @@ if (!PSec->Name.startswith(".idata")) continue; - std::vector &Chunks = PSec->Chunks; - if (!Chunks.empty()) + if (!PSec->Chunks.empty()) HasIdata = true; - std::stable_sort(Chunks.begin(), Chunks.end(), [&](Chunk *S, Chunk *T) { + llvm::stable_sort(PSec->Chunks, [&](Chunk *S, Chunk *T) { SectionChunk *SC1 = dyn_cast_or_null(S); SectionChunk *SC2 = dyn_cast_or_null(T); if (!SC1 || !SC2) { @@ -845,7 +843,7 @@ } // Finally, move some output sections to the end. - auto SectionOrder = [&](OutputSection *S) { + auto SectionOrder = [&](const OutputSection *S) { // Move DISCARDABLE (or non-memory-mapped) sections to the end of file because // the loader cannot handle holes. Stripping can remove other discardable ones // than .reloc, which is first of them (created early). @@ -858,10 +856,10 @@ return 1; return 0; }; - std::stable_sort(OutputSections.begin(), OutputSections.end(), - [&](OutputSection *S, OutputSection *T) { - return SectionOrder(S) < SectionOrder(T); - }); + llvm::stable_sort(OutputSections, + [&](const OutputSection *S, const OutputSection *T) { + return SectionOrder(S) < SectionOrder(T); + }); } void Writer::createMiscChunks() { @@ -1779,7 +1777,7 @@ return SAObj == SBObj && SA->getSectionNumber() < SB->getSectionNumber(); }; - std::stable_sort(Chunks.begin(), Chunks.end(), SectionChunkOrder); + llvm::stable_sort(Chunks, SectionChunkOrder); if (Config->Verbose) { for (auto &C : Chunks) { Index: ELF/AArch64ErrataFix.cpp =================================================================== --- ELF/AArch64ErrataFix.cpp +++ ELF/AArch64ErrataFix.cpp @@ -463,9 +463,9 @@ std::vector &MapSyms = KV.second; if (MapSyms.size() <= 1) continue; - std::stable_sort( - MapSyms.begin(), MapSyms.end(), - [](const Defined *A, const Defined *B) { return A->Value < B->Value; }); + llvm::stable_sort(MapSyms, [](const Defined *A, const Defined *B) { + return A->Value < B->Value; + }); MapSyms.erase( std::unique(MapSyms.begin(), MapSyms.end(), [=](const Defined *A, const Defined *B) { Index: ELF/CallGraphSort.cpp =================================================================== --- ELF/CallGraphSort.cpp +++ ELF/CallGraphSort.cpp @@ -172,8 +172,8 @@ SecToCluster[I] = &Clusters[I]; } - std::stable_sort(SortedSecs.begin(), SortedSecs.end(), [&](int A, int B) { - return Clusters[B].getDensity() < Clusters[A].getDensity(); + llvm::stable_sort(SortedSecs, [&](int A, int B) { + return Clusters[A].getDensity() > Clusters[B].getDensity(); }); for (int SI : SortedSecs) { @@ -209,10 +209,9 @@ }); // Sort by density. - std::stable_sort(Clusters.begin(), Clusters.end(), - [](const Cluster &A, const Cluster &B) { - return A.getDensity() > B.getDensity(); - }); + llvm::stable_sort(Clusters, [](const Cluster &A, const Cluster &B) { + return A.getDensity() > B.getDensity(); + }); } DenseMap CallGraphSort::run() { Index: ELF/ICF.cpp =================================================================== --- ELF/ICF.cpp +++ ELF/ICF.cpp @@ -467,10 +467,9 @@ // From now on, sections in Sections vector are ordered so that sections // in the same equivalence class are consecutive in the vector. - std::stable_sort(Sections.begin(), Sections.end(), - [](InputSection *A, InputSection *B) { - return A->Class[0] < B->Class[0]; - }); + llvm::stable_sort(Sections, [](const InputSection *A, const InputSection *B) { + return A->Class[0] < B->Class[0]; + }); // Compare static contents and assign unique IDs for each static content. forEachClass([&](size_t Begin, size_t End) { segregate(Begin, End, true); }); Index: ELF/LinkerScript.cpp =================================================================== --- ELF/LinkerScript.cpp +++ ELF/LinkerScript.cpp @@ -345,7 +345,7 @@ static void sortSections(MutableArrayRef Vec, SortSectionPolicy K) { if (K != SortSectionPolicy::Default && K != SortSectionPolicy::None) - std::stable_sort(Vec.begin(), Vec.end(), getComparator(K)); + llvm::stable_sort(Vec, getComparator(K)); } // Sort sections as instructed by SORT-family commands and --sort-section Index: ELF/MapFile.cpp =================================================================== --- ELF/MapFile.cpp +++ ELF/MapFile.cpp @@ -72,12 +72,10 @@ // Sort symbols by address. We want to print out symbols in the // order in the output file rather than the order they appeared // in the input files. - for (auto &It : Ret) { - SmallVectorImpl &V = It.second; - std::stable_sort(V.begin(), V.end(), [](Defined *A, Defined *B) { + for (auto &It : Ret) + llvm::stable_sort(It.second, [](Defined *A, Defined *B) { return A->getVA() < B->getVA(); }); - } return Ret; } Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -138,13 +138,10 @@ static void sortByOrder(MutableArrayRef In, llvm::function_ref Order) { - using Pair = std::pair; - auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; }; - - std::vector V; + std::vector> V; for (InputSection *S : In) V.push_back({Order(S), S}); - std::stable_sort(V.begin(), V.end(), Comp); + llvm::stable_sort(V, less_first()); for (size_t I = 0; I < V.size(); ++I) In[I] = V[I].second; @@ -369,7 +366,7 @@ void OutputSection::sortCtorsDtors() { assert(SectionCommands.size() == 1); auto *ISD = cast(SectionCommands[0]); - std::stable_sort(ISD->Sections.begin(), ISD->Sections.end(), compCtors); + llvm::stable_sort(ISD->Sections, compCtors); } // If an input string is in the form of "foo.N" where N is a number, Index: ELF/Relocations.cpp =================================================================== --- ELF/Relocations.cpp +++ ELF/Relocations.cpp @@ -1243,10 +1243,10 @@ // Sort relocations by offset to binary search for R_RISCV_PCREL_HI20 if (Config->EMachine == EM_RISCV) - std::stable_sort(Sec.Relocations.begin(), Sec.Relocations.end(), - [](const Relocation &LHS, const Relocation &RHS) { - return LHS.Offset < RHS.Offset; - }); + llvm::stable_sort(Sec.Relocations, + [](const Relocation &LHS, const Relocation &RHS) { + return LHS.Offset < RHS.Offset; + }); } template void elf::scanRelocations(InputSectionBase &S) { @@ -1418,10 +1418,10 @@ for (const std::pair TS : ISD->ThunkSections) if (TS.second == Pass) NewThunks.push_back(TS.first); - std::stable_sort(NewThunks.begin(), NewThunks.end(), - [](const ThunkSection *A, const ThunkSection *B) { - return A->OutSecOff < B->OutSecOff; - }); + llvm::stable_sort(NewThunks, + [](const ThunkSection *A, const ThunkSection *B) { + return A->OutSecOff < B->OutSecOff; + }); // Merge sorted vectors of Thunks and InputSections by OutSecOff std::vector Tmp; Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -472,7 +472,7 @@ auto Less = [](const FdeData &A, const FdeData &B) { return A.PcRel < B.PcRel; }; - std::stable_sort(Ret.begin(), Ret.end(), Less); + llvm::stable_sort(Ret, Less); auto Eq = [](const FdeData &A, const FdeData &B) { return A.PcRel == B.PcRel; }; @@ -1498,7 +1498,7 @@ template void RelocationSection::writeTo(uint8_t *Buf) { if (Sort) - std::stable_sort(Relocs.begin(), Relocs.end(), compRelocations); + llvm::stable_sort(Relocs, compRelocations); for (const DynamicReloc &Rel : Relocs) { encodeDynamicReloc(reinterpret_cast(Buf), Rel); @@ -1831,7 +1831,7 @@ // NB: It also sorts Symbols to meet the GNU hash table requirements. In.GnuHashTab->addSymbols(Symbols); } else if (Config->EMachine == EM_MIPS) { - std::stable_sort(Symbols.begin(), Symbols.end(), sortMipsSymbols); + llvm::stable_sort(Symbols, sortMipsSymbols); } size_t I = 0; @@ -2199,9 +2199,9 @@ Symbols.push_back({B, Ent.StrTabOffset, Hash, BucketIdx}); } - std::stable_sort( - Symbols.begin(), Symbols.end(), - [](const Entry &L, const Entry &R) { return L.BucketIdx < R.BucketIdx; }); + llvm::stable_sort(Symbols, [](const Entry &L, const Entry &R) { + return L.BucketIdx < R.BucketIdx; + }); V.erase(Mid, V.end()); for (const Entry &Ent : Symbols) @@ -3088,8 +3088,7 @@ return AOut->SectionIndex < BOut->SectionIndex; return A->OutSecOff < B->OutSecOff; }; - std::stable_sort(ExecutableSections.begin(), ExecutableSections.end(), - CompareByFilePosition); + llvm::stable_sort(ExecutableSections, CompareByFilePosition); Sentinel = ExecutableSections.back(); // Optionally merge adjacent duplicate entries. if (Config->MergeArmExidx) { Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -1280,11 +1280,11 @@ return; assert(Sec->SectionCommands.size() == 1); auto *ISD = cast(Sec->SectionCommands[0]); - std::stable_sort(ISD->Sections.begin(), ISD->Sections.end(), - [](const InputSection *A, const InputSection *B) -> bool { - return A->File->PPC64SmallCodeModelTocRelocs && - !B->File->PPC64SmallCodeModelTocRelocs; - }); + llvm::stable_sort(ISD->Sections, + [](const InputSection *A, const InputSection *B) -> bool { + return A->File->PPC64SmallCodeModelTocRelocs && + !B->File->PPC64SmallCodeModelTocRelocs; + }); return; } @@ -1453,7 +1453,7 @@ Sec->Type == SHT_ARM_EXIDX) continue; - std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition); + llvm::stable_sort(Sections, compareByFilePosition); for (int I = 0, N = Sections.size(); I < N; ++I) *ScriptSections[I] = Sections[I]; Index: lib/ReaderWriter/MachO/MachOLinkingContext.cpp =================================================================== --- lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -1014,11 +1014,10 @@ // new undefines from libraries. void MachOLinkingContext::finalizeInputFiles() { std::vector> &elements = getNodes(); - std::stable_sort(elements.begin(), elements.end(), - [](const std::unique_ptr &a, - const std::unique_ptr &b) { - return !isLibrary(a) && isLibrary(b); - }); + llvm::stable_sort(elements, [](const std::unique_ptr &a, + const std::unique_ptr &b) { + return !isLibrary(a) && isLibrary(b); + }); size_t numLibs = std::count_if(elements.begin(), elements.end(), isLibrary); elements.push_back(llvm::make_unique(numLibs)); } Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -1402,10 +1402,10 @@ // Sort in order of priority (lowest first) so that they are called // in the correct order. - std::stable_sort(InitFunctions.begin(), InitFunctions.end(), - [](const WasmInitEntry &L, const WasmInitEntry &R) { - return L.Priority < R.Priority; - }); + llvm::stable_sort(InitFunctions, + [](const WasmInitEntry &L, const WasmInitEntry &R) { + return L.Priority < R.Priority; + }); } void Writer::run() {