Emit unused EH frames for weak definitions on Darwin,
because assembler/linker can't cope with weak absolutes.
PR 1880.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45811 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp
index c1091e9..1f7618a 100644
--- a/lib/CodeGen/DwarfWriter.cpp
+++ b/lib/CodeGen/DwarfWriter.cpp
@@ -2877,18 +2877,25 @@
         O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
     }
 
-    // If there are no calls then you can't unwind.
-    if (!EHFrameInfo.hasCalls) { 
+    // If corresponding function is weak definition, this should be too.
+    if ((EHFrameInfo.linkage == Function::WeakLinkage || 
+         EHFrameInfo.linkage == Function::LinkOnceLinkage) &&
+        TAI->getWeakDefDirective())
+      O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
+
+    // If there are no calls then you can't unwind.  This may mean we can
+    // omit the EH Frame, but some environments do not handle weak absolute
+    // symbols.
+    if (!EHFrameInfo.hasCalls &&
+        ((EHFrameInfo.linkage != Function::WeakLinkage && 
+          EHFrameInfo.linkage != Function::LinkOnceLinkage) ||
+         !TAI->getWeakDefDirective() ||
+         TAI->getSupportsWeakOmittedEHFrame()))
+    { 
       O << EHFrameInfo.FnName << " = 0\n";
     } else {
       O << EHFrameInfo.FnName << ":\n";
 
-      // If corresponding function is weak definition, this should be too.
-      if ((EHFrameInfo.linkage == Function::WeakLinkage || 
-           EHFrameInfo.linkage == Function::LinkOnceLinkage) &&
-          TAI->getWeakDefDirective())
-        O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
-
       // EH frame header.
       EmitDifference("eh_frame_end", EHFrameInfo.Number,
                      "eh_frame_begin", EHFrameInfo.Number, true);