RISC-V port

Luís Marques luis at luismarques.eu
Thu May 24 14:01:48 UTC 2018


On Wednesday, 23 May 2018 at 16:10:47 UTC, Luís Marques wrote:
> On Wednesday, 23 May 2018 at 15:35:12 UTC, David Nadlinger 
> wrote:
> You know what's silly? I had activated the debug flag `debug = 
> EH_personality`, but that debug code uses printf with varargs, 
> and I hand't yet ported varargs, so that's what was crashing on 
> the D side... arrg!

Consider this code:

extern(C)
void drun()
{
     try
     {
         throw new Exception("throw test");
     }
     catch(Exception e)
     {
         writeln_("caught from D");
     }
}

When an expection is thrown the function _d_throw_exception is 
called. In turn, it calls _Unwind_RaiseException. But that 
function fails, returning a high numeric value that isn't part of 
the expected return type enum (_Unwind_Reason_Code) values. So 
the D exception personality is never called, and the catch block 
is never executed. The only thing that is currently missing in 
the assembly is the CFI stack adjustment directives. But I don't 
think that's what's causing the problem, because 1) when those 
are missing in the C++ code basic exception handling still works, 
and 2) I've tried to manually add those to the assembly file and 
it makes no difference.

I've also tried to make drun only throw a pre-existing __gshared 
global Exception instance object, to simplify the function and 
stack adjustment, but it makes no difference. The problem seems 
to be elsewhere.

Here's the assembly for the following code:

https://gist.github.com/luismarques/238f5bd98f8dfbf9c6356071dfc9c2c5

pragma(LDC_no_moduleinfo);

extern(C) void writeln_(const(char)[] s) nothrow @nogc;

__gshared Exception e;

extern(C)
void allocException()
{
     e = new Exception("test exception");
}

extern(C)
void drun()
{
     try
     {
         throw e;
     }
     catch(Exception e)
     {
         writeln_("caught from D");
     }
}

Any idea on what might be wrong?


More information about the digitalmars-d-ldc mailing list