[lld] [lld-macho] Add support for category names in ConcatInputSection's (PR #90850)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Fri May 3 15:26:07 PDT 2024


================
@@ -186,13 +186,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 CStringInputSection or a
+// 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);
+  if (auto *s = dyn_cast_or_null<CStringInputSection>(sym->isec()))
+    return s->getStringRefAtOffset(sym->value + r.addend);
+
+  if (isa<ConcatInputSection>(sym->isec())) {
+    auto strData = sym->isec()->data.slice(sym->value);
+    uint32_t len = strnlen((const char *)strData.data(), strData.size());
+    return StringRef((const char *)strData.data(), len);
+  }
----------------
ellishg wrote:

Thanks for resolving my nits 😄 

I noticed in the `CStringInputSection` case we use `r.addend`. Why don't we use that here? If this is not used, can we add `assert(r.addend == 0)`? I have no idea if this is possible, but I think this would happen if multiple strings were under the same label and referenced by different offsets.

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


More information about the llvm-commits mailing list