[lld] 9b7b21d - [lld-macho] Don't allocate memory in parallelForEach

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 11 10:32:37 PST 2022


Author: Jez Ng
Date: 2022-03-11T13:32:24-05:00
New Revision: 9b7b21d2f7cfd6784fdb7adbc022b200a60105fa

URL: https://github.com/llvm/llvm-project/commit/9b7b21d2f7cfd6784fdb7adbc022b200a60105fa
DIFF: https://github.com/llvm/llvm-project/commit/9b7b21d2f7cfd6784fdb7adbc022b200a60105fa.diff

LOG: [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

Added: 
    

Modified: 
    lld/MachO/ICF.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp
index 16ce44f21eaa2..8d3570ea9bdd6 100644
--- a/lld/MachO/ICF.cpp
+++ b/lld/MachO/ICF.cpp
@@ -383,22 +383,26 @@ void macho::foldIdenticalSections() {
       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 BumpPtrAllocator 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


        


More information about the llvm-commits mailing list