[LLVMdev] Darwin vs exceptions

Dale Johannesen dalej at apple.com
Fri Dec 7 16:40:50 PST 2007

So I couldn't get exceptions to work on PPC darwin.  After much  
digging and confusion, there seem
to be two separate issues.

The gcc testsuite is running the version of the unwinding code that  
was built with the local (llvm-)gcc,
which doesn't work because nobody has implemented  
builtin_return_address for that target.
So that's one problem.

More seriously, the version of the unwinding code installed on the  
system doesn't work either, for a
different reason (and also doesn't work on x86 Darwin).   It turns out  
the installed code has the
following patch, which is not in the llvm-gcc source (or Apple's gcc  
sources for that matter; libgcc
lives in a separate repository these days):

Index: gcc/unwind-dw2.c
--- gcc/unwind-dw2.c    (revision 124749)
+++ gcc/unwind-dw2.c    (working copy)
@@ -1526,7 +1526,7 @@
  static inline _Unwind_Ptr
  uw_identify_context (struct _Unwind_Context *context)
-  return _Unwind_GetIP (context);
+  return _Unwind_GetCFA (context);

I'm uncertain of the merit of this patch, but it's in shipping Leopard  
and works with gcc, so we're
stuck with it.

The effect of this is that llvm's strategy of making every C++  
selector claim that it has a catch-all
handler at the end, as described here
does not work in this environment.   Claiming that a function has a  
catch-all handler when it does
not causes the unwinder to go into a loop.  I tried simply removing  
the code that does this:

Index: cp/except.c
--- cp/except.c	(revision 44663)
+++ cp/except.c	(working copy)
@@ -104,7 +104,7 @@
    lang_eh_runtime_type = build_eh_type_type;
    lang_protect_cleanup_actions = &cp_protect_cleanup_actions;
    /* LLVM local */
-  lang_eh_catch_all = return_null_tree;
+/*  lang_eh_catch_all = return_null_tree;*/

  /* Returns an expression to be executed if an unhandled exception is

and that works well for me; i.e., the gcc tests that exercise  
exceptions work as well with the
two patches above (on x86) as they did before.

Now I need some help:
- Why was C++ claiming that every selector has a catch-all handler?   
The documentation above just says
the C++ personality function will terminate the program if it detects  
that unwinding the exception only results in matches with cleanups.
Isn't that what's supposed to happen if there's no handler anywhere?
- What is the right thing for Linux?  Is the deletion above safe there?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20071207/9bb08cf8/attachment.html>

More information about the llvm-dev mailing list