hookize the cygwin ".linkonce" directive.
authorChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 05:08:13 +0000 (05:08 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 19 Jan 2010 05:08:13 +0000 (05:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93855 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCAsmInfo.h
lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmInfoCOFF.cpp
lib/Target/X86/AsmPrinter/X86AsmPrinter.cpp

index a340a12138481730d0cf33a44c671526c3bd0a70..22f147587cd9f74b6dba27875662fbbd4030da36 100644 (file)
@@ -226,6 +226,10 @@ namespace llvm {
     /// 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 @@ namespace llvm {
     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;
     }
index 4c53d7a284aadd8be3eeb9aa004e5f7260f1cdd9..556b0aa6c68d6d8d666e2e06a8601ec16b7321d6 100644 (file)
@@ -62,6 +62,7 @@ MCAsmInfo::MCAsmInfo() {
   UsedDirective = 0;
   WeakRefDirective = 0;
   WeakDefDirective = 0;
+  LinkOnceDirective = 0;
   // FIXME: These are ELFish - move to ELFMAI.
   HiddenDirective = "\t.hidden\t";
   ProtectedDirective = "\t.protected\t";
index 23b0dd77916b9d797d8c6d6eeb2719bbf19760de..1b27bf026ec70fbcb239d6a07d5eda7921030a78 100644 (file)
@@ -25,6 +25,7 @@ MCAsmInfoCOFF::MCAsmInfoCOFF() {
   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
index 358bb70e2cbd178caff95ba5c4ef1a1fd0f22989..a0954110577598c819247fe5c0f6e45b7da6d3af 100644 (file)
@@ -727,12 +727,16 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
   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 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
     // 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 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
 
   EmitAlignment(AlignLog, GVar);
   O << *GVarSym << ":";
-  if (VerboseAsm){
+  if (VerboseAsm) {
     O.PadToColumn(MAI->getCommentColumn());
     O << MAI->getCommentString() << ' ';
     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());