Darwin -static should codegen static ctors / dtors to .constructor / .destructor...
authorEvan Cheng <evan.cheng@apple.com>
Tue, 30 Jan 2007 08:04:53 +0000 (08:04 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Tue, 30 Jan 2007 08:04:53 +0000 (08:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33657 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMAsmPrinter.cpp
lib/Target/ARM/ARMTargetAsmInfo.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCTargetAsmInfo.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86TargetAsmInfo.cpp

index b73c4109e5ff2bfc7b0d8cc0ac1030ee03bb8953..0412bc58ac4d95eb08abae780da54a0f301e7124 100644 (file)
@@ -714,8 +714,16 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
     if (!I->hasInitializer())   // External global require no code
       continue;
 
-    if (EmitSpecialLLVMGlobal(I))
+    if (EmitSpecialLLVMGlobal(I)) {
+      if (Subtarget->isTargetDarwin() &&
+          TM.getRelocationModel() == Reloc::Static) {
+        if (I->getName() == "llvm.global_ctors")
+          O << ".reference .constructors_used\n";
+        else if (I->getName() == "llvm.global_dtors")
+          O << ".reference .destructors_used\n";
+      }
       continue;
+    }
 
     std::string name = Mang->getValueName(I);
     Constant *C = I->getInitializer();
index f896eb724cabb4cf1b62a2ed05b9271e223739b2..56da6d9f05ae90e24c46c6ac5c11abce263a6fdd 100644 (file)
@@ -28,8 +28,13 @@ ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) {
     JumpTableDataSection = ".const";
     CStringSection = "\t.cstring";
     HasDotTypeDotSizeDirective = false;
-    StaticCtorsSection = ".mod_init_func";
-    StaticDtorsSection = ".mod_term_func";
+    if (TM.getRelocationModel() == Reloc::Static) {
+      StaticCtorsSection = ".constructor";
+      StaticDtorsSection = ".destructor";
+    } else {
+      StaticCtorsSection = ".mod_init_func";
+      StaticDtorsSection = ".mod_term_func";
+    }
     
     // In non-PIC modes, emit a special label before jump tables so that the
     // linker can perform more accurate dead code stripping.
index 3945d1ac3721956899f871c4ee400a8a77fca774..7126af286782e0ca6c3dc5841a2ca984f518472f 100644 (file)
@@ -855,8 +855,15 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
     if (!I->hasInitializer()) continue;   // External global require no code
     
     // Check to see if this is a special global used by LLVM, if so, emit it.
-    if (EmitSpecialLLVMGlobal(I))
+    if (EmitSpecialLLVMGlobal(I)) {
+      if (TM.getRelocationModel() == Reloc::Static) {
+        if (I->getName() == "llvm.global_ctors")
+          O << ".reference .constructors_used\n";
+        else if (I->getName() == "llvm.global_dtors")
+          O << ".reference .destructors_used\n";
+      }
       continue;
+    }
     
     std::string name = Mang->getValueName(I);
     
index 0fc8481b742c0e60965411a29d21d5b69deca750..2442a38366fa1e76f650bf8e5f52167ddd9e716e 100644 (file)
@@ -53,8 +53,13 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM)
   JumpTableDataSection = ".const";
   GlobalDirective = "\t.globl\t";
   CStringSection = "\t.cstring";
-  StaticCtorsSection = ".mod_init_func";
-  StaticDtorsSection = ".mod_term_func";
+  if (TM.getRelocationModel() == Reloc::Static) {
+    StaticCtorsSection = ".constructor";
+    StaticDtorsSection = ".destructor";
+  } else {
+    StaticCtorsSection = ".mod_init_func";
+    StaticDtorsSection = ".mod_term_func";
+  }
   UsedDirective = "\t.no_dead_strip\t";
   WeakRefDirective = "\t.weak_reference\t";
   HiddenDirective = "\t.private_extern\t";
index ff85828c5a52473e447c2a880861a1ca4ba2bce1..0e9171bb711255157bbe4eb954bfc20043c883b9 100644 (file)
@@ -134,8 +134,16 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       continue;   // External global require no code
     
     // Check to see if this is a special global used by LLVM, if so, emit it.
-    if (EmitSpecialLLVMGlobal(I))
+    if (EmitSpecialLLVMGlobal(I)) {
+      if (Subtarget->isTargetDarwin() &&
+          TM.getRelocationModel() == Reloc::Static) {
+        if (I->getName() == "llvm.global_ctors")
+          O << ".reference .constructors_used\n";
+        else if (I->getName() == "llvm.global_dtors")
+          O << ".reference .destructors_used\n";
+      }
       continue;
+    }
     
     std::string name = Mang->getValueName(I);
     Constant *C = I->getInitializer();
index 2bb4a6c227244a1ac95731cb6c9a7c8b6a1f9a71..20e0f195fcf0c4c4900f7f40bd783ae41a91f727 100644 (file)
@@ -59,8 +59,13 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     LCOMMDirective = "\t.lcomm\t";
     COMMDirectiveTakesAlignment = false;
     HasDotTypeDotSizeDirective = false;
-    StaticCtorsSection = ".mod_init_func";
-    StaticDtorsSection = ".mod_term_func";
+    if (TM.getRelocationModel() == Reloc::Static) {
+      StaticCtorsSection = ".constructor";
+      StaticDtorsSection = ".destructor";
+    } else {
+      StaticCtorsSection = ".mod_init_func";
+      StaticDtorsSection = ".mod_term_func";
+    }
     InlineAsmStart = "# InlineAsm Start";
     InlineAsmEnd = "# InlineAsm End";
     SetDirective = "\t.set";