XCore target: Handle common linkage

llvm-svn: 201563
This commit is contained in:
Robert Lytton 2014-02-18 11:21:59 +00:00
parent 19ed0d05b8
commit 346e808ec6
3 changed files with 22 additions and 7 deletions

View File

@ -87,9 +87,9 @@ XCoreTargetStreamer &XCoreAsmPrinter::getTargetStreamer() {
}
void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV) {
assert(((GV->hasExternalLinkage() ||
GV->hasWeakLinkage()) ||
GV->hasLinkOnceLinkage()) && "Unexpected linkage");
assert( ( GV->hasExternalLinkage() || GV->hasWeakLinkage() ||
GV->hasLinkOnceLinkage() || GV->hasCommonLinkage() ) &&
"Unexpected linkage");
if (ArrayType *ATy = dyn_cast<ArrayType>(
cast<PointerType>(GV->getType())->getElementType())) {
@ -99,7 +99,8 @@ void XCoreAsmPrinter::emitArrayBound(MCSymbol *Sym, const GlobalVariable *GV) {
OutStreamer.EmitAssignment(SymGlob,
MCConstantExpr::Create(ATy->getNumElements(),
OutContext));
if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage()) {
if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
GV->hasCommonLinkage()) {
// TODO Use COMDAT groups for LinkOnceLinkage
OutStreamer.EmitSymbolAttribute(SymGlob, MCSA_Weak);
}
@ -131,11 +132,13 @@ void XCoreAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
case GlobalValue::WeakAnyLinkage:
case GlobalValue::WeakODRLinkage:
case GlobalValue::ExternalLinkage:
case GlobalValue::CommonLinkage:
emitArrayBound(GVSym, GV);
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
// TODO Use COMDAT groups for LinkOnceLinkage
if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())
if (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
GV->hasCommonLinkage())
OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Weak);
// FALL THROUGH
case GlobalValue::InternalLinkage:

View File

@ -149,13 +149,13 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
TM.getDataLayout()->getTypeAllocSize(ObjType) < CodeModelLargeSize) {
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection
: DataRelROSection;
if (Kind.isBSS()) return BSSSection;
if (Kind.isBSS() || Kind.isCommon())return BSSSection;
if (Kind.isDataRel()) return DataSection;
if (Kind.isReadOnlyWithRel()) return DataRelROSection;
} else {
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySectionLarge
: DataRelROSectionLarge;
if (Kind.isBSS()) return BSSSectionLarge;
if (Kind.isBSS() || Kind.isCommon())return BSSSectionLarge;
if (Kind.isDataRel()) return DataSectionLarge;
if (Kind.isReadOnlyWithRel()) return DataRelROSectionLarge;
}

View File

@ -25,9 +25,21 @@ define protected void @test_protected() {
; CHECK: .weak array
@array = weak global [2 x i32] zeroinitializer
; CHECK: .globl ac.globound
; CHECK: ac.globound = 2
; CHECK: .weak ac.globound
; CHECK: .globl ac
; CHECK: .weak ac
@ac = common global [2 x i32] zeroinitializer
; CHECK: .globl gd
; CHECK: .weak gd
@gd = weak global i32 0
; CHECK: .globl gc
; CHECK: .weak gc
@gc = common global i32 0
; CHECK-NOT: .hidden test_hidden_declaration
; CHECK: .weak gr