[lld] [lld-macho][ObjC] Implement category merging into base class (PR #92448)

via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 15:04:47 PDT 2024


================
@@ -552,6 +556,29 @@ ObjcCategoryMerger::tryGetDefinedAtIsecOffset(const ConcatInputSection *isec,
   return dyn_cast_or_null<Defined>(sym);
 }
 
+// Get the class's ro_data symbol. If getMetaRo is true, then we will return
+// the meta-class's ro_data symbol. Otherwise, we will return the class
+// (instance) ro_data symbol.
+Defined *ObjcCategoryMerger::getClassRo(const Defined *classSym,
+                                        bool getMetaRo) {
+  ConcatInputSection *isec = dyn_cast<ConcatInputSection>(classSym->isec());
+  if (!isec)
+    return nullptr;
+
+  if (!getMetaRo)
+    return tryGetDefinedAtIsecOffset(isec, classLayout.roDataOffset +
+                                               classSym->value);
+
+  Defined *metaClass = tryGetDefinedAtIsecOffset(
+      isec, classLayout.metaClassOffset + classSym->value);
+  if (!metaClass)
+    return nullptr;
+
+  return tryGetDefinedAtIsecOffset(
+      dyn_cast<ConcatInputSection>(metaClass->isec()),
----------------
alx32 wrote:

`tryGetDefinedAtIsecOffset` does check it for `null`. It does `tryGetSymbolAtIsecOffset`(which checks for `null`) + `dyn_cast_or_null` (checks for `null`).

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


More information about the llvm-commits mailing list