CodeGen: be more conservative about setting section

The section names currently are MachO specific.  Only set the section on the
variables if the file format is MachO.

llvm-svn: 285126
This commit is contained in:
Saleem Abdulrasool 2016-10-25 21:43:28 +00:00
parent a49bd14843
commit 3c628af117
2 changed files with 89 additions and 29 deletions

View File

@ -2919,10 +2919,13 @@ CGObjCMac::EmitProtocolList(Twine Name,
ProtocolRefs.size()),
ProtocolRefs);
StringRef Section;
if (CGM.getTriple().isOSBinFormatMachO())
Section = "__OBJC,__cat_cls_meth,regular,no_dead_strip";
llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values);
llvm::GlobalVariable *GV =
CreateMetadataVar(Name, Init, "__OBJC,__cat_cls_meth,regular,no_dead_strip",
CGM.getPointerAlign(), false);
CreateMetadataVar(Name, Init, Section, CGM.getPointerAlign(), false);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListPtrTy);
}
@ -3028,12 +3031,13 @@ llvm::Constant *CGObjCCommonMac::EmitPropertyList(Twine Name,
Values[2] = llvm::ConstantArray::get(AT, Properties);
llvm::Constant *Init = llvm::ConstantStruct::getAnon(Values);
StringRef Section;
if (CGM.getTriple().isOSBinFormatMachO())
Section = (ObjCABI == 2) ? "__DATA, __objc_const"
: "__OBJC,__property,regular,no_dead_strip";
llvm::GlobalVariable *GV =
CreateMetadataVar(Name, Init,
(ObjCABI == 2) ? "__DATA, __objc_const" :
"__OBJC,__property,regular,no_dead_strip",
CGM.getPointerAlign(),
true);
CreateMetadataVar(Name, Init, Section, CGM.getPointerAlign(), true);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.PropertyListPtrTy);
}
@ -3049,9 +3053,12 @@ CGObjCCommonMac::EmitProtocolMethodTypes(Twine Name,
MethodTypes.size());
llvm::Constant *Init = llvm::ConstantArray::get(AT, MethodTypes);
llvm::GlobalVariable *GV = CreateMetadataVar(
Name, Init, (ObjCABI == 2) ? "__DATA, __objc_const" : StringRef(),
CGM.getPointerAlign(), true);
StringRef Section;
if (CGM.getTriple().isOSBinFormatMachO() && ObjCABI == 2)
Section = "__DATA, __objc_const";
llvm::GlobalVariable *GV =
CreateMetadataVar(Name, Init, Section, CGM.getPointerAlign(), true);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.Int8PtrPtrTy);
}
@ -5959,18 +5966,21 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer(
}
llvm::Constant *Init = llvm::ConstantStruct::get(ObjCTypes.ClassRonfABITy,
Values);
llvm::SmallString<64> ROLabel;
llvm::raw_svector_ostream(ROLabel)
<< ((flags & NonFragileABI_Class_Meta) ? "\01l_OBJC_METACLASS_RO_$_"
: "\01l_OBJC_CLASS_RO_$_")
<< ClassName;
llvm::GlobalVariable *CLASS_RO_GV =
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassRonfABITy, false,
llvm::GlobalValue::PrivateLinkage,
Init,
(flags & NonFragileABI_Class_Meta) ?
std::string("\01l_OBJC_METACLASS_RO_$_")+ClassName :
std::string("\01l_OBJC_CLASS_RO_$_")+ClassName);
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassRonfABITy, false,
llvm::GlobalValue::PrivateLinkage, Init, ROLabel);
CLASS_RO_GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassRonfABITy));
CLASS_RO_GV->setSection("__DATA, __objc_const");
if (CGM.getTriple().isOSBinFormatMachO())
CLASS_RO_GV->setSection("__DATA, __objc_const");
return CLASS_RO_GV;
}
/// BuildClassMetaData - This routine defines that to-level meta-data
@ -6002,9 +6012,10 @@ llvm::GlobalVariable *CGObjCNonFragileABIMac::BuildClassMetaData(
Values);
llvm::GlobalVariable *GV = GetClassGlobal(ClassName, Weak);
GV->setInitializer(Init);
GV->setSection("__DATA, __objc_data");
if (CGM.getTriple().isOSBinFormatMachO())
GV->setSection("__DATA, __objc_data");
GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassnfABITy));
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassnfABITy));
if (!CGM.getTriple().isOSBinFormatCOFF())
if (HiddenVisibility)
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
@ -6333,7 +6344,8 @@ void CGObjCNonFragileABIMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
ExtCatName.str());
GCATV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.CategorynfABITy));
GCATV->setSection("__DATA, __objc_const");
if (CGM.getTriple().isOSBinFormatMachO())
GCATV->setSection("__DATA, __objc_const");
CGM.addCompilerUsedGlobal(GCATV);
DefinedCategories.push_back(GCATV);
@ -6420,7 +6432,8 @@ CGObjCNonFragileABIMac::EmitMethodList(Twine Name, MethodListType MLT,
llvm::GlobalValue::PrivateLinkage, Init,
Prefix + Name);
GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection("__DATA, __objc_const");
if (CGM.getTriple().isOSBinFormatMachO())
GV->setSection("__DATA, __objc_const");
CGM.addCompilerUsedGlobal(GV);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.MethodListnfABIPtrTy);
}
@ -6476,7 +6489,8 @@ CGObjCNonFragileABIMac::EmitIvarOffsetVar(const ObjCInterfaceDecl *ID,
IvarOffsetGV->setVisibility(llvm::GlobalValue::DefaultVisibility);
}
IvarOffsetGV->setSection("__DATA, __objc_ivar");
if (CGM.getTriple().isOSBinFormatMachO())
IvarOffsetGV->setSection("__DATA, __objc_ivar");
return IvarOffsetGV;
}
@ -6552,8 +6566,8 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
Prefix + OID->getObjCRuntimeNameAsString());
GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection("__DATA, __objc_const");
if (CGM.getTriple().isOSBinFormatMachO())
GV->setSection("__DATA, __objc_const");
CGM.addCompilerUsedGlobal(GV);
return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.IvarListnfABIPtrTy);
}
@ -6777,9 +6791,9 @@ CGObjCNonFragileABIMac::EmitProtocolList(Twine Name,
GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::PrivateLinkage,
Init, Name);
GV->setSection("__DATA, __objc_const");
GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType()));
if (CGM.getTriple().isOSBinFormatMachO())
GV->setSection("__DATA, __objc_const");
CGM.addCompilerUsedGlobal(GV);
return llvm::ConstantExpr::getBitCast(GV,
ObjCTypes.ProtocolListnfABIPtrTy);
@ -7449,7 +7463,8 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
Entry->setAlignment(DL.getABITypeAlignment(ObjCTypes.EHTypeTy));
if (ForDefinition)
Entry->setSection("__DATA,__objc_const");
if (CGM.getTriple().isOSBinFormatMachO())
Entry->setSection("__DATA,__objc_const");
return Entry;
}

View File

@ -0,0 +1,45 @@
// RUN: %clang_cc1 -triple thumbv7--windows-itanium -fdeclspec -fobjc-runtime=ios -emit-llvm -o - %s -Wno-objc-root-class | FileCheck %s
@protocol Protocol
- (void) protocol_method;
@end
__declspec(dllexport)
@interface Interface<Protocol>
@property(assign) id property;
+ (void) class_method;
- (void) instance_method;
@end
@implementation Interface
+ (void) class_method {
}
- (void) protocol_method {
}
- (void) instance_method {
}
@end
@implementation Interface(Category)
- (void) category_method {
}
@end
// CHECK-NOT: @"OBJC_IVAR_$_Interface._property" = {{.*}} section "__DATA, __objc_ivar"
// CHECK-NOT: @"OBJC_CLASS_$_Interface" = {{.*}} section "__DATA, __objc_data"
// CHECK-NOT: @"OBJC_METACLASS_$_Interface" = {{.*}} section "__DATA, __objc_data"
// CHECK-NOT: @"\01l_OBJC_$_CLASS_METHODS_Interface" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_PROTOCOL_INSTANCE_METHODS_Protocol" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_PROTOCOL_METHOD_TYPES_Protocol" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_CLASS_PROTOCOLS_$_Interface" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_METACLASS_RO_$_" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_INSTANCE_METHODS_Interface" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_INSTANCE_VARIABLES_Interface" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_PROP_LIST_Interface" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_CLASS_RO_$_Interface" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_CATEGORY_INSTANCE_METHODS_Interface_$_Category" = {{.*}} section "__DATA, __objc_const"
// CHECK-NOT: @"\01l_OBJC_$_CATEGORY_Interface_$_Category" = {{.*}} section "__DATA, __objc_const"