From: Robert Lytton Date: Tue, 18 Feb 2014 11:21:59 +0000 (+0000) Subject: XCore target: Handle common linkage X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=ade82a41570f557f993e149159ccf870b9cd3998;p=oota-llvm.git XCore target: Handle common linkage git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201563 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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