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

Kyungwoo Lee via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 14:40:41 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()),
----------------
kyulee-com wrote:

Can it be `null`? Then `tryGetDefinedAtIsecOffset` didn't seem to check it.
Otherwise, can we make it a static case, or adding an assertion?

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


More information about the llvm-commits mailing list