[lld] [lld-macho] Category Merger: add support for addrsig references (PR #90903)

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Sun May 5 08:42:23 PDT 2024


================
@@ -1188,6 +1200,35 @@ void ObjcCategoryMerger::eraseMergedCategories() {
                                   catLayout.instancePropsOffset);
     }
   }
+
+  removeRefsToErasedIsecs();
+}
+
+// The compiler may generate references to categories inside the addrsig
+// section. This function will erase these references.
+void ObjcCategoryMerger::removeRefsToErasedIsecs() {
+  for (InputSection *isec : inputSections) {
+    if (isec->getName() != section_names::addrSig)
+      continue;
+
+    auto removeRelocs = [this](Reloc &r) {
+      auto *isec = dyn_cast_or_null<ConcatInputSection>(
+          r.referent.dyn_cast<InputSection *>());
+      if (!isec) {
+        Defined *sym =
+            dyn_cast_or_null<Defined>(r.referent.dyn_cast<Symbol *>());
+        if (sym)
+          isec = dyn_cast<ConcatInputSection>(sym->isec());
+      }
+      if (!isec)
+        return false;
+      return erasedIsecs.count(isec) > 0;
+    };
+
+    isec->relocs.erase(
----------------
kyulee-com wrote:

I think you could replace these two operations by:
```suggestion
    llvm::erase_if(isec->relocs, removeRelocs);
```

https://github.com/llvm/llvm-project/pull/90903


More information about the llvm-commits mailing list