diff --git a/lib/Target/XCore/XCoreAsmPrinter.cpp b/lib/Target/XCore/XCoreAsmPrinter.cpp index 1edd33c5f02..0a1ecd55780 100644 --- a/lib/Target/XCore/XCoreAsmPrinter.cpp +++ b/lib/Target/XCore/XCoreAsmPrinter.cpp @@ -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( cast(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: diff --git a/lib/Target/XCore/XCoreTargetObjectFile.cpp b/lib/Target/XCore/XCoreTargetObjectFile.cpp index 33b719b34d2..6584ee2d13a 100644 --- a/lib/Target/XCore/XCoreTargetObjectFile.cpp +++ b/lib/Target/XCore/XCoreTargetObjectFile.cpp @@ -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; } diff --git a/test/CodeGen/XCore/linkage.ll b/test/CodeGen/XCore/linkage.ll index 7a1179b7ab6..7384fe7bcf0 100644 --- a/test/CodeGen/XCore/linkage.ll +++ b/test/CodeGen/XCore/linkage.ll @@ -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