A initialized global variable cannot be extern weak. However, if a global value's...
authorEvan Cheng <evan.cheng@apple.com>
Fri, 1 Dec 2006 09:13:26 +0000 (09:13 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Fri, 1 Dec 2006 09:13:26 +0000 (09:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32069 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.cpp

index fdc335d4cf429c16569b52c39ede534f804f6f26..0998c29226a7ce726f85eb4ef86b04aa04a39cf7 100644 (file)
@@ -605,6 +605,9 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
     } else {
       switch (I->getLinkage()) {
       case GlobalValue::LinkOnceLinkage:
+      case GlobalValue::ExternalWeakLinkage:
+        O << "\t.weak_reference " << name << "\n";
+        break;
       case GlobalValue::WeakLinkage:
         O << "\t.globl " << name << '\n'
           << "\t.weak_definition " << name << '\n';
@@ -635,6 +638,13 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
 
       EmitAlignment(Align, I);
       O << name << ":\t\t\t\t; '" << I->getName() << "'\n";
+
+      // If the initializer is a extern weak symbol, remember to emit the weak
+      // reference!
+      if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
+        if (GV->hasExternalWeakLinkage())
+          ExtWeakSymbols.insert(Mang->getValueName(GV));
+
       EmitGlobalConstant(C);
       O << '\n';
     }
index a37cbb5406b1b03e71158eb94a8bb5ecc2daf404..b92a087859d89bb605a89a5e7e5f3c1957fb8eb8 100644 (file)
@@ -177,17 +177,6 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
     } else {
       switch (I->getLinkage()) {
-      case GlobalValue::ExternalWeakLinkage:
-       if (Subtarget->isTargetDarwin()) {
-         assert(0 && "External weak linkage for Darwin not implemented yet");
-       } else if (Subtarget->isTargetCygwin()) {
-         // There is no external weak linkage on Mingw32 platform.
-         // Defaulting just to external
-         O << "\t.globl " << name << "\n";
-       } else {
-         O << "\t.weak " << name << "\n";
-         break;
-       }
       case GlobalValue::LinkOnceLinkage:
       case GlobalValue::WeakLinkage:
         if (Subtarget->isTargetDarwin()) {
@@ -257,6 +246,12 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       if (TAI->hasDotTypeDotSizeDirective())
         O << "\t.size " << name << ", " << Size << "\n";
 
+      // If the initializer is a extern weak symbol, remember to emit the weak
+      // reference!
+      if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
+        if (GV->hasExternalWeakLinkage())
+          ExtWeakSymbols.insert(Mang->getValueName(GV));
+
       EmitGlobalConstant(C);
       O << '\n';
     }