[lld] [lld-macho] Implement ObjC category merging (-objc_category_merging) (PR #82928)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 29 02:02:01 PST 2024


================
@@ -176,13 +187,22 @@ ObjcCategoryChecker::ObjcCategoryChecker()
       roClassLayout(target->wordSize), listHeaderLayout(target->wordSize),
       methodLayout(target->wordSize) {}
 
-// \p r must point to an offset within a cstring section.
+// \p r must point to an offset within a cstring section or ConcatInputSection
 static StringRef getReferentString(const Reloc &r) {
   if (auto *isec = r.referent.dyn_cast<InputSection *>())
     return cast<CStringInputSection>(isec)->getStringRefAtOffset(r.addend);
   auto *sym = cast<Defined>(r.referent.get<Symbol *>());
-  return cast<CStringInputSection>(sym->isec)->getStringRefAtOffset(sym->value +
-                                                                    r.addend);
+  uint32_t dataOff = sym->value + r.addend;
+  if (auto *cisec = dyn_cast<ConcatInputSection>(sym->isec)) {
+    uint32_t buffSize = cisec->data.size();
+    const char *pszBuff = reinterpret_cast<const char *>(cisec->data.data());
+    assert(dataOff < buffSize);
+    uint32_t sLen = strnlen(pszBuff + dataOff, buffSize - dataOff);
----------------
alx32 wrote:

Ah, this could actually be a separate commit PR as it's a fix for the category checker. Will separate out in a separate PR and add comment to address your questions. 
What do you mean by "Can we use a separate API?". 

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


More information about the llvm-commits mailing list