Handle quoted names when constructing $stub's,
[oota-llvm.git] / lib / Target / X86 / X86AsmPrinter.cpp
index 9720100e3707fb7310307e078f92ef270af59c18..caccf52b075e1a81eaf4ed3bf3a5613b2b7a1e8c 100644 (file)
@@ -102,13 +102,13 @@ void X86SharedAsmPrinter::decorateName(std::string &Name,
   case StdCall:
     // "Pure" variadic functions do not receive @0 suffix.
     if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
-        (FT->getNumParams() == 1 && F->isStructReturn()))
+        (FT->getNumParams() == 1 && F->hasStructRetAttr()))
       Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
     break;
   case FastCall:
     // "Pure" variadic functions do not receive @0 suffix.
     if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
-        (FT->getNumParams() == 1 && F->isStructReturn()))
+        (FT->getNumParams() == 1 && F->hasStructRetAttr()))
       Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
 
     if (Name[0] == '_') {
@@ -200,7 +200,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
       
       if (!I->isThreadLocal() &&
           (I->hasInternalLinkage() || I->hasWeakLinkage() ||
-           I->hasLinkOnceLinkage())) {
+           I->hasLinkOnceLinkage() || I->hasCommonLinkage())) {
         if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
         if (!NoZerosInBSS && TAI->getBSSSection())
           SwitchToDataSection(TAI->getBSSSection(), I);
@@ -211,6 +211,16 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
             O << TAI->getLCOMMDirective() << name << "," << Size;
             if (Subtarget->isTargetDarwin())
               O << "," << Align;
+          } else if (Subtarget->isTargetDarwin() && !I->hasCommonLinkage()) {
+            O << "\t.globl " << name << "\n"
+              << TAI->getWeakDefDirective() << name << "\n";
+            SwitchToDataSection("\t.section __DATA,__datacoal_nt,coalesced", I);
+            EmitAlignment(Align, I);
+            O << name << ":\t\t\t\t" << TAI->getCommentString() << " ";
+            PrintUnmangledNameSafely(I, O);
+            O << "\n";
+            EmitGlobalConstant(C);
+            continue;
           } else {
             O << TAI->getCOMMDirective()  << name << "," << Size;
             
@@ -235,6 +245,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     }
 
     switch (I->getLinkage()) {
+    case GlobalValue::CommonLinkage:
     case GlobalValue::LinkOnceLinkage:
     case GlobalValue::WeakLinkage:
       if (Subtarget->isTargetDarwin()) {
@@ -374,16 +385,18 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
          i != e; ++i, ++j) {
       SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
                           "self_modifying_code+pure_instructions,5", 0);
-      O << "L" << *i << "$stub:\n";
-      O << "\t.indirect_symbol " << *i << "\n";
+      std::string p = *i;
+      printSuffixedName(p, "$stub");
+      O << ":\n";
+      O << "\t.indirect_symbol " << p << "\n";
       O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
     }
 
     O << "\n";
 
-    if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI &&
-        !Subtarget->is64Bit()) {
+    if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
       // Add the (possibly multiple) personalities to the set of global values.
+      // Only referenced functions get into the Personalities list.
       const std::vector<Function *>& Personalities = MMI->getPersonalities();
 
       for (std::vector<Function *>::const_iterator I = Personalities.begin(),
@@ -397,8 +410,10 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
                     "\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
     for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
          i != e; ++i) {
-      O << "L" << *i << "$non_lazy_ptr:\n";
-      O << "\t.indirect_symbol " << *i << "\n";
+      std::string p = *i;
+      printSuffixedName(p, "$non_lazy_ptr");
+      O << ":\n";
+      O << "\t.indirect_symbol " << p << "\n";
       O << "\t.long\t0\n";
     }