[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:59:40 PST 2022


int3 updated this revision to Diff 414641.
int3 added a comment.

format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121458/new/

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,26 @@
       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.414641.patch
Type: text/x-patch
Size: 2122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220311/4b35fc7d/attachment.bin>


More information about the llvm-commits mailing list