Skip to content

Commit ae91b36

Browse files
committed
[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
1 parent 6592214 commit ae91b36

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

objectivec/objc.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,10 +1342,13 @@ void ObjCProcessor::PostProcessObjCSections(ObjCReader* reader)
13421342
{
13431343
auto start = ivars->GetStart();
13441344
auto end = ivars->GetEnd();
1345-
auto ivarSectionEntryTypeBuilder = new TypeBuilder(Type::IntegerType(8, false));
1345+
// The ivar section contains entries of type `long` for for all architectures
1346+
// except arm64, which uses `int` for the ivar offset.
1347+
size_t ivarOffsetSize = m_data->GetDefaultArchitecture()->GetName() == "aarch64" ? 4 : ptrSize;
1348+
auto ivarSectionEntryTypeBuilder = new TypeBuilder(Type::IntegerType(ivarOffsetSize, false));
13461349
ivarSectionEntryTypeBuilder->SetConst(true);
13471350
auto type = ivarSectionEntryTypeBuilder->Finalize();
1348-
for (view_ptr_t i = start; i < end; i += ptrSize)
1351+
for (view_ptr_t i = start; i < end; i += ivarOffsetSize)
13491352
{
13501353
m_data->DefineDataVariable(i, type);
13511354
}

0 commit comments

Comments
 (0)