Skip to content

Commit

Permalink
[lld-macho] Fix category merging category map non-determinism (llvm#9…
Browse files Browse the repository at this point in the history
…1159)

Currently in `ObjcCategoryMerger::doMerge` and
`generateCatListForNonErasedCategories` we use maps of pointers which
leads to non-determinism. Switch instead to using `MapVector` which
preserves determinism.
  • Loading branch information
alx32 authored May 6, 2024
1 parent 2287f8d commit 6e5ed35
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lld/MachO/ObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ class ObjcCategoryMerger {
void eraseMergedCategories();

void generateCatListForNonErasedCategories(
std::map<ConcatInputSection *, std::set<uint64_t>>
MapVector<ConcatInputSection *, std::set<uint64_t>>
catListToErasedOffsets);
void collectSectionWriteInfoFromIsec(const InputSection *isec,
InfoWriteSection &catWriteInfo);
Expand Down Expand Up @@ -491,7 +491,7 @@ class ObjcCategoryMerger {
InfoCategoryWriter infoCategoryWriter;
std::vector<ConcatInputSection *> &allInputSections;
// Map of base class Symbol to list of InfoInputCategory's for it
DenseMap<const Symbol *, std::vector<InfoInputCategory>> categoryMap;
MapVector<const Symbol *, std::vector<InfoInputCategory>> categoryMap;
// Set for tracking InputSection erased via eraseISec
DenseSet<InputSection *> erasedIsecs;

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

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

for (auto &mapEntry : categoryMap) {
for (InfoInputCategory &catInfo : mapEntry.second) {
Expand Down

0 comments on commit 6e5ed35

Please sign in to comment.