mcstreamerize .no_dead_strip and .reference for static ctors/dtors.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94290 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 3d2f415..415627e 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -313,7 +313,7 @@
   }
 
   if (MAI->getSetDirective()) {
-    O << '\n';
+    OutStreamer.AddBlankLine();
     for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
          I != E; ++I) {
       MCSymbol *Name = GetGlobalValueSymbol(I);
@@ -563,7 +563,7 @@
   } else {
     O << *GetMBBSymbol(MBB->getNumber());
     // If the arch uses custom Jump Table directives, don't calc relative to
-    // JT
+    // JT.
     if (!HadJTEntryDirective) 
       O << '-' << *GetJTISymbol(uid);
   }
@@ -575,7 +575,7 @@
 /// do nothing and return false.
 bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
   if (GV->getName() == "llvm.used") {
-    if (MAI->getUsedDirective() != 0)    // No need to emit this at all.
+    if (MAI->hasNoDeadStrip())    // No need to emit this at all.
       EmitLLVMUsedList(GV->getInitializer());
     return true;
   }
@@ -597,8 +597,11 @@
     EmitXXStructorList(GV->getInitializer());
     
     if (TM.getRelocationModel() == Reloc::Static &&
-        MAI->hasStaticCtorDtorReferenceInStaticMode())
-      O << ".reference .constructors_used\n";
+        MAI->hasStaticCtorDtorReferenceInStaticMode()) {
+      StringRef Sym(".constructors_used");
+      OutStreamer.EmitSymbolAttribute(OutContext.GetOrCreateSymbol(Sym),
+                                      MCStreamer::Reference);
+    }
     return true;
   } 
   
@@ -608,8 +611,11 @@
     EmitXXStructorList(GV->getInitializer());
 
     if (TM.getRelocationModel() == Reloc::Static &&
-        MAI->hasStaticCtorDtorReferenceInStaticMode())
-      O << ".reference .destructors_used\n";
+        MAI->hasStaticCtorDtorReferenceInStaticMode()) {
+      StringRef Sym(".destructors_used");
+      OutStreamer.EmitSymbolAttribute(OutContext.GetOrCreateSymbol(Sym),
+                                      MCStreamer::Reference);
+    }
     return true;
   }
   
@@ -620,8 +626,6 @@
 /// global in the specified llvm.used list for which emitUsedDirectiveFor
 /// is true, as being used with this directive.
 void AsmPrinter::EmitLLVMUsedList(Constant *List) {
-  const char *Directive = MAI->getUsedDirective();
-
   // Should be an array of 'i8*'.
   ConstantArray *InitList = dyn_cast<ConstantArray>(List);
   if (InitList == 0) return;
@@ -629,11 +633,9 @@
   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
     const GlobalValue *GV =
       dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
-    if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) {
-      O << Directive;
-      EmitConstantValueOnly(InitList->getOperand(i));
-      O << '\n';
-    }
+    if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang))
+      OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(GV),
+                                      MCStreamer::NoDeadStrip);
   }
 }
 
@@ -1584,6 +1586,7 @@
   // Print the main label for the block.
   if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
     if (VerboseAsm) {
+      // NOTE: Want this comment at start of line.
       O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
       if (const BasicBlock *BB = MBB->getBasicBlock())
         if (BB->hasName())