hookize the cygwin ".linkonce" directive.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93855 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h
index a340a12..22f1475 100644
--- a/include/llvm/MC/MCAsmInfo.h
+++ b/include/llvm/MC/MCAsmInfo.h
@@ -226,6 +226,10 @@
     /// WeakDefDirective - This directive, if non-null, is used to declare a
     /// global as being a weak defined symbol.
     const char *WeakDefDirective;            // Defaults to NULL.
+
+    /// LinkOnceDirective - This directive, if non-null is used to declare a
+    /// global as being a weak defined symbol.  This is used on cygwin/mingw.
+    const char *LinkOnceDirective;           // Defaults to NULL.
     
     /// HiddenDirective - This directive, if non-null, is used to declare a
     /// global or function as having hidden visibility.
@@ -426,12 +430,9 @@
     const char *getUsedDirective() const {
       return UsedDirective;
     }
-    const char *getWeakRefDirective() const {
-      return WeakRefDirective;
-    }
-    const char *getWeakDefDirective() const {
-      return WeakDefDirective;
-    }
+    const char *getWeakRefDirective() const { return WeakRefDirective; }
+    const char *getWeakDefDirective() const { return WeakDefDirective; }
+    const char *getLinkOnceDirective() const { return LinkOnceDirective; }
     const char *getHiddenDirective() const {
       return HiddenDirective;
     }
diff --git a/lib/MC/MCAsmInfo.cpp b/lib/MC/MCAsmInfo.cpp
index 4c53d7a..556b0aa 100644
--- a/lib/MC/MCAsmInfo.cpp
+++ b/lib/MC/MCAsmInfo.cpp
@@ -62,6 +62,7 @@
   UsedDirective = 0;
   WeakRefDirective = 0;
   WeakDefDirective = 0;
+  LinkOnceDirective = 0;
   // FIXME: These are ELFish - move to ELFMAI.
   HiddenDirective = "\t.hidden\t";
   ProtectedDirective = "\t.protected\t";
diff --git a/lib/MC/MCAsmInfoCOFF.cpp b/lib/MC/MCAsmInfoCOFF.cpp
index 23b0dd7..1b27bf0 100644
--- a/lib/MC/MCAsmInfoCOFF.cpp
+++ b/lib/MC/MCAsmInfoCOFF.cpp
@@ -25,6 +25,7 @@
   HiddenDirective = NULL;
   PrivateGlobalPrefix = "L";  // Prefix for private global symbols
   WeakRefDirective = "\t.weak\t";
+  LinkOnceDirective = "\t.linkonce same_size\n";
   SetDirective = "\t.set\t";
 
   // Set up DWARF directives
diff --git a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
index 358bb70..a095411 100644
--- a/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
+++ b/lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp
@@ -727,12 +727,16 @@
   case GlobalValue::WeakAnyLinkage:
   case GlobalValue::WeakODRLinkage:
   case GlobalValue::LinkerPrivateLinkage:
-    if (Subtarget->isTargetDarwin()) {
+    if (const char *WeakDef = MAI->getWeakDefDirective()) {
+      // .globl _foo
       OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
-      O << MAI->getWeakDefDirective() << *GVarSym << '\n';
-    } else if (Subtarget->isTargetCygMing()) {
+      // .weak_definition _foo
+      O << WeakDef << *GVarSym << '\n';
+    } else if (const char *LinkOnce = MAI->getLinkOnceDirective()) {
+      // .globl _foo
       OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
-      O << "\t.linkonce same_size\n";
+      // .linkonce same_size
+      O << LinkOnce;
     } else
       O << "\t.weak\t" << *GVarSym << '\n';
     break;
@@ -741,7 +745,8 @@
     // FIXME: appending linkage variables should go into a section of
     // their name or something.  For now, just emit them as external.
   case GlobalValue::ExternalLinkage:
-    // If external or appending, declare as a global symbol
+    // If external or appending, declare as a global symbol.
+    // .globl _foo
     OutStreamer.EmitSymbolAttribute(GVarSym, MCStreamer::Global);
     break;
   case GlobalValue::PrivateLinkage:
@@ -753,7 +758,7 @@
 
   EmitAlignment(AlignLog, GVar);
   O << *GVarSym << ":";
-  if (VerboseAsm){
+  if (VerboseAsm) {
     O.PadToColumn(MAI->getCommentColumn());
     O << MAI->getCommentString() << ' ';
     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());