From ae91b3686853d7002f9e8b8eaf33188080f8542d Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Fri, 11 Jul 2025 10:01:52 -0700 Subject: [ObjC] Use the appropriate integer size for entries in __objc_ivar The `__objc_ivar` section contains [values of type `long` for all architectures except arm64, where it contains `int`][1]. This fixes problems with resolving non-fragile ivar accesses to struct field accesses on arm64 and 32-bit architectures. [1]: https://github.com/llvm/llvm-project/blob/535d6917ec3308ade866f205644b740666312342/clang/lib/CodeGen/CGObjCMac.cpp#L5628-L5629 --- objectivec/objc.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'objectivec/objc.cpp') diff --git a/objectivec/objc.cpp b/objectivec/objc.cpp index f0a6a8f3..0d82fb4f 100644 --- a/objectivec/objc.cpp +++ b/objectivec/objc.cpp @@ -1342,10 +1342,13 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader) { auto start = ivars->GetStart(); auto end = ivars->GetEnd(); - auto ivarSectionEntryTypeBuilder = new TypeBuilder(Type::IntegerType(8, false)); + // The ivar section contains entries of type `long` for for all architectures + // except arm64, which uses `int` for the ivar offset. + size_t ivarOffsetSize = m_data->GetDefaultArchitecture()->GetName() == "aarch64" ? 4 : ptrSize; + auto ivarSectionEntryTypeBuilder = new TypeBuilder(Type::IntegerType(ivarOffsetSize, false)); ivarSectionEntryTypeBuilder->SetConst(true); auto type = ivarSectionEntryTypeBuilder->Finalize(); - for (view_ptr_t i = start; i < end; i += ptrSize) + for (view_ptr_t i = start; i < end; i += ivarOffsetSize) { m_data->DefineDataVariable(i, type); } -- cgit v1.3.1