move production of .reference directives for static ctor/dtor list on
authorChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 04:34:02 +0000 (04:34 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 04:34:02 +0000 (04:34 +0000)
darwin into common code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93849 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmInfo.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmInfoDarwin.cpp
lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

index 6d01278711faac103bf27828bd9e618ff3d5d0b2..1368e1f424973e54f11556ba9ad1a88da1880343 100644 (file)
@@ -36,7 +36,13 @@ namespace llvm {
 
     /// HasMachoZeroFillDirective - True if this is a MachO target that supports
     /// the macho-specific .zerofill directive for emitting BSS Symbols.
-    bool HasMachoZeroFillDirective;           // Default is false.
+    bool HasMachoZeroFillDirective;               // Default is false.
+    
+    /// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
+    /// emit a ".reference .constructors_used" or ".reference .destructors_used"
+    /// directive after the a static ctor/dtor list.  This directive is only
+    /// emitted in Static relocation model.
+    bool HasStaticCtorDtorReferenceInStaticMode;  // Default is false.
     
     /// NeedsSet - True if target asm treats expressions in data directives
     /// as linktime-relocatable.  For assembly-time computation, we need to
@@ -314,7 +320,9 @@ namespace llvm {
     // Accessors.
     //
     bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
-    
+    bool hasStaticCtorDtorReferenceInStaticMode() const {
+      return HasStaticCtorDtorReferenceInStaticMode;
+    }
     const char *getNonexecutableStackDirective() const {
       return NonexecutableStackDirective;
     }
index 3beb4d66ac83513ed22ec2ca337c15caa9d102c6..9a19f81e38b92acebbefc9eba69be2f5ef828b0e 100644 (file)
@@ -449,6 +449,10 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
     OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
     EmitAlignment(Align, 0);
     EmitXXStructorList(GV->getInitializer());
+    
+    if (TM.getRelocationModel() == Reloc::Static &&
+        MAI->hasStaticCtorDtorReferenceInStaticMode())
+      O << ".reference .constructors_used\n";
     return true;
   } 
   
@@ -456,6 +460,10 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
     OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
     EmitAlignment(Align, 0);
     EmitXXStructorList(GV->getInitializer());
+
+    if (TM.getRelocationModel() == Reloc::Static &&
+        MAI->hasStaticCtorDtorReferenceInStaticMode())
+      O << ".reference .destructors_used\n";
     return true;
   }
   
index 6e8cd0ce8d758c76d0ca7ae9e3fcacf01c258241..277a09e9e9a1391156767299f99e999fff8b6db6 100644 (file)
@@ -20,6 +20,7 @@ using namespace llvm;
 
 MCAsmInfo::MCAsmInfo() {
   HasMachoZeroFillDirective = false;
+  HasStaticCtorDtorReferenceInStaticMode = false;
   NonexecutableStackDirective = 0;
   NeedsSet = false;
   MaxInstLength = 4;
index 8719bee89bfb7bd5dbdd5b0d2b9bf46d72c3733e..5de86e0c901ee23f1e32261bd2bf719dffbecff7 100644 (file)
@@ -36,6 +36,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
   LCOMMDirective = "\t.lcomm\t";
   ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
   HasMachoZeroFillDirective = true;  // Uses .zerofill
+  HasStaticCtorDtorReferenceInStaticMode = true;
   SetDirective = "\t.set";
   ProtectedDirective = "\t.globl\t";
   HasDotTypeDotSizeDirective = false;
index fd26169db3fd6ff5e747dfb623fc5ffdc68b2391..070c29a24dd1cb6a17fde2d2dc3ef6393bd37ca4 100644 (file)
@@ -1171,17 +1171,8 @@ void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
     return;
 
   // Check to see if this is a special global used by LLVM, if so, emit it.
-
-  if (EmitSpecialLLVMGlobal(GVar)) {
-    if (Subtarget->isTargetDarwin() &&
-        TM.getRelocationModel() == Reloc::Static) {
-      if (GVar->getName() == "llvm.global_ctors")
-        O << ".reference .constructors_used\n";
-      else if (GVar->getName() == "llvm.global_dtors")
-        O << ".reference .destructors_used\n";
-    }
+  if (EmitSpecialLLVMGlobal(GVar))
     return;
-  }
 
   MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
   
index e17d89a363b29689c7fc6b7ce52f97e45b33d151..a1c117dd04194e605e29e61099aec61769270a15 100644 (file)
@@ -933,15 +933,8 @@ void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
     return;   // External global require no code
 
   // Check to see if this is a special global used by LLVM, if so, emit it.
-  if (EmitSpecialLLVMGlobal(GVar)) {
-    if (TM.getRelocationModel() == Reloc::Static) {
-      if (GVar->getName() == "llvm.global_ctors")
-        O << ".reference .constructors_used\n";
-      else if (GVar->getName() == "llvm.global_dtors")
-        O << ".reference .destructors_used\n";
-    }
+  if (EmitSpecialLLVMGlobal(GVar))
     return;
-  }
 
   MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
   printVisibility(GVarSym, GVar->getVisibility());
index 438c208ad8fee98dd8dffb7c362110b77d50580a..bdbb2946faf74dcadc390ee677f6e2602f5c10ee 100644 (file)
@@ -651,16 +651,8 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
     return;   // External global require no code
   
   // Check to see if this is a special global used by LLVM, if so, emit it.
-  if (EmitSpecialLLVMGlobal(GVar)) {
-    if (Subtarget->isTargetDarwin() &&
-        TM.getRelocationModel() == Reloc::Static) {
-      if (GVar->getName() == "llvm.global_ctors")
-        O << ".reference .constructors_used\n";
-      else if (GVar->getName() == "llvm.global_dtors")
-        O << ".reference .destructors_used\n";
-    }
+  if (EmitSpecialLLVMGlobal(GVar))
     return;
-  }
   
   const TargetData *TD = TM.getTargetData();