Skip to content

[lld] Use llvm::stable_sort (NFC) #140488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lld/COFF/LLDMapFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static SymbolMapTy getSectionSyms(ArrayRef<DefinedRegular *> syms) {
// Sort symbols by address.
for (auto &it : ret) {
SmallVectorImpl<DefinedRegular *> &v = it.second;
std::stable_sort(v.begin(), v.end(), [](DefinedRegular *a, DefinedRegular *b) {
llvm::stable_sort(v, [](DefinedRegular *a, DefinedRegular *b) {
return a->getRVA() < b->getRVA();
});
}
Expand Down
7 changes: 3 additions & 4 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4677,10 +4677,9 @@ createMemtagGlobalDescriptors(Ctx &ctx,

bool MemtagGlobalDescriptors::updateAllocSize(Ctx &ctx) {
size_t oldSize = getSize();
std::stable_sort(symbols.begin(), symbols.end(),
[&ctx = ctx](const Symbol *s1, const Symbol *s2) {
return s1->getVA(ctx) < s2->getVA(ctx);
});
llvm::stable_sort(symbols, [&ctx = ctx](const Symbol *s1, const Symbol *s2) {
return s1->getVA(ctx) < s2->getVA(ctx);
});
return oldSize != getSize();
}

Expand Down
24 changes: 12 additions & 12 deletions lld/wasm/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,18 +1050,18 @@ void Writer::createOutputSegments() {
}

// Sort segments by type, placing .bss last
std::stable_sort(segments.begin(), segments.end(),
[](const OutputSegment *a, const OutputSegment *b) {
auto order = [](StringRef name) {
return StringSwitch<int>(name)
.StartsWith(".tdata", 0)
.StartsWith(".rodata", 1)
.StartsWith(".data", 2)
.StartsWith(".bss", 4)
.Default(3);
};
return order(a->name) < order(b->name);
});
llvm::stable_sort(segments,
[](const OutputSegment *a, const OutputSegment *b) {
auto order = [](StringRef name) {
return StringSwitch<int>(name)
.StartsWith(".tdata", 0)
.StartsWith(".rodata", 1)
.StartsWith(".data", 2)
.StartsWith(".bss", 4)
.Default(3);
};
return order(a->name) < order(b->name);
});

for (size_t i = 0; i < segments.size(); ++i)
segments[i]->index = i;
Expand Down