forked from OSchip/llvm-project
CodeGen: fix section names for different file formats
This changes the codegen to match the section names according to the ObjC rewriter as well as the runtime. The changes to the test are simply whitespace changes to the section attributes and names and are functionally equivalent (the whitespace is ignored by the linker). llvm-svn: 304661
This commit is contained in:
parent
39fbe3bb60
commit
13d73d53c4
|
@ -1004,6 +1004,8 @@ protected:
|
|||
const ObjCInterfaceDecl *ID,
|
||||
ObjCCommonTypesHelper &ObjCTypes);
|
||||
|
||||
std::string GetSectionName(StringRef Section, StringRef MachOAttributes);
|
||||
|
||||
public:
|
||||
/// CreateMetadataVar - Create a global variable with internal
|
||||
/// linkage for use by the Objective-C runtime.
|
||||
|
@ -4786,6 +4788,27 @@ llvm::Value *CGObjCMac::EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
|
|||
|
||||
/* *** Private Interface *** */
|
||||
|
||||
std::string CGObjCCommonMac::GetSectionName(StringRef Section,
|
||||
StringRef MachOAttributes) {
|
||||
switch (CGM.getTriple().getObjectFormat()) {
|
||||
default:
|
||||
llvm_unreachable("unexpected object file format");
|
||||
case llvm::Triple::MachO: {
|
||||
if (MachOAttributes.empty())
|
||||
return ("__DATA," + Section).str();
|
||||
return ("__DATA," + Section + "," + MachOAttributes).str();
|
||||
}
|
||||
case llvm::Triple::ELF:
|
||||
assert(Section.substr(0, 2) == "__" &&
|
||||
"expected the name to begin with __");
|
||||
return Section.substr(2).str();
|
||||
case llvm::Triple::COFF:
|
||||
assert(Section.substr(0, 2) == "__" &&
|
||||
"expected the name to begin with __");
|
||||
return ("." + Section.substr(2) + "$B").str();
|
||||
}
|
||||
}
|
||||
|
||||
/// EmitImageInfo - Emit the image info marker used to encode some module
|
||||
/// level information.
|
||||
///
|
||||
|
@ -4809,9 +4832,10 @@ enum ImageInfoFlags {
|
|||
|
||||
void CGObjCCommonMac::EmitImageInfo() {
|
||||
unsigned version = 0; // Version is unused?
|
||||
const char *Section = (ObjCABI == 1) ?
|
||||
"__OBJC, __image_info,regular" :
|
||||
"__DATA, __objc_imageinfo, regular, no_dead_strip";
|
||||
std::string Section =
|
||||
(ObjCABI == 1)
|
||||
? "__OBJC,__image_info,regular"
|
||||
: GetSectionName("__objc_imageinfo", "regular,no_dead_strip");
|
||||
|
||||
// Generate module-level named metadata to convey this information to the
|
||||
// linker and code-gen.
|
||||
|
@ -5930,17 +5954,21 @@ void CGObjCNonFragileABIMac::FinishNonFragileABIModule() {
|
|||
}
|
||||
|
||||
AddModuleClassList(DefinedClasses, "OBJC_LABEL_CLASS_$",
|
||||
"__DATA, __objc_classlist, regular, no_dead_strip");
|
||||
GetSectionName("__objc_classlist",
|
||||
"regular,no_dead_strip"));
|
||||
|
||||
AddModuleClassList(DefinedNonLazyClasses, "OBJC_LABEL_NONLAZY_CLASS_$",
|
||||
"__DATA, __objc_nlclslist, regular, no_dead_strip");
|
||||
GetSectionName("__objc_nlclslist",
|
||||
"regular,no_dead_strip"));
|
||||
|
||||
// Build list of all implemented category addresses in array
|
||||
// L_OBJC_LABEL_CATEGORY_$.
|
||||
AddModuleClassList(DefinedCategories, "OBJC_LABEL_CATEGORY_$",
|
||||
"__DATA, __objc_catlist, regular, no_dead_strip");
|
||||
GetSectionName("__objc_catlist",
|
||||
"regular,no_dead_strip"));
|
||||
AddModuleClassList(DefinedNonLazyCategories, "OBJC_LABEL_NONLAZY_CATEGORY_$",
|
||||
"__DATA, __objc_nlcatlist, regular, no_dead_strip");
|
||||
GetSectionName("__objc_nlcatlist",
|
||||
"regular,no_dead_strip"));
|
||||
|
||||
EmitImageInfo();
|
||||
}
|
||||
|
@ -6359,7 +6387,8 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF,
|
|||
llvm::GlobalValue::WeakAnyLinkage,
|
||||
Init,
|
||||
ProtocolName);
|
||||
PTGV->setSection("__DATA, __objc_protorefs, coalesced, no_dead_strip");
|
||||
PTGV->setSection(GetSectionName("__objc_protorefs",
|
||||
"coalesced,no_dead_strip"));
|
||||
PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
|
||||
PTGV->setAlignment(Align.getQuantity());
|
||||
CGM.addCompilerUsedGlobal(PTGV);
|
||||
|
@ -6818,8 +6847,8 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol(
|
|||
PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolRef));
|
||||
PTGV->setAlignment(
|
||||
CGM.getDataLayout().getABITypeAlignment(ObjCTypes.ProtocolnfABIPtrTy));
|
||||
if (CGM.getTriple().isOSBinFormatMachO())
|
||||
PTGV->setSection("__DATA, __objc_protolist, coalesced, no_dead_strip");
|
||||
PTGV->setSection(GetSectionName("__objc_protolist",
|
||||
"coalesced,no_dead_strip"));
|
||||
PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
|
||||
CGM.addCompilerUsedGlobal(PTGV);
|
||||
return Entry;
|
||||
|
@ -7015,7 +7044,7 @@ CGObjCNonFragileABIMac::EmitVTableMessageSend(CodeGenFunction &CGF,
|
|||
/*constant*/ false,
|
||||
llvm::GlobalValue::WeakAnyLinkage);
|
||||
messageRef->setVisibility(llvm::GlobalValue::HiddenVisibility);
|
||||
messageRef->setSection("__DATA, __objc_msgrefs, coalesced");
|
||||
messageRef->setSection(GetSectionName("__objc_msgrefs", "coalesced"));
|
||||
}
|
||||
|
||||
bool requiresnullCheck = false;
|
||||
|
@ -7126,7 +7155,8 @@ CGObjCNonFragileABIMac::EmitClassRefFromId(CodeGenFunction &CGF,
|
|||
false, llvm::GlobalValue::PrivateLinkage,
|
||||
ClassGV, "OBJC_CLASSLIST_REFERENCES_$_");
|
||||
Entry->setAlignment(Align.getQuantity());
|
||||
Entry->setSection("__DATA, __objc_classrefs, regular, no_dead_strip");
|
||||
Entry->setSection(GetSectionName("__objc_classrefs",
|
||||
"regular,no_dead_strip"));
|
||||
CGM.addCompilerUsedGlobal(Entry);
|
||||
}
|
||||
return CGF.Builder.CreateAlignedLoad(Entry, Align);
|
||||
|
@ -7160,7 +7190,8 @@ CGObjCNonFragileABIMac::EmitSuperClassRef(CodeGenFunction &CGF,
|
|||
false, llvm::GlobalValue::PrivateLinkage,
|
||||
ClassGV, "OBJC_CLASSLIST_SUP_REFS_$_");
|
||||
Entry->setAlignment(Align.getQuantity());
|
||||
Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
|
||||
Entry->setSection(GetSectionName("__objc_superrefs",
|
||||
"regular,no_dead_strip"));
|
||||
CGM.addCompilerUsedGlobal(Entry);
|
||||
}
|
||||
return CGF.Builder.CreateAlignedLoad(Entry, Align);
|
||||
|
@ -7182,7 +7213,8 @@ llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF,
|
|||
MetaClassGV, "OBJC_CLASSLIST_SUP_REFS_$_");
|
||||
Entry->setAlignment(Align.getQuantity());
|
||||
|
||||
Entry->setSection("__DATA, __objc_superrefs, regular, no_dead_strip");
|
||||
Entry->setSection(GetSectionName("__objc_superrefs",
|
||||
"regular,no_dead_strip"));
|
||||
CGM.addCompilerUsedGlobal(Entry);
|
||||
}
|
||||
|
||||
|
@ -7278,7 +7310,8 @@ Address CGObjCNonFragileABIMac::EmitSelectorAddr(CodeGenFunction &CGF,
|
|||
false, llvm::GlobalValue::PrivateLinkage,
|
||||
Casted, "OBJC_SELECTOR_REFERENCES_");
|
||||
Entry->setExternallyInitialized(true);
|
||||
Entry->setSection("__DATA, __objc_selrefs, literal_pointers, no_dead_strip");
|
||||
Entry->setSection(GetSectionName("__objc_selrefs",
|
||||
"literal_pointers,no_dead_strip"));
|
||||
Entry->setAlignment(Align.getQuantity());
|
||||
CGM.addCompilerUsedGlobal(Entry);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
// RUN: %clang_cc1 -triple x86_64-unknown-windows -fobjc-dispatch-method=mixed -fobjc-runtime=ios -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-COFF
|
||||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fobjc-dispatch-method=mixed -fobjc-runtime=ios -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-ELF
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-ios -fobjc-dispatch-method=mixed -fobjc-runtime=ios -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-MACHO
|
||||
|
||||
__attribute__((__objc_root_class__))
|
||||
@interface NSObject
|
||||
+ (void)load;
|
||||
+ (id)class;
|
||||
@end
|
||||
|
||||
@protocol P
|
||||
@end
|
||||
|
||||
@interface I<P> : NSObject
|
||||
+ (void)load;
|
||||
@end
|
||||
|
||||
@implementation I
|
||||
+ (void)load; { }
|
||||
@end
|
||||
|
||||
@implementation I(C)
|
||||
+ (void)load; {
|
||||
[super load];
|
||||
}
|
||||
@end
|
||||
|
||||
@interface J : NSObject
|
||||
- (void)m;
|
||||
@end
|
||||
|
||||
_Bool f(J *j) {
|
||||
[j m];
|
||||
return [I class] == @protocol(P);
|
||||
}
|
||||
|
||||
// CHECK-COFF: @"OBJC_CLASSLIST_SUP_REFS_$_" = {{.*}}, section ".objc_superrefs$B"
|
||||
// CHECK-COFF: @OBJC_SELECTOR_REFERENCES_ = {{.*}}, section ".objc_selrefs$B"
|
||||
// CHECK-COFF: @"OBJC_CLASSLIST_REFERENCES_$_" = {{.*}}, section ".objc_classrefs$B"
|
||||
// CHECK-COFF: @"\01l_objc_msgSend_fixup_class" = {{.*}}, section ".objc_msgrefs$B"
|
||||
// CHECK-COFF: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section ".objc_protolist$B"
|
||||
// CHECK-COFF: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section ".objc_protorefs$B"
|
||||
// CHECK-COFF: @"OBJC_LABEL_CLASS_$" = {{.*}}, section ".objc_classlist$B"
|
||||
// CHECK-COFF: @"OBJC_LABEL_NONLAZY_CLASS_$" = {{.*}}, section ".objc_nlclslist$B"
|
||||
// CHECK-COFF: @"OBJC_LABEL_CATEGORY_$" = {{.*}}, section ".objc_catlist$B"
|
||||
// CHECK-COFF: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = {{.*}}, section ".objc_nlcatlist$B"
|
||||
// CHECK-COFF: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !".objc_imageinfo$B"}
|
||||
|
||||
// CHECK-ELF: @"OBJC_CLASSLIST_SUP_REFS_$_" = {{.*}}, section "objc_superrefs"
|
||||
// CHECK-ELF: @OBJC_SELECTOR_REFERENCES_ = {{.*}}, section "objc_selrefs"
|
||||
// CHECK-ELF: @"OBJC_CLASSLIST_REFERENCES_$_" = {{.*}}, section "objc_classrefs"
|
||||
// CHECK-ELF: @"\01l_objc_msgSend_fixup_class" = {{.*}}, section "objc_msgrefs"
|
||||
// CHECK-ELF: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section "objc_protolist"
|
||||
// CHECK-ELF: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "objc_protorefs"
|
||||
// CHECK-ELF: @"OBJC_LABEL_CLASS_$" = {{.*}}, section "objc_classlist"
|
||||
// CHECK-ELF: @"OBJC_LABEL_NONLAZY_CLASS_$" = {{.*}}, section "objc_nlclslist"
|
||||
// CHECK-ELF: @"OBJC_LABEL_CATEGORY_$" = {{.*}}, section "objc_catlist"
|
||||
// CHECK-ELF: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = {{.*}}, section "objc_nlcatlist"
|
||||
// CHECK-ELF: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !"objc_imageinfo"}
|
||||
|
||||
// CHECK-MACHO: @"OBJC_CLASSLIST_SUP_REFS_$_" = {{.*}}, section "__DATA,__objc_superrefs,regular,no_dead_strip"
|
||||
// CHECK-MACHO: @OBJC_SELECTOR_REFERENCES_ = {{.*}}, section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip"
|
||||
// CHECK-MACHO: @"OBJC_CLASSLIST_REFERENCES_$_" = {{.*}}, section "__DATA,__objc_classrefs,regular,no_dead_strip"
|
||||
// CHECK-MACHO: @"\01l_objc_msgSend_fixup_class" = {{.*}}, section "__DATA,__objc_msgrefs,coalesced"
|
||||
// CHECK-MACHO: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section "__DATA,__objc_protolist,coalesced,no_dead_strip"
|
||||
// CHECK-MACHO: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "__DATA,__objc_protorefs,coalesced,no_dead_strip"
|
||||
// CHECK-MACHO: @"OBJC_LABEL_CLASS_$" = {{.*}}, section "__DATA,__objc_classlist,regular,no_dead_strip"
|
||||
// CHECK-MACHO: @"OBJC_LABEL_NONLAZY_CLASS_$" = {{.*}}, section "__DATA,__objc_nlclslist,regular,no_dead_strip"
|
||||
// CHECK-MACHO: @"OBJC_LABEL_CATEGORY_$" = {{.*}}, section "__DATA,__objc_catlist,regular,no_dead_strip"
|
||||
// CHECK-MACHO: @"OBJC_LABEL_NONLAZY_CATEGORY_$" = {{.*}}, section "__DATA,__objc_nlcatlist,regular,no_dead_strip"
|
||||
// CHECK-MACHO: !{{[0-9]+}} = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
|
||||
|
Loading…
Reference in New Issue