On Thu, May 24, 2018 at 11:57 AM, Luís Marques <
luism...@gmail.com> wrote:
> I'm trying to add exception handling support to the LLVM's RISC-V backend,
> to be able to properly support D's runtime and standard libraries, but I've
> run into a puzzling behavior of libgcc's _Unwind_RaiseException.
Yes, it is broken. It looks like stack unwinding has mostly been
working by accident for us. I traced the problem to the
implementation of the __builtin_eh_return function in the RISC-V
backend. The code was copied from the MIPS port. It is using the
first four arg registers for EH data, and then saving them in the
prologue and restoring them in the epilogue. The MIPS port however
has separate function return value regs from the argument registers,
so it works. In the RISC-V port, the function return value regs
overlap the argument regs, so this is clobbering the function return
value in the epilogue, which is the problem you noticed. We could
change the registers, but that might be an ABI change. I'm not sure
if anyone outside libgcc cares about the registers used here,
builtin_eh_return isn't supposed to be called by users. I also think
that saving/restoring these register is not required, because they are
call clobbered regs to begin with. That looks like a safer change,
but that will take some time to test. And I need to read through a
lot of code and make sure I correctly understand what is going on
here.
Untested patch attached that may or may not work.
Jim