Skip to content

Commit 6e5ed35

Browse files
authored
[lld-macho] Fix category merging category map non-determinism (#91159)
Currently in `ObjcCategoryMerger::doMerge` and `generateCatListForNonErasedCategories` we use maps of pointers which leads to non-determinism. Switch instead to using `MapVector` which preserves determinism.
1 parent 2287f8d commit 6e5ed35

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lld/MachO/ObjC.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ class ObjcCategoryMerger {
437437
void eraseMergedCategories();
438438

439439
void generateCatListForNonErasedCategories(
440-
std::map<ConcatInputSection *, std::set<uint64_t>>
440+
MapVector<ConcatInputSection *, std::set<uint64_t>>
441441
catListToErasedOffsets);
442442
void collectSectionWriteInfoFromIsec(const InputSection *isec,
443443
InfoWriteSection &catWriteInfo);
@@ -491,7 +491,7 @@ class ObjcCategoryMerger {
491491
InfoCategoryWriter infoCategoryWriter;
492492
std::vector<ConcatInputSection *> &allInputSections;
493493
// Map of base class Symbol to list of InfoInputCategory's for it
494-
DenseMap<const Symbol *, std::vector<InfoInputCategory>> categoryMap;
494+
MapVector<const Symbol *, std::vector<InfoInputCategory>> categoryMap;
495495
// Set for tracking InputSection erased via eraseISec
496496
DenseSet<InputSection *> erasedIsecs;
497497

@@ -1104,7 +1104,7 @@ void ObjcCategoryMerger::collectAndValidateCategoriesData() {
11041104
// (not erased). For these not erased categories, we generate new __objc_catlist
11051105
// entries since the parent __objc_catlist entry will be erased
11061106
void ObjcCategoryMerger::generateCatListForNonErasedCategories(
1107-
const std::map<ConcatInputSection *, std::set<uint64_t>>
1107+
const MapVector<ConcatInputSection *, std::set<uint64_t>>
11081108
catListToErasedOffsets) {
11091109

11101110
// Go through all offsets of all __objc_catlist's that we process and if there
@@ -1171,7 +1171,7 @@ void ObjcCategoryMerger::eraseISec(ConcatInputSection *isec) {
11711171
// them.
11721172
void ObjcCategoryMerger::eraseMergedCategories() {
11731173
// Map of InputSection to a set of offsets of the categories that were merged
1174-
std::map<ConcatInputSection *, std::set<uint64_t>> catListToErasedOffsets;
1174+
MapVector<ConcatInputSection *, std::set<uint64_t>> catListToErasedOffsets;
11751175

11761176
for (auto &mapEntry : categoryMap) {
11771177
for (InfoInputCategory &catInfo : mapEntry.second) {

0 commit comments

Comments
 (0)