Skip to content

Commit 2b42d20

Browse files
committed
Set dllimport on Objective C ivar offsets
This commit ensures that offsets for instance variables are marked with `dllimport` if the interface to which they belong have this attribute.
1 parent 62fec3d commit 2b42d20

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/CodeGen/CGObjCGNU.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -1699,11 +1699,18 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
16991699
llvm::Value *EmitIvarOffset(CodeGenFunction &CGF,
17001700
const ObjCInterfaceDecl *Interface,
17011701
const ObjCIvarDecl *Ivar) override {
1702-
const std::string Name = GetIVarOffsetVariableName(Ivar->getContainingInterface(), Ivar);
1702+
const ObjCInterfaceDecl *ContainingInterface =
1703+
Ivar->getContainingInterface();
1704+
const std::string Name =
1705+
GetIVarOffsetVariableName(ContainingInterface, Ivar);
17031706
llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name);
1704-
if (!IvarOffsetPointer)
1707+
if (!IvarOffsetPointer) {
17051708
IvarOffsetPointer = new llvm::GlobalVariable(TheModule, IntTy, false,
17061709
llvm::GlobalValue::ExternalLinkage, nullptr, Name);
1710+
if (Ivar->getAccessControl() != ObjCIvarDecl::Private &&
1711+
Ivar->getAccessControl() != ObjCIvarDecl::Package)
1712+
CGM.setGVProperties(IvarOffsetPointer, ContainingInterface);
1713+
}
17071714
CharUnits Align = CGM.getIntAlign();
17081715
llvm::Value *Offset =
17091716
CGF.Builder.CreateAlignedLoad(IntTy, IvarOffsetPointer, Align);

clang/test/CodeGenObjC/dllstorage.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ id f(Q *q) {
151151

152152
// CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
153153

154-
// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external global i32
154+
// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external dllimport global i32
155155

156156
int g(void) {
157157
@autoreleasepool {

0 commit comments

Comments
 (0)