summaryrefslogtreecommitdiff
path: root/objectivec/objc.cpp
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-07-11 10:01:52 -0700
committerMark Rowe <mark@vector35.com>2025-07-13 09:49:22 -0700
commitae91b3686853d7002f9e8b8eaf33188080f8542d (patch)
treed96af178e3ba3943f5031b9116e44c5650acaf6b /objectivec/objc.cpp
parent6592214139290634550860697116801883131153 (diff)
[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
Diffstat (limited to 'objectivec/objc.cpp')
-rw-r--r--objectivec/objc.cpp7
1 files changed, 5 insertions, 2 deletions
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);
}