[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 06:51:33 PDT 2024
https://github.com/alx32 updated https://github.com/llvm/llvm-project/pull/90850
>From c098eb08a9306b795c273d88c18b8c42f4949434 Mon Sep 17 00:00:00 2001
From: Alex Borcan <alexborcan at fb.com>
Date: Thu, 2 May 2024 05:22:23 -0700
Subject: [PATCH] [lld-macho] Add support for category names in
ConcatInputSection's
---
lld/MachO/ObjC.cpp | 17 ++++++++++++++---
...objc-category-merging-extern-class-minimal.s | 2 +-
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp
index 95fe0c9374f150..68a8645532dff6 100644
--- a/lld/MachO/ObjC.cpp
+++ b/lld/MachO/ObjC.cpp
@@ -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);
+ }
+
+ llvm_unreachable("unknown reference section in getReferentString");
}
void ObjcCategoryChecker::parseMethods(const ConcatInputSection *methodsIsec,
diff --git a/lld/test/MachO/objc-category-merging-extern-class-minimal.s b/lld/test/MachO/objc-category-merging-extern-class-minimal.s
index ede7ef5d9c32d4..3e220ef372ca0d 100644
--- a/lld/test/MachO/objc-category-merging-extern-class-minimal.s
+++ b/lld/test/MachO/objc-category-merging-extern-class-minimal.s
@@ -118,7 +118,7 @@ __OBJC_$_CATEGORY_MyBaseClass_$_Category01:
.quad 0
.long 64 ; 0x40
.space 4
- .section __TEXT,__objc_classname,cstring_literals
+ .section __DATA,__objc_const
l_OBJC_CLASS_NAME_.1: ; @OBJC_CLASS_NAME_.1
.asciz "Category02"
.section __TEXT,__objc_methname,cstring_literals
More information about the llvm-commits
mailing list