Win64 exception handling

Kai Nacke via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Tue Mar 24 04:48:44 PDT 2015


On Monday, 23 March 2015 at 22:55:18 UTC, Johan Engelen wrote:
> Hi all,
>   I have been trying to work on exception handling on Windows 
> x64 (with LLVM 3.6), but for a long time now, I am stuck on 
> something perhaps very simple.
>
> My test case is this program:
> int main() {
>     try {
>         throw new Exception("johan");
>     } catch (Exception jow) {
>     }
>     return 0;
> }
>
> This crashes, and Visual Studio's debugger tells me it's 
> because of an unhandled exception. As far as I understand it, 
> we call RtlRaiseException() from _d_throw_exception() and that 
> should call the personality function _d_eh_personality(). 
> However, _d_eh_personality() is never entered. Instead, 
> RtlRaiseException() returns and the program crashes. I am stuck 
> on how to continue from here. I have tried many different 
> things, but I cannot get the OS to call _d_eh_personality().
>
> One thing that strikes me is that the exception code 
> STATUS_LDC_D_EXCEPTION is passed to RtlRaiseException(), but is 
> not used anywhere else in our source.
> Does LLVM not correctly register _d_eh_personality() with the 
> OS? Or is there some filtering done on the exception code?
>
> I'd appreciate any help.
>
> -Johan

Hi Johan!

A quick check revealed: it works with current LLVM trunk but not 
with 3.6. I hvae no clue why.

The connection between RtlRaiseException() and 
_d_eh_personality() is the unwind information. You can 
"disassemble" the unwind information with llvm-objdump -u. If the 
code range is wrong or some other data is corrupt then the 
personality function is not called. You should also disassemble 
the object file and check .xdata and .pdata sections.

(The unwind information from LLVM 3.6 has no flag set. I believe 
that at least UNW_ExceptionHandler must be set.)

Regards,
Kai


More information about the digitalmars-d-ldc mailing list