Reapply my previous asmprinter changes now with more testing and two 
additional bug fixes:

1. The bug that everyone hit was a problem in the asmprinter where it
   would remove $stub but keep the L prefix on a name when emitting the
   indirect symbol.  This is easy to fix by keeping the name of the stub
   and the name of the symbol in a StringMap instead of just keeping a
   StringSet and trying to reconstruct it late.

2. There was a problem printing the personality function.  The current
   logic to print out the personality function from the DWARF information
   is a bit of a cesspool right now that duplicates a bunch of other 
   logic in the asm printer.  The short version of it is that it depends
   on emitting both the L and _ prefix for symbols (at least on darwin)
   and until I can untangle it, it is best to switch the mangler back to
   emitting both prefixes.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75646 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index d0b0aab..7e1d413 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -210,13 +210,13 @@
     for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
          I != E; ++I) {
       if (I->hasExternalWeakLinkage())
-        O << TAI->getWeakRefDirective() << Mang->getValueName(I) << '\n';
+        O << TAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
     }
     
     for (Module::const_iterator I = M.begin(), E = M.end();
          I != E; ++I) {
       if (I->hasExternalWeakLinkage())
-        O << TAI->getWeakRefDirective() << Mang->getValueName(I) << '\n';
+        O << TAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
     }
   }
 
@@ -227,11 +227,10 @@
     O << '\n';
     for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
          I != E; ++I) {
-      std::string Name = Mang->getValueName(I);
-      std::string Target;
+      std::string Name = Mang->getMangledName(I);
 
       const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
-      Target = Mang->getValueName(GV);
+      std::string Target = Mang->getMangledName(GV);
 
       if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
         O << "\t.globl\t" << Name << '\n';
@@ -270,15 +269,16 @@
   assert(MF && "No machine function?");
   Name = MF->getFunction()->getName();
   if (Name.empty())
-    Name = Mang->getValueName(MF->getFunction());
+    Name = Mang->getMangledName(MF->getFunction());
   
+  // FIXME: THIS SEEMS REALLY WRONG, it will get two prefixes.
   Name = Mang->makeNameProper(TAI->getEHGlobalPrefix() + Name + ".eh");
   return Name;
 }
 
 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
   // What's my mangled name?
-  CurrentFnName = Mang->getValueName(MF.getFunction());
+  CurrentFnName = Mang->getMangledName(MF.getFunction());
   IncrementFunctionNumber();
 }
 
@@ -576,11 +576,11 @@
                                                  std::string &LinkName) const {
   if (isa<Function>(GV)) {
     LinkName += TAI->getFunctionAddrPrefix();
-    LinkName += Mang->getValueName(GV);
+    LinkName += Mang->getMangledName(GV);
     LinkName += TAI->getFunctionAddrSuffix();
   } else {
     LinkName += TAI->getGlobalVarAddrPrefix();
-    LinkName += Mang->getValueName(GV);
+    LinkName += Mang->getMangledName(GV);
     LinkName += TAI->getGlobalVarAddrSuffix();
   }  
   
@@ -858,11 +858,11 @@
     // FunctionAddrPrefix/Suffix (these all default to "" )
     if (isa<Function>(GV)) {
       O << TAI->getFunctionAddrPrefix()
-        << Mang->getValueName(GV)
+        << Mang->getMangledName(GV)
         << TAI->getFunctionAddrSuffix();
     } else {
       O << TAI->getGlobalVarAddrPrefix()
-        << Mang->getValueName(GV)
+        << Mang->getMangledName(GV)
         << TAI->getGlobalVarAddrSuffix();
     }
   } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp
index e041bd3..05b7361 100644
--- a/lib/CodeGen/ELFWriter.cpp
+++ b/lib/CodeGen/ELFWriter.cpp
@@ -601,7 +601,7 @@
 
     // Use the name mangler to uniquify the LLVM symbol.
     std::string Name;
-    if (I->GV) Name.append(Mang->getValueName(I->GV));
+    if (I->GV) Name.append(Mang->getMangledName(I->GV));
 
     if (Name.empty()) {
       I->NameIdx = 0;
diff --git a/lib/CodeGen/MachOCodeEmitter.cpp b/lib/CodeGen/MachOCodeEmitter.cpp
index 14ebc3f..7709276 100644
--- a/lib/CodeGen/MachOCodeEmitter.cpp
+++ b/lib/CodeGen/MachOCodeEmitter.cpp
@@ -60,7 +60,7 @@
 
   // Create symbol for function entry
   const GlobalValue *FuncV = MF.getFunction();
-  MachOSym FnSym(FuncV, MOW.Mang->getValueName(FuncV), MOS->Index, TAI);
+  MachOSym FnSym(FuncV, MOW.Mang->getMangledName(FuncV), MOS->Index, TAI);
   FnSym.n_value = getCurrentPCOffset();
 
   // add it to the symtab.
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
index 5cbe6fd..d19b218 100644
--- a/lib/CodeGen/MachOWriter.cpp
+++ b/lib/CodeGen/MachOWriter.cpp
@@ -221,7 +221,7 @@
   }
   // Globals without external linkage apparently do not go in the symbol table.
   if (!GV->hasLocalLinkage()) {
-    MachOSym Sym(GV, Mang->getValueName(GV), Sec->Index, TAI);
+    MachOSym Sym(GV, Mang->getMangledName(GV), Sec->Index, TAI);
     Sym.n_value = Sec->size();
     SymbolTable.push_back(Sym);
   }
@@ -255,7 +255,7 @@
     // merged with other symbols.
     if (NoInit || GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() ||
         GV->hasCommonLinkage()) {
-      MachOSym ExtOrCommonSym(GV, Mang->getValueName(GV),
+      MachOSym ExtOrCommonSym(GV, Mang->getMangledName(GV),
                               MachOSym::NO_SECT, TAI);
       // For undefined (N_UNDF) external (N_EXT) types, n_value is the size in
       // bytes of the symbol.
@@ -454,7 +454,7 @@
   for (std::vector<GlobalValue*>::iterator I = PendingGlobals.begin(),
          E = PendingGlobals.end(); I != E; ++I) {
     if (GVOffset[*I] == 0 && GVSection[*I] == 0) {
-      MachOSym UndfSym(*I, Mang->getValueName(*I), MachOSym::NO_SECT, TAI);
+      MachOSym UndfSym(*I, Mang->getMangledName(*I), MachOSym::NO_SECT, TAI);
       SymbolTable.push_back(UndfSym);
       GVOffset[*I] = -1;
     }