Skip to content

Commit 9b7b21d

Browse files
committed
[lld-macho] Don't allocate memory in parallelForEach
... since BumpPtrAllocator isn't thread-safe. Reviewed By: #lld-macho, Roger Differential Revision: https://reviews.llvm.org/D121458
1 parent f3676c3 commit 9b7b21d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

lld/MachO/ICF.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,22 +383,26 @@ void macho::foldIdenticalSections() {
383383
for (Defined *d : isec->symbols)
384384
if (d->unwindEntry)
385385
hashable.push_back(d->unwindEntry);
386+
387+
// __cfstring has embedded addends that foil ICF's hashing / equality
388+
// checks. (We can ignore embedded addends when doing ICF because the same
389+
// information gets recorded in our Reloc structs.) We therefore create a
390+
// mutable copy of the CFString and zero out the embedded addends before
391+
// performing any hashing / equality checks.
392+
if (isCfStringSection(isec) || isClassRefsSection(isec)) {
393+
// We have to do this copying serially as the BumpPtrAllocator is not
394+
// thread-safe. FIXME: Make a thread-safe allocator.
395+
MutableArrayRef<uint8_t> copy = isec->data.copy(bAlloc());
396+
for (const Reloc &r : isec->relocs)
397+
target->relocateOne(copy.data() + r.offset, r, /*va=*/0,
398+
/*relocVA=*/0);
399+
isec->data = copy;
400+
}
386401
} else {
387402
isec->icfEqClass[0] = ++icfUniqueID;
388403
}
389404
}
390405
parallelForEach(hashable, [](ConcatInputSection *isec) {
391-
// __cfstring has embedded addends that foil ICF's hashing / equality
392-
// checks. (We can ignore embedded addends when doing ICF because the same
393-
// information gets recorded in our Reloc structs.) We therefore create a
394-
// mutable copy of the CFString and zero out the embedded addends before
395-
// performing any hashing / equality checks.
396-
if (isCfStringSection(isec) || isClassRefsSection(isec)) {
397-
MutableArrayRef<uint8_t> copy = isec->data.copy(bAlloc());
398-
for (const Reloc &r : isec->relocs)
399-
target->relocateOne(copy.data() + r.offset, r, /*va=*/0, /*relocVA=*/0);
400-
isec->data = copy;
401-
}
402406
assert(isec->icfEqClass[0] == 0); // don't overwrite a unique ID!
403407
// Turn-on the top bit to guarantee that valid hashes have no collisions
404408
// with the small-integer unique IDs for ICF-ineligible sections

0 commit comments

Comments
 (0)