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

via llvm-commits llvm-commits at lists.llvm.org
Thu May 2 13:56:10 PDT 2024


================
@@ -186,13 +186,24 @@ 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 (isa<CStringInputSection>(sym->isec()))
+    return cast<CStringInputSection>(sym->isec())
+        ->getStringRefAtOffset(sym->value + r.addend);
+
+  if (isa<ConcatInputSection>(sym->isec())) {
+    auto &data = sym->isec()->data;
+    const char *pDataStart = reinterpret_cast<const char *>(data.data());
+    uint32_t len = strnlen(pDataStart + sym->value, data.size() - sym->value);
+    return StringRef(pDataStart + sym->value, len);
----------------
alx32 wrote:

The `concatInputSection` can have multiple strings in it - so can't use `data.slice(sym->value);`. Need to do a `strlen` first to determine the string size. I am not sure if `sim->size` is valid and can be used, but I can check if that is preferable.

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


More information about the llvm-commits mailing list