[LLVMdev] Getting exceptions to work?

Talin viridia at gmail.com
Sun May 24 00:41:10 PDT 2009

Well, after much labor, I think I have managed to create a personality 
function that works. But I must say it is frightening how complicated 
all of this stuff is.

-- Talin

Duncan Sands wrote:
> Hi Talin, if you change @throwSomething so that it prints a message
> if the _Unwind_RaiseException call returns, then you will see that
> it does in fact return.
> define internal fastcc void @throwSomething() {
> entry:
>          %throwable = malloc %Throwable
>          call fastcc void @Throwable.construct(%Throwable* %throwable)
>          %unwindInfo = getelementptr %Throwable* %throwable, i32 0, i32 1
>          call void @print(i8* bitcast ([6 x i8]* @str_throw to i8 *))
>          %throw = call i32 @_Unwind_RaiseException(%UnwindInfo* %unwindInfo)
>          call void @print(i8* bitcast ([6 x i8]* @str_abort to i8 *))
>          ret void
> }
> This is because it unwound the stack without finding any exception
> handlers.  It doesn't consider your exception handler to be a handler
> because it is registered as a "cleanup" which apparently doesn't count.
> (To force cleanups to be run in this situation you have to call the gcc
> forced unwind routine after calling Unwind_RaiseException).
> Of course you would probably like to have your handler be considered a
> real handler.  Sadly you can't use __gcc_personality_v0 for this: it
> only handles cleanups, and if it sees something else (eg: if you specify
> a catch-all in the selector) then it tells the unwinder to keep on
> unwinding, which is not what you want.
> So indeed you either need to write your own personality routine or use
> a more powerful personality function like the C++ personality, and use
> an eh.selector call to specify a catch-all (use null for this).
> In order to get correct invoke semantics, LLVM really needs its own
> personality function.  The problem is that LLVM doesn't have its own
> runtime library like libgcc.  This could be overcome by outputting the
> LLVM personality into each assembler file that needs it, with weak
> linkage so that multiple copies get collapsed to one at link time.
> Ciao,
> Duncan.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list