[llvm-commits] [llvm] r93838 - in /llvm/trunk: include/llvm/MC/MCAsmInfo.h include/llvm/Target/TargetLoweringObjectFile.h lib/MC/MCAsmInfo.cpp lib/MC/MCAsmInfoDarwin.cpp lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp lib/Target/TargetLoweringObjectFile.cpp lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

Chris Lattner sabre at nondot.org
Mon Jan 18 18:09:44 PST 2010


Author: lattner
Date: Mon Jan 18 20:09:44 2010
New Revision: 93838

URL: http://llvm.org/viewvc/llvm-project?rev=93838&view=rev
Log:
Cleanup handling of .zerofill on darwin:

1. TargetLoweringObjectFileMachO should decide if something
   goes in zerofill instead of having every target do it.
2. TargetLoweringObjectFileMachO should assign said symbols to
   the right MCSection, the asmprinters should just emit to the
   right section.
3. Since all zerofill stuff goes through mcstreamer anymore,
   MAI can have a bool "haszerofill" instead of having the textual
   directive to emit.


Modified:
    llvm/trunk/include/llvm/MC/MCAsmInfo.h
    llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
    llvm/trunk/lib/MC/MCAsmInfo.cpp
    llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp
    llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
    llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
    llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
    llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

Modified: llvm/trunk/include/llvm/MC/MCAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmInfo.h Mon Jan 18 20:09:44 2010
@@ -29,15 +29,15 @@
     // Properties to be set by the target writer, used to configure asm printer.
     //
 
-    /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
-    /// section on this target.  Null if this target doesn't support zerofill.
-    const char *ZeroFillDirective;           // Default is null.
-
     /// NonexecutableStackDirective - Directive for declaring to the
     /// linker and beyond that the emitted code does not require stack
     /// memory to be executable.
     const char *NonexecutableStackDirective; // Default is null.
 
+    /// HasMachoZeroFillDirective - True if this is a MachO target that supports
+    /// the macho-specific .zerofill directive for emitting BSS Symbols.
+    bool HasMachoZeroFillDirective;           // Default is false.
+    
     /// NeedsSet - True if target asm treats expressions in data directives
     /// as linktime-relocatable.  For assembly-time computation, we need to
     /// use a .set.  Thus:
@@ -313,10 +313,7 @@
 
     // Accessors.
     //
-    const char *getZeroFillDirective() const {
-      return ZeroFillDirective;
-    }
-    bool hasZeroFillDirective() const { return ZeroFillDirective != 0; }
+    bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
     
     const char *getNonexecutableStackDirective() const {
       return NonexecutableStackDirective;

Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Mon Jan 18 20:09:44 2010
@@ -258,6 +258,7 @@
   const MCSection *ConstDataCoalSection;
   const MCSection *ConstDataSection;
   const MCSection *DataCoalSection;
+  const MCSection *DataCommonSection;
   const MCSection *FourByteConstantSection;
   const MCSection *EightByteConstantSection;
   const MCSection *SixteenByteConstantSection;
@@ -312,6 +313,12 @@
     return ConstTextCoalSection;
   }
   
+  /// getDataCommonSection - Return the "__DATA,__common" section we put
+  /// zerofill (aka bss) data into.
+  const MCSection *getDataCommonSection() const {
+    return DataCommonSection;
+  }
+  
   /// getLazySymbolPointerSection - Return the section corresponding to
   /// the .lazy_symbol_pointer directive.
   const MCSection *getLazySymbolPointerSection() const {

Modified: llvm/trunk/lib/MC/MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfo.cpp?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfo.cpp Mon Jan 18 20:09:44 2010
@@ -19,7 +19,7 @@
 using namespace llvm;
 
 MCAsmInfo::MCAsmInfo() {
-  ZeroFillDirective = 0;
+  HasMachoZeroFillDirective = false;
   NonexecutableStackDirective = 0;
   NeedsSet = false;
   MaxInstLength = 4;

Modified: llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp Mon Jan 18 20:09:44 2010
@@ -35,7 +35,7 @@
   HiddenDirective = "\t.private_extern ";
   LCOMMDirective = "\t.lcomm\t";
   ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
-  ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
+  HasMachoZeroFillDirective = true;  // Uses .zerofill
   SetDirective = "\t.set";
   ProtectedDirective = "\t.globl\t";
   HasDotTypeDotSizeDirective = false;

Modified: llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp Mon Jan 18 20:09:44 2010
@@ -1196,71 +1196,76 @@
   if (Subtarget->isTargetELF())
     O << "\t.type " << *GVarSym << ",%object\n";
 
+  SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
   const MCSection *TheSection =
-    getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
+    getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
   OutStreamer.SwitchSection(TheSection);
 
+  // Handle the zerofill directive on darwin, which is a special form of BSS
+  // emission.
+  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective()) {
+    TargetLoweringObjectFileMachO &TLOFMacho = 
+    static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
+    if (TheSection == TLOFMacho.getDataCommonSection()) {
+      // .globl _foo
+      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+      // .zerofill __DATA, __common, _foo, 400, 5
+      OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
+      return;
+    }
+  }
+  
   // FIXME: get this stuff from section kind flags.
   if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal() &&
       // Don't put things that should go in the cstring section into "comm".
-      !TheSection->getKind().isMergeableCString()) {
-    if (GVar->hasExternalLinkage()) {
-      if (const char *Directive = MAI->getZeroFillDirective()) {
-        O << "\t.globl\t" << *GVarSym << "\n";
-        O << Directive << "__DATA, __common, " << *GVarSym
-          << ", " << Size << ", " << Align << "\n";
-        return;
-      }
-    }
+      !TheSection->getKind().isMergeableCString() &&
+      (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
+    if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-    if (GVar->hasLocalLinkage() || GVar->isWeakForLinker()) {
-      if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
-
-      if (isDarwin) {
-        if (GVar->hasLocalLinkage()) {
-          O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size
-            << ',' << Align;
-        } else if (GVar->hasCommonLinkage()) {
-          O << MAI->getCOMMDirective() << *GVarSym << ',' << Size
-            << ',' << Align;
-        } else {
-          OutStreamer.SwitchSection(TheSection);
-          O << "\t.globl " << *GVarSym << '\n' << MAI->getWeakDefDirective();
-          O << *GVarSym << '\n';
-          EmitAlignment(Align, GVar);
-          O << *GVarSym << ":";
-          if (VerboseAsm) {
-            O.PadToColumn(MAI->getCommentColumn());
-            O << MAI->getCommentString() << ' ';
-            WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
-          }
-          O << '\n';
-          EmitGlobalConstant(C);
-          return;
-        }
-      } else if (MAI->getLCOMMDirective() != NULL) {
-        if (GVar->hasLocalLinkage()) {
-          O << MAI->getLCOMMDirective() << *GVarSym << "," << Size;
-        } else {
-          O << MAI->getCOMMDirective() << *GVarSym << "," << Size;
-          if (MAI->getCOMMDirectiveTakesAlignment())
-            O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
+    if (isDarwin) {
+      if (GVar->hasLocalLinkage()) {
+        O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size
+          << ',' << Align;
+      } else if (GVar->hasCommonLinkage()) {
+        O << MAI->getCOMMDirective() << *GVarSym << ',' << Size
+          << ',' << Align;
+      } else {
+        OutStreamer.SwitchSection(TheSection);
+        O << "\t.globl " << *GVarSym << '\n' << MAI->getWeakDefDirective();
+        O << *GVarSym << '\n';
+        EmitAlignment(Align, GVar);
+        O << *GVarSym << ":";
+        if (VerboseAsm) {
+          O.PadToColumn(MAI->getCommentColumn());
+          O << MAI->getCommentString() << ' ';
+          WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
         }
+        O << '\n';
+        EmitGlobalConstant(C);
+        return;
+      }
+    } else if (MAI->getLCOMMDirective() != NULL) {
+      if (GVar->hasLocalLinkage()) {
+        O << MAI->getLCOMMDirective() << *GVarSym << "," << Size;
       } else {
-        if (GVar->hasLocalLinkage())
-          O << "\t.local\t" << *GVarSym << '\n';
         O << MAI->getCOMMDirective() << *GVarSym << "," << Size;
         if (MAI->getCOMMDirectiveTakesAlignment())
-          O << "," << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
-      }
-      if (VerboseAsm) {
-        O.PadToColumn(MAI->getCommentColumn());
-        O << MAI->getCommentString() << ' ';
-        WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
+          O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
       }
-      O << "\n";
-      return;
+    } else {
+      if (GVar->hasLocalLinkage())
+        O << "\t.local\t" << *GVarSym << '\n';
+      O << MAI->getCOMMDirective() << *GVarSym << "," << Size;
+      if (MAI->getCOMMDirectiveTakesAlignment())
+        O << "," << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
     }
+    if (VerboseAsm) {
+      O.PadToColumn(MAI->getCommentColumn());
+      O << MAI->getCommentString() << ' ';
+      WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
+    }
+    O << "\n";
+    return;
   }
 
   switch (GVar->getLinkage()) {

Modified: llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Mon Jan 18 20:09:44 2010
@@ -721,25 +721,25 @@
       !GVar->hasSection() &&
       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
        GVar->isWeakForLinker())) {
-      if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
+    if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-      if (GVar->hasExternalLinkage()) {
-        O << "\t.global " << *GVarSym << '\n';
-        O << "\t.type " << *GVarSym << ", @object\n";
-        O << *GVarSym << ":\n";
-        O << "\t.zero " << Size << '\n';
-      } else if (GVar->hasLocalLinkage()) {
-        O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size;
-      } else {
-        O << ".comm " << *GVarSym << ',' << Size;
-      }
-      if (VerboseAsm) {
-        O << "\t\t" << MAI->getCommentString() << " '";
-        WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
-        O << "'";
-      }
-      O << '\n';
-      return;
+    if (GVar->hasExternalLinkage()) {
+      O << "\t.global " << *GVarSym << '\n';
+      O << "\t.type " << *GVarSym << ", @object\n";
+      O << *GVarSym << ":\n";
+      O << "\t.zero " << Size << '\n';
+    } else if (GVar->hasLocalLinkage()) {
+      O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size;
+    } else {
+      O << ".comm " << *GVarSym << ',' << Size;
+    }
+    if (VerboseAsm) {
+      O << "\t\t" << MAI->getCommentString() << " '";
+      WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
+      O << "'";
+    }
+    O << '\n';
+    return;
   }
 
   switch (GVar->getLinkage()) {
@@ -944,10 +944,25 @@
   unsigned Size = TD->getTypeAllocSize(Type);
   unsigned Align = TD->getPreferredAlignmentLog(GVar);
 
+  SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
   const MCSection *TheSection =
-    getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
+    getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
   OutStreamer.SwitchSection(TheSection);
 
+  // Handle the zerofill directive on darwin, which is a special form of BSS
+  // emission.
+  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective()) {
+    TargetLoweringObjectFileMachO &TLOFMacho = 
+    static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
+    if (TheSection == TLOFMacho.getDataCommonSection()) {
+      // .globl _foo
+      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+      // .zerofill __DATA, __common, _foo, 400, 5
+      OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
+      return;
+    }
+  }
+  
   /// FIXME: Drive this off the section!
   if (C->isNullValue() && /* FIXME: Verify correct */
       !GVar->hasSection() &&
@@ -957,11 +972,7 @@
       !TheSection->getKind().isMergeableCString()) {
     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
 
-    if (GVar->hasExternalLinkage()) {
-      O << "\t.globl " << *GVarSym << '\n';
-      O << "\t.zerofill __DATA, __common, " << *GVarSym << ", "
-        << Size << ", " << Align;
-    } else if (GVar->hasLocalLinkage()) {
+    if (GVar->hasLocalLinkage()) {
       O << MAI->getLCOMMDirective() << *GVarSym << ',' << Size << ',' << Align;
     } else if (!GVar->hasCommonLinkage()) {
       O << "\t.globl " << *GVarSym << '\n' << MAI->getWeakDefDirective();

Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Mon Jan 18 20:09:44 2010
@@ -750,6 +750,9 @@
   ConstDataCoalSection
     = getMachOSection("__DATA","__const_coal", MCSectionMachO::S_COALESCED,
                       SectionKind::getText());
+  DataCommonSection
+    = getMachOSection("__DATA","__common", MCSectionMachO::S_ZEROFILL,
+                      SectionKind::getBSS());
   ConstDataSection  // .const_data
     = getMachOSection("__DATA", "__const", 0,
                       SectionKind::getReadOnlyWithRel());
@@ -915,6 +918,11 @@
   if (Kind.isReadOnlyWithRel())
     return ConstDataSection;
 
+  // Put zero initialized globals with strong external linkage in the
+  // DATA, __common section with the .zerofill directive.
+  if (Kind.isBSS() && GV->hasExternalLinkage())
+    return DataCommonSection;
+  
   // Otherwise, just drop the variable in the normal data section.
   return DataSection;
 }

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp?rev=93838&r1=93837&r2=93838&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp Mon Jan 18 20:09:44 2010
@@ -664,88 +664,83 @@
   
   const TargetData *TD = TM.getTargetData();
 
-  MCSymbol *GVSym = GetGlobalValueSymbol(GVar);
+  MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
   Constant *C = GVar->getInitializer();
   const Type *Type = C->getType();
   unsigned Size = TD->getTypeAllocSize(Type);
   unsigned Align = TD->getPreferredAlignmentLog(GVar);
 
-  printVisibility(GVSym, GVar->getVisibility());
+  printVisibility(GVarSym, GVar->getVisibility());
 
   if (Subtarget->isTargetELF())
-    O << "\t.type\t" << *GVSym << ", at object\n";
+    O << "\t.type\t" << *GVarSym << ", at object\n";
   
   SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
   const MCSection *TheSection =
     getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
   OutStreamer.SwitchSection(TheSection);
 
+  // Handle the zerofill directive on darwin, which is a special form of BSS
+  // emission.
+  if (GVKind.isBSS() && MAI->hasMachoZeroFillDirective()) {
+    TargetLoweringObjectFileMachO &TLOFMacho = 
+      static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
+    if (TheSection == TLOFMacho.getDataCommonSection()) {
+      // .globl _foo
+      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+      // .zerofill __DATA, __common, _foo, 400, 5
+      OutStreamer.EmitZerofill(TheSection, GVarSym, Size, 1 << Align);
+      return;
+    }
+  }
+  
   // FIXME: get this stuff from section kind flags.
   if (C->isNullValue() && !GVar->hasSection() &&
       // Don't put things that should go in the cstring section into "comm".
-      !TheSection->getKind().isMergeableCString()) {
-    if (GVar->hasExternalLinkage()) {
-      if (MAI->hasZeroFillDirective()) {
-        // .globl _foo
-        OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
-        // .zerofill __DATA, __common, _foo, 400, 5
-        TargetLoweringObjectFileMachO &TLOFMacho = 
-          static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
-        // FIXME: This stuff should already be handled by SectionForGlobal!
-        const MCSection *TheSection = 
-          TLOFMacho.getMachOSection("__DATA", "__common",
-                                    MCSectionMachO::S_ZEROFILL,
-                                    SectionKind::getBSS());
-          
-        OutStreamer.EmitZerofill(TheSection, GVSym, Size, 1 << Align);
-        return;
-      }
-    }
-
-    if (!GVar->isThreadLocal() &&
-        (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
-      if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
-
-      if (MAI->getLCOMMDirective() != NULL) {
-        if (GVar->hasLocalLinkage()) {
-          O << MAI->getLCOMMDirective() << *GVSym << ',' << Size;
-          if (Subtarget->isTargetDarwin())
-            O << ',' << Align;
-        } else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
-          OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
-          O << MAI->getWeakDefDirective() << *GVSym << '\n';
-          EmitAlignment(Align, GVar);
-          O << *GVSym << ":";
-          if (VerboseAsm) {
-            O.PadToColumn(MAI->getCommentColumn());
-            O << MAI->getCommentString() << ' ';
-            WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
-          }
-          O << '\n';
-          EmitGlobalConstant(C);
-          return;
-        } else {
-          O << MAI->getCOMMDirective() << *GVSym << ',' << Size;
-          if (MAI->getCOMMDirectiveTakesAlignment())
-            O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
+      !TheSection->getKind().isMergeableCString() &&
+      !GVar->isThreadLocal() &&
+      (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
+    if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
+
+    if (const char *LComm = MAI->getLCOMMDirective()) {
+      if (GVar->hasLocalLinkage()) {
+        O << LComm << *GVarSym << ',' << Size;
+        if (Subtarget->isTargetDarwin())
+          O << ',' << Align;
+      } else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
+        OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+        O << MAI->getWeakDefDirective() << *GVarSym << '\n';
+        EmitAlignment(Align, GVar);
+        O << *GVarSym << ":";
+        if (VerboseAsm) {
+          O.PadToColumn(MAI->getCommentColumn());
+          O << MAI->getCommentString() << ' ';
+          WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
         }
+        O << '\n';
+        EmitGlobalConstant(C);
+        return;
       } else {
-        if (!Subtarget->isTargetCygMing()) {
-          if (GVar->hasLocalLinkage())
-            O << "\t.local\t" << *GVSym << '\n';
-        }
-        O << MAI->getCOMMDirective() << *GVSym << ',' << Size;
+        O << MAI->getCOMMDirective() << *GVarSym << ',' << Size;
         if (MAI->getCOMMDirectiveTakesAlignment())
           O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
       }
-      if (VerboseAsm) {
-        O.PadToColumn(MAI->getCommentColumn());
-        O << MAI->getCommentString() << ' ';
-        WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
+    } else {
+      if (!Subtarget->isTargetCygMing()) {
+        if (GVar->hasLocalLinkage())
+          O << "\t.local\t" << *GVarSym << '\n';
       }
-      O << '\n';
-      return;
+      O << MAI->getCOMMDirective() << *GVarSym << ',' << Size;
+      if (MAI->getCOMMDirectiveTakesAlignment())
+        O << ',' << (MAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
+    }
+    if (VerboseAsm) {
+      O.PadToColumn(MAI->getCommentColumn());
+      O << MAI->getCommentString() << ' ';
+      WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
     }
+    O << '\n';
+    return;
   }
 
   switch (GVar->getLinkage()) {
@@ -756,13 +751,13 @@
   case GlobalValue::WeakODRLinkage:
   case GlobalValue::LinkerPrivateLinkage:
     if (Subtarget->isTargetDarwin()) {
-      OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
-      O << MAI->getWeakDefDirective() << *GVSym << '\n';
+      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
+      O << MAI->getWeakDefDirective() << *GVarSym << '\n';
     } else if (Subtarget->isTargetCygMing()) {
-      OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
+      OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
       O << "\t.linkonce same_size\n";
     } else
-      O << "\t.weak\t" << *GVSym << '\n';
+      O << "\t.weak\t" << *GVarSym << '\n';
     break;
   case GlobalValue::DLLExportLinkage:
   case GlobalValue::AppendingLinkage:
@@ -770,7 +765,7 @@
     // their name or something.  For now, just emit them as external.
   case GlobalValue::ExternalLinkage:
     // If external or appending, declare as a global symbol
-    OutStreamer.EmitSymbolAttribute(GVSym, MCStreamer::Global);
+    OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
     break;
   case GlobalValue::PrivateLinkage:
   case GlobalValue::InternalLinkage:
@@ -780,7 +775,7 @@
   }
 
   EmitAlignment(Align, GVar);
-  O << *GVSym << ":";
+  O << *GVarSym << ":";
   if (VerboseAsm){
     O.PadToColumn(MAI->getCommentColumn());
     O << MAI->getCommentString() << ' ';
@@ -791,7 +786,7 @@
   EmitGlobalConstant(C);
 
   if (MAI->hasDotTypeDotSizeDirective())
-    O << "\t.size\t" << *GVSym << ", " << Size << '\n';
+    O << "\t.size\t" << *GVarSym << ", " << Size << '\n';
 }
 
 void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {





More information about the llvm-commits mailing list