Assert that the name of some internal variables start with \01L or \01l.

No functionality change. This is just an intermediate patch for changing those
global variables to use private linkage.

llvm-svn: 202409
This commit is contained in:
Rafael Espindola 2014-02-27 16:26:32 +00:00
parent 8837995b52
commit 21039aac60
1 changed files with 55 additions and 47 deletions

View File

@ -2567,6 +2567,12 @@ llvm::Constant *CGObjCCommonMac::GetProtocolRef(const ObjCProtocolDecl *PD) {
return GetOrEmitProtocolRef(PD); return GetOrEmitProtocolRef(PD);
} }
static void assertPrivateName(const llvm::GlobalValue *GV) {
StringRef NameRef = GV->getName();
assert(NameRef[0] == '\01' && (NameRef[1] == 'L' || NameRef[1] == 'l'));
assert(GV->getLinkage() == llvm::GlobalValue::InternalLinkage);
}
/* /*
// Objective-C 1.0 extensions // Objective-C 1.0 extensions
struct _objc_protocol { struct _objc_protocol {
@ -2652,7 +2658,6 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) {
if (Entry) { if (Entry) {
// Already created, fix the linkage and update the initializer. // Already created, fix the linkage and update the initializer.
assert(Entry->getLinkage() == llvm::GlobalValue::InternalLinkage);
Entry->setInitializer(Init); Entry->setInitializer(Init);
} else { } else {
Entry = Entry =
@ -2666,6 +2671,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) {
Protocols[PD->getIdentifier()] = Entry; Protocols[PD->getIdentifier()] = Entry;
} }
assertPrivateName(Entry);
CGM.AddUsedGlobal(Entry); CGM.AddUsedGlobal(Entry);
return Entry; return Entry;
@ -2687,6 +2693,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocolRef(const ObjCProtocolDecl *PD) {
// FIXME: Is this necessary? Why only for protocol? // FIXME: Is this necessary? Why only for protocol?
Entry->setAlignment(4); Entry->setAlignment(4);
} }
assertPrivateName(Entry);
return Entry; return Entry;
} }
@ -3142,14 +3149,13 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
if (GV) { if (GV) {
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy && assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type."); "Forward metaclass reference has incorrect type.");
assert(GV->getLinkage() == llvm::GlobalValue::InternalLinkage);
GV->setInitializer(Init); GV->setInitializer(Init);
GV->setSection(Section); GV->setSection(Section);
GV->setAlignment(4); GV->setAlignment(4);
CGM.AddUsedGlobal(GV); CGM.AddUsedGlobal(GV);
} } else
else
GV = CreateMetadataVar(Name, Init, Section, 4, true); GV = CreateMetadataVar(Name, Init, Section, 4, true);
assertPrivateName(GV);
DefinedClasses.push_back(GV); DefinedClasses.push_back(GV);
// method definition entries must be clear for next implementation. // method definition entries must be clear for next implementation.
MethodDefinitions.clear(); MethodDefinitions.clear();
@ -3210,13 +3216,13 @@ llvm::Constant *CGObjCMac::EmitMetaClass(const ObjCImplementationDecl *ID,
if (GV) { if (GV) {
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy && assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
"Forward metaclass reference has incorrect type."); "Forward metaclass reference has incorrect type.");
assert(GV->getLinkage() == llvm::GlobalValue::InternalLinkage);
GV->setInitializer(Init); GV->setInitializer(Init);
} else { } else {
GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false, GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Name); Init, Name);
} }
assertPrivateName(GV);
GV->setSection("__OBJC,__meta_class,regular,no_dead_strip"); GV->setSection("__OBJC,__meta_class,regular,no_dead_strip");
GV->setAlignment(4); GV->setAlignment(4);
CGM.AddUsedGlobal(GV); CGM.AddUsedGlobal(GV);
@ -3235,35 +3241,29 @@ llvm::Constant *CGObjCMac::EmitMetaClassRef(const ObjCInterfaceDecl *ID) {
// Check for an existing forward reference. // Check for an existing forward reference.
// Previously, metaclass with internal linkage may have been defined. // Previously, metaclass with internal linkage may have been defined.
// pass 'true' as 2nd argument so it is returned. // pass 'true' as 2nd argument so it is returned.
if (llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true);
true)) { if (!GV)
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy && GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
"Forward metaclass reference has incorrect type."); llvm::GlobalValue::InternalLinkage, 0, Name);
return GV;
} else { assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
// Generate as an external reference to keep a consistent "Forward metaclass reference has incorrect type.");
// module. This will be patched up when we emit the metaclass. assertPrivateName(GV);
return new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false, return GV;
llvm::GlobalValue::InternalLinkage,
0,
Name);
}
} }
llvm::Value *CGObjCMac::EmitSuperClassRef(const ObjCInterfaceDecl *ID) { llvm::Value *CGObjCMac::EmitSuperClassRef(const ObjCInterfaceDecl *ID) {
std::string Name = "\01L_OBJC_CLASS_" + ID->getNameAsString(); std::string Name = "\01L_OBJC_CLASS_" + ID->getNameAsString();
llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true);
if (llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name,
true)) { if (!GV)
assert(GV->getType()->getElementType() == ObjCTypes.ClassTy && GV = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false,
"Forward class metadata reference has incorrect type."); llvm::GlobalValue::InternalLinkage, 0, Name);
return GV;
} else { assert(GV->getType()->getElementType() == ObjCTypes.ClassTy &&
return new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassTy, false, "Forward class metadata reference has incorrect type.");
llvm::GlobalValue::InternalLinkage, assertPrivateName(GV);
0, return GV;
Name);
}
} }
/* /*
@ -3436,6 +3436,7 @@ CGObjCCommonMac::CreateMetadataVar(Twine Name,
llvm::GlobalVariable *GV = llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), Ty, false, new llvm::GlobalVariable(CGM.getModule(), Ty, false,
llvm::GlobalValue::InternalLinkage, Init, Name); llvm::GlobalValue::InternalLinkage, Init, Name);
assertPrivateName(GV);
if (Section) if (Section)
GV->setSection(Section); GV->setSection(Section);
if (Align) if (Align)
@ -4998,7 +4999,7 @@ void CGObjCMac::FinishModule() {
Values[2] = llvm::Constant::getNullValue(ObjCTypes.ProtocolListPtrTy); Values[2] = llvm::Constant::getNullValue(ObjCTypes.ProtocolListPtrTy);
Values[3] = Values[4] = Values[3] = Values[4] =
llvm::Constant::getNullValue(ObjCTypes.MethodDescriptionListPtrTy); llvm::Constant::getNullValue(ObjCTypes.MethodDescriptionListPtrTy);
assert(I->second->getLinkage() == llvm::GlobalValue::InternalLinkage); assertPrivateName(I->second);
I->second->setInitializer(llvm::ConstantStruct::get(ObjCTypes.ProtocolTy, I->second->setInitializer(llvm::ConstantStruct::get(ObjCTypes.ProtocolTy,
Values)); Values));
CGM.AddUsedGlobal(I->second); CGM.AddUsedGlobal(I->second);
@ -5526,6 +5527,7 @@ AddModuleClassList(ArrayRef<llvm::GlobalValue*> Container,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Init,
SymbolName); SymbolName);
assertPrivateName(GV);
GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType())); GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection(SectionName); GV->setSection(SectionName);
CGM.AddUsedGlobal(GV); CGM.AddUsedGlobal(GV);
@ -5714,6 +5716,7 @@ llvm::GlobalVariable * CGObjCNonFragileABIMac::BuildClassRoTInitializer(
(flags & NonFragileABI_Class_Meta) ? (flags & NonFragileABI_Class_Meta) ?
std::string("\01l_OBJC_METACLASS_RO_$_")+ClassName : std::string("\01l_OBJC_METACLASS_RO_$_")+ClassName :
std::string("\01l_OBJC_CLASS_RO_$_")+ClassName); std::string("\01l_OBJC_CLASS_RO_$_")+ClassName);
assertPrivateName(CLASS_RO_GV);
CLASS_RO_GV->setAlignment( CLASS_RO_GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassRonfABITy)); CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassRonfABITy));
CLASS_RO_GV->setSection("__DATA, __objc_const"); CLASS_RO_GV->setSection("__DATA, __objc_const");
@ -6037,6 +6040,7 @@ void CGObjCNonFragileABIMac::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Init,
ExtCatName); ExtCatName);
assertPrivateName(GCATV);
GCATV->setAlignment( GCATV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.CategorynfABITy)); CGM.getDataLayout().getABITypeAlignment(ObjCTypes.CategorynfABITy));
GCATV->setSection("__DATA, __objc_const"); GCATV->setSection("__DATA, __objc_const");
@ -6097,6 +6101,7 @@ CGObjCNonFragileABIMac::EmitMethodList(Twine Name,
llvm::GlobalVariable *GV = llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::InternalLinkage, Init, Name); llvm::GlobalValue::InternalLinkage, Init, Name);
assertPrivateName(GV);
GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType())); GV->setAlignment(CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection(Section); GV->setSection(Section);
CGM.AddUsedGlobal(GV); CGM.AddUsedGlobal(GV);
@ -6215,6 +6220,7 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Init,
Prefix + OID->getName()); Prefix + OID->getName());
assertPrivateName(GV);
GV->setAlignment( GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(Init->getType())); CGM.getDataLayout().getABITypeAlignment(Init->getType()));
GV->setSection("__DATA, __objc_const"); GV->setSection("__DATA, __objc_const");
@ -6424,6 +6430,7 @@ CGObjCNonFragileABIMac::EmitProtocolList(Twine Name,
GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, GV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
Init, Name); Init, Name);
assertPrivateName(GV);
GV->setSection("__DATA, __objc_const"); GV->setSection("__DATA, __objc_const");
GV->setAlignment( GV->setAlignment(
CGM.getDataLayout().getABITypeAlignment(Init->getType())); CGM.getDataLayout().getABITypeAlignment(Init->getType()));
@ -6675,7 +6682,7 @@ llvm::Value *CGObjCNonFragileABIMac::EmitClassRefFromId(CodeGenFunction &CGF,
Entry->setSection("__DATA, __objc_classrefs, regular, no_dead_strip"); Entry->setSection("__DATA, __objc_classrefs, regular, no_dead_strip");
CGM.AddUsedGlobal(Entry); CGM.AddUsedGlobal(Entry);
} }
assertPrivateName(Entry);
return CGF.Builder.CreateLoad(Entry); return CGF.Builder.CreateLoad(Entry);
} }
@ -6709,7 +6716,7 @@ CGObjCNonFragileABIMac::EmitSuperClassRef(CodeGenFunction &CGF,
Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip"); Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
CGM.AddUsedGlobal(Entry); CGM.AddUsedGlobal(Entry);
} }
assertPrivateName(Entry);
return CGF.Builder.CreateLoad(Entry); return CGF.Builder.CreateLoad(Entry);
} }
@ -6719,23 +6726,23 @@ CGObjCNonFragileABIMac::EmitSuperClassRef(CodeGenFunction &CGF,
llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF, llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF,
const ObjCInterfaceDecl *ID) { const ObjCInterfaceDecl *ID) {
llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()]; llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()];
if (Entry) if (!Entry) {
return CGF.Builder.CreateLoad(Entry);
std::string MetaClassName(getMetaclassSymbolPrefix() + ID->getNameAsString()); std::string MetaClassName(getMetaclassSymbolPrefix() +
llvm::GlobalVariable *MetaClassGV = GetClassGlobal(MetaClassName); ID->getNameAsString());
Entry = llvm::GlobalVariable *MetaClassGV = GetClassGlobal(MetaClassName);
new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy, false, Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy,
llvm::GlobalValue::InternalLinkage, false, llvm::GlobalValue::InternalLinkage,
MetaClassGV, MetaClassGV,
"\01L_OBJC_CLASSLIST_SUP_REFS_$_"); "\01L_OBJC_CLASSLIST_SUP_REFS_$_");
Entry->setAlignment( Entry->setAlignment(
CGM.getDataLayout().getABITypeAlignment( CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ClassnfABIPtrTy));
ObjCTypes.ClassnfABIPtrTy));
Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip"); Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
CGM.AddUsedGlobal(Entry); CGM.AddUsedGlobal(Entry);
}
assertPrivateName(Entry);
return CGF.Builder.CreateLoad(Entry); return CGF.Builder.CreateLoad(Entry);
} }
@ -6819,6 +6826,7 @@ llvm::Value *CGObjCNonFragileABIMac::EmitSelector(CodeGenFunction &CGF,
Entry->setSection("__DATA, __objc_selrefs, literal_pointers, no_dead_strip"); Entry->setSection("__DATA, __objc_selrefs, literal_pointers, no_dead_strip");
CGM.AddUsedGlobal(Entry); CGM.AddUsedGlobal(Entry);
} }
assertPrivateName(Entry);
if (lval) if (lval)
return Entry; return Entry;