iphone + LDC, a new ARM adventure

David Nadlinger code at klickverbot.at
Mon Jan 6 05:06:19 PST 2014


Hi Dan, Hi Jacob,

On Sun, Jan 5, 2014 at 6:28 PM, Dan Olson <zans.is.for.cans at yahoo.com> wrote:
> Jacob Carlborg <doob at me.com> writes:
>> Hmm, I would have thought iOS used DWARF-based exception handling.
>
> Hi Jacob.
>
> Yeah, I probably have called it wrong as I am just learning about
> exception handling implementations.

No, even though I'm no expert for iOS development, from reading
through the related LLVM code when implementing LDC/MinGW exception
handling I'm fairly sure that SJLJ-style exception handling is used
there. At least, the extra function calls emitted in the fast (non-EH)
path are a sure sign that it is not the standard DWARF scheme.

Why would you think otherwise, Jacob? Including more context with your
messages would make a fair amount of them infinitely more useful…

> clangc c++ exception handling for
> C++ armv7-apple-darwin is emitting __gxx_personality_sj0 and plugs in
> _Unwind_SjLj_Register/_Unwind_SjLj_Unregister.  Perhaps those are just
> for catching C code longjmps?

They are for (un)registering the exception handling context with the
global table of active handlers. The parameter to
_Unwind_SjLj_Register is constructed by the setjmp() part of SJLJ
(it's in fact an optimized, inlined version instead of an actual
function call).  When an exception is raised, this global linked list
is walked, calling the personality functions for the respective
entries to determine whether to longjmp to them.

> I read llvm source code for a while yesterday and really haven't wrapped
> by brain around it yet.

I'd start out by getting a feel for the LLVM IR we need to generate.
For this, you can have a look at the respective Clang output (-S
-emit-llvm). The LLVM docs also have a page on the subject, but
unfortunately, it is rather sparse:
http://llvm.org/docs/ExceptionHandling.html#setjmp-longjmp-exception-handling

The more involved part will likely be to get the personality function
right. Fortunately, at least the related parts of libunwind are open
source: http://www.opensource.apple.com/source/libunwind/libunwind-35.3/src/Unwind-sjlj.c.
The source for the GCC/Clang personality function
(__gxx_personality_sj0) is probably available somewhere as well, but I
don't know where to look right now (libc++, probably).

David



More information about the digitalmars-d-ldc mailing list