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

This commit is contained in:
Kazu Hirata 2025-05-19 06:20:00 -07:00 committed by GitHub
parent 325281631a
commit 91a7085faf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 17 deletions

View File

@ -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();
});
}

View File

@ -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();
}

View File

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