Proper handle case, when aliasee is external weak symbol referenced only by alias...
authorAnton Korobeynikov <asl@math.spbu.ru>
Thu, 6 Sep 2007 17:21:48 +0000 (17:21 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Thu, 6 Sep 2007 17:21:48 +0000 (17:21 +0000)
Also, fix a case, when target doesn't have weak symbols supported.

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

lib/CodeGen/AsmPrinter.cpp
test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll [new file with mode: 0644]

index 9387847cff6e17de9863eb1c195e2b5183ceec55..fa6f5691fc30f9e4dd53a96b40108156c195ce20 100644 (file)
@@ -132,13 +132,11 @@ bool AsmPrinter::doFinalization(Module &M) {
          I!=E; ++I) {
       std::string Name = Mang->getValueName(I);
       std::string Target;
+
+      const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
+      Target = Mang->getValueName(GV);
       
-      if (const GlobalValue *GV = I->getAliasedGlobal())
-        Target = Mang->getValueName(GV);
-      else
-        assert(0 && "Unsupported aliasee");
-      
-      if (I->hasExternalLinkage())
+      if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
         O << "\t.globl\t" << Name << "\n";
       else if (I->hasWeakLinkage())
         O << TAI->getWeakRefDirective() << Name << "\n";
@@ -146,6 +144,15 @@ bool AsmPrinter::doFinalization(Module &M) {
         assert(0 && "Invalid alias linkage");
       
       O << TAI->getSetDirective() << Name << ", " << Target << "\n";
+
+      // If the aliasee has external weak linkage it can be referenced only by
+      // alias itself. In this case it can be not in ExtWeakSymbols list. Emit
+      // weak reference in such case.
+      if (GV->hasExternalWeakLinkage())
+        if (TAI->getWeakRefDirective())
+          O << TAI->getWeakRefDirective() << Target << "\n";
+        else
+          O << "\t.globl\t" << Target << "\n";
     }
   }
 
diff --git a/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll b/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll
new file mode 100644 (file)
index 0000000..4f95b76
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep weak | count 2
+@__gthrw_pthread_once = alias weak i32 (i32*, void ()*)* @pthread_once         ; <i32 (i32*, void ()*)*> [#uses=0]
+
+declare extern_weak i32 @pthread_once(i32*, void ()*)