[PATCH] D121458: [lld-macho] Don't allocate memory in parallelForEach
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 11 05:27:31 PST 2022
int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
... since BumpPtrAllocator isn't thread-safe.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121458
Files:
lld/MachO/ICF.cpp
Index: lld/MachO/ICF.cpp
===================================================================
--- lld/MachO/ICF.cpp
+++ lld/MachO/ICF.cpp
@@ -383,22 +383,25 @@
for (Defined *d : isec->symbols)
if (d->unwindEntry)
hashable.push_back(d->unwindEntry);
+
+ // __cfstring has embedded addends that foil ICF's hashing / equality
+ // checks. (We can ignore embedded addends when doing ICF because the same
+ // information gets recorded in our Reloc structs.) We therefore create a
+ // mutable copy of the CFString and zero out the embedded addends before
+ // performing any hashing / equality checks.
+ if (isCfStringSection(isec) || isClassRefsSection(isec)) {
+ // We have to do this copying serially as the bump ptr allocator is not
+ // thread-safe. FIXME: Make a thread-safe allocator.
+ MutableArrayRef<uint8_t> copy = isec->data.copy(bAlloc());
+ for (const Reloc &r : isec->relocs)
+ target->relocateOne(copy.data() + r.offset, r, /*va=*/0, /*relocVA=*/0);
+ isec->data = copy;
+ }
} else {
isec->icfEqClass[0] = ++icfUniqueID;
}
}
parallelForEach(hashable, [](ConcatInputSection *isec) {
- // __cfstring has embedded addends that foil ICF's hashing / equality
- // checks. (We can ignore embedded addends when doing ICF because the same
- // information gets recorded in our Reloc structs.) We therefore create a
- // mutable copy of the CFString and zero out the embedded addends before
- // performing any hashing / equality checks.
- if (isCfStringSection(isec) || isClassRefsSection(isec)) {
- MutableArrayRef<uint8_t> copy = isec->data.copy(bAlloc());
- for (const Reloc &r : isec->relocs)
- target->relocateOne(copy.data() + r.offset, r, /*va=*/0, /*relocVA=*/0);
- isec->data = copy;
- }
assert(isec->icfEqClass[0] == 0); // don't overwrite a unique ID!
// Turn-on the top bit to guarantee that valid hashes have no collisions
// with the small-integer unique IDs for ICF-ineligible sections
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121458.414637.patch
Type: text/x-patch
Size: 2093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220311/93491c48/attachment.bin>
More information about the llvm-commits
mailing list