Fixed mingw\cygwin linkonce linkage once again.
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 18 Oct 2006 09:12:29 +0000 (09:12 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 18 Oct 2006 09:12:29 +0000 (09:12 +0000)
Added workaround for linker bug with linkonce sections.
Changed sections prefix to allow linker merge them
(PE loader doesn't like too much long-named sections :) )
All of this unbreaks libstdc++ on mingw32 allowing (small)
programs to be compiled, linked and run.

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

lib/Target/X86/X86ATTAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp

index bb6bb3dbc1334a2636597c2cbdfa0a00bba6a543..dc2ecca7cb4544e6431f2f674ae684503493575b 100755 (executable)
@@ -40,7 +40,7 @@ std::string X86ATTAsmPrinter::getSectionForFunction(const Function &F) const {
     if (Subtarget->isTargetDarwin()) {
       return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
     } else if (Subtarget->isTargetCygwin()) {
-      return "\t.section\t.llvm.linkonce.t." + CurrentFnName + ",\"ax\"\n";
+      return "\t.section\t.text$linkonce." + CurrentFnName + ",\"ax\"\n";
     } else {
       return "\t.section\t.llvm.linkonce.t." + CurrentFnName +
              ",\"ax\",@progbits\n";
@@ -90,6 +90,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
     O << "\t.globl\t" << CurrentFnName << "\n";    
     break;
   case Function::LinkOnceLinkage:
+  case Function::WeakLinkage:
     if (Subtarget->isTargetDarwin()) {
       O << "\t.globl\t" << CurrentFnName << "\n";
       O << "\t.weak_definition\t" << CurrentFnName << "\n";
@@ -102,20 +103,13 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
       O << "\t.weak " << CurrentFnName << "\n";
     }
     break;
-  case Function::WeakLinkage:
-    if (Subtarget->isTargetDarwin()) {
-      O << "\t.globl\t" << CurrentFnName << "\n";
-      O << "\t.weak_definition\t" << CurrentFnName << "\n";
-    } else if (Subtarget->isTargetCygwin()) {
-      EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
-      O << "\t.weak " << CurrentFnName << "\n";
-    } else {
-      EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
-      O << "\t.weak " << CurrentFnName << "\n";
-    }
-    break;
   }
   O << CurrentFnName << ":\n";
+  // Add some workaround for linkonce linkage on Cygwin\MinGW
+  if (Subtarget->isTargetCygwin() &&
+      (F->getLinkage() == Function::LinkOnceLinkage ||
+       F->getLinkage() == Function::WeakLinkage))
+    O << "_llvm$workaround$fake$stub_" << CurrentFnName << ":\n";
 
   if (Subtarget->isTargetDarwin()) {
     // Emit pre-function debug information.
index 2a3a2aaed441a2dc4ea39be7f89b77b6ec3b29ef..bab80dbd443d324e9066d81df7d2a4fd1b29ff3a 100644 (file)
@@ -174,12 +174,13 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     } else {
       switch (I->getLinkage()) {
       case GlobalValue::LinkOnceLinkage:
+      case GlobalValue::WeakLinkage:
         if (Subtarget->isTargetDarwin()) {
           O << "\t.globl " << name << "\n"
             << "\t.weak_definition " << name << "\n";
           SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
         } else if (Subtarget->isTargetCygwin()) {
-          O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n"
+          O << "\t.section\t.data$linkonce." << name << ",\"aw\"\n"
             << "\t.globl " << name << "\n"
             << "\t.linkonce same_size\n";
         } else {
@@ -187,19 +188,6 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
             << "\t.weak " << name << "\n";
         }
         break;
-      case GlobalValue::WeakLinkage:
-        if (Subtarget->isTargetDarwin()) {
-          O << "\t.globl " << name << "\n"
-            << "\t.weak_definition " << name << "\n";
-          SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
-        } else if (Subtarget->isTargetCygwin()) {
-          O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n"
-            << "\t.weak " << name << "\n";
-        } else {
-          O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"
-            << "\t.weak " << name << "\n";
-        }
-        break;
       case GlobalValue::AppendingLinkage:
         // FIXME: appending linkage variables should go into a section of
         // their name or something.  For now, just emit them as external.