@@ -383,22 +383,26 @@ void macho::foldIdenticalSections() {
383
383
for (Defined *d : isec->symbols )
384
384
if (d->unwindEntry )
385
385
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
+ }
386
401
} else {
387
402
isec->icfEqClass [0 ] = ++icfUniqueID;
388
403
}
389
404
}
390
405
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
- }
402
406
assert (isec->icfEqClass [0 ] == 0 ); // don't overwrite a unique ID!
403
407
// Turn-on the top bit to guarantee that valid hashes have no collisions
404
408
// with the small-integer unique IDs for ICF-ineligible sections
0 commit comments