[lld] [lld-macho][ObjC] Implement category merging into base class (PR #92448)
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Thu May 16 14:09:54 PDT 2024
================
@@ -552,6 +556,32 @@ 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;
+
+ Defined *classRo = nullptr;
+ if (getMetaRo) {
+ Defined *metaClass = tryGetDefinedAtIsecOffset(
+ isec, classLayout.metaClassOffset + classSym->value);
+
+ classRo = metaClass ? tryGetDefinedAtIsecOffset(
+ dyn_cast<ConcatInputSection>(metaClass->isec()),
+ classLayout.roDataOffset)
+ : nullptr;
+ } else {
+ classRo = tryGetDefinedAtIsecOffset(isec, classLayout.roDataOffset +
+ classSym->value);
+ }
+
+ return classRo;
----------------
ellishg wrote:
I think this should be equivalent.
```suggestion
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()), classLayout.roDataOffset);
```
https://github.com/llvm/llvm-project/pull/92448
More information about the llvm-commits
mailing list