Fix .eh table linkage issues on Darwin.  Some EH support
for Darwin PPC, but it's not fully working yet.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44258 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp
index da75887..bac735a 100644
--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -322,10 +322,11 @@
   struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter {
   
     DwarfWriter DW;
+    MachineModuleInfo *MMI;
 
     DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM,
                      const TargetAsmInfo *T)
-      : PPCAsmPrinter(O, TM, T), DW(O, this, T) {
+      : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
     }
 
     virtual const char *getPassName() const {
@@ -774,11 +775,13 @@
 /// method to print assembly for each instruction.
 ///
 bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
-  DW.SetModuleInfo(&getAnalysis<MachineModuleInfo>());
+  // We need this for Personality functions.
+  MMI = &getAnalysis<MachineModuleInfo>();
+  DW.SetModuleInfo(MMI);
 
   SetupMachineFunction(MF);
   O << "\n\n";
-  
+
   // Print out constants referenced by the function
   EmitConstantPool(MF.getConstantPool());
 
@@ -1054,6 +1057,15 @@
 
   O << "\n";
 
+  if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) {
+    // Add the (possibly multiple) personalities to the set of global values.
+    const std::vector<Function *>& Personalities = MMI->getPersonalities();
+
+    for (std::vector<Function *>::const_iterator I = Personalities.begin(),
+           E = Personalities.end(); I != E; ++I)
+      if (*I) GVStubs.insert("_" + (*I)->getName());
+  }
+
   // Output stubs for external and common global variables.
   if (!GVStubs.empty()) {
     SwitchToDataSection(".non_lazy_symbol_pointer");
diff --git a/lib/Target/PowerPC/PPCTargetAsmInfo.cpp b/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
index 992b090..ee1d063 100644
--- a/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
+++ b/lib/Target/PowerPC/PPCTargetAsmInfo.cpp
@@ -43,7 +43,6 @@
   PrivateGlobalPrefix = "L";
   ConstantPoolSection = "\t.const\t";
   JumpTableDataSection = ".const";
-  GlobalDirective = "\t.globl\t";
   CStringSection = "\t.cstring";
   FourByteConstantSection = "\t.literal4\n";
   EightByteConstantSection = "\t.literal8\n";
@@ -56,6 +55,7 @@
     StaticDtorsSection = ".mod_term_func";
   }
   UsedDirective = "\t.no_dead_strip\t";
+  WeakDefDirective = "\t.weak_definition\t";
   WeakRefDirective = "\t.weak_reference\t";
   HiddenDirective = "\t.private_extern\t";
   SupportsExceptionHandling = false;
@@ -66,6 +66,7 @@
   DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
   DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
   DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
+  GlobalEHDirective = "\t.globl\t";
   DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
   DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
   DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index fd2e6fb..9ea796b 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -75,6 +75,7 @@
   HasDotTypeDotSizeDirective(true),
   UsedDirective(0),
   WeakRefDirective(0),
+  WeakDefDirective(0),
   HiddenDirective("\t.hidden\t"),
   ProtectedDirective("\t.protected\t"),
   AbsoluteDebugSectionOffsets(false),
@@ -89,6 +90,7 @@
   DwarfInfoSection(".debug_info"),
   DwarfLineSection(".debug_line"),
   DwarfFrameSection(".debug_frame"),
+  GlobalEHDirective(0),
   DwarfPubNamesSection(".debug_pubnames"),
   DwarfPubTypesSection(".debug_pubtypes"),
   DwarfStrSection(".debug_str"),
diff --git a/lib/Target/X86/X86ATTAsmPrinter.cpp b/lib/Target/X86/X86ATTAsmPrinter.cpp
index 5575ee7..a78a898 100644
--- a/lib/Target/X86/X86ATTAsmPrinter.cpp
+++ b/lib/Target/X86/X86ATTAsmPrinter.cpp
@@ -124,7 +124,7 @@
       // FIXME: This should be parameterized somewhere.
       EmitAlignment(4, F, 0, true, 0x90);
       O << "\t.globl\t" << CurrentFnName << "\n";
-      O << "\t.weak_definition\t" << CurrentFnName << "\n";
+      O << TAI->getWeakDefDirective() << CurrentFnName << "\n";
     } else if (Subtarget->isTargetCygMing()) {
       EmitAlignment(4, F);     // FIXME: This should be parameterized somewhere.
       O << "\t.globl\t" << CurrentFnName << "\n";
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp
index 078709b..31e5010 100644
--- a/lib/Target/X86/X86AsmPrinter.cpp
+++ b/lib/Target/X86/X86AsmPrinter.cpp
@@ -214,7 +214,7 @@
     case GlobalValue::WeakLinkage:
       if (Subtarget->isTargetDarwin()) {
         O << "\t.globl\t" << name << "\n"
-          << "\t.weak_definition " << name << "\n";
+          << TAI->getWeakDefDirective() << name << "\n";
         SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
       } else if (Subtarget->isTargetCygMing()) {
         std::string SectionName(".section\t.data$linkonce." +
diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp
index 05cf2bf..44c1432 100644
--- a/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -76,6 +76,7 @@
     SetDirective = "\t.set";
     PCSymbol = ".";
     UsedDirective = "\t.no_dead_strip\t";
+    WeakDefDirective = "\t.weak_definition\t";
     WeakRefDirective = "\t.weak_reference\t";
     HiddenDirective = "\t.private_extern\t";
     
@@ -92,6 +93,7 @@
     DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
     DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
     DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
+    GlobalEHDirective = "\t.globl\t";
     DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
     DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
     DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";