[LLVMdev] Failed to catch exception across function calls

Tim Northover t.p.northover at gmail.com
Tue May 5 20:12:01 PDT 2015


> I wonder how should I approach this issue, is there anything in the backend
> that could cause the bug ?

Some cursory research suggests that r1 is the stack pointer on
OpenRISC. You seem to be modifying that (& storing callee-saved
registers?) but not emitting the required .cfi_XYZ directives to tell
the unwinder about those changes.

The way exceptions work is that they need extra information to restore
the CPU state to what it was in each caller until they reach a catch
clause that can handle the exception. This information is provided by
each function saying "I changed sp by X, and stored the registers my
caller expects to be saved at locations Y, Z and W". It does this via
.cfi directives.

This is usually handled in XYZFrameLowering.cpp (though I vaguely
remember x86 uses a separate pass which re-parses the frame to
generate them -- don't quote me on that). I'd suggest searching around
for .cfi_def_cfa and .cfi_offset as the most important two:

  + ".cfi_def_cfa R, off" says "when this function was first called,
SP == R + off".
  + ".cfi_offset R, off" says "to find out what R used to be when the
function was first called, load the value at offset "off" from where
SP was when this function was called.

It's slightly more subtle than that, particularly on CISC
architectures (I'd suggest ignoring x86, for example), but that's the
essence of it. Hopefully you'll also be able to get the hang of it
from what GCC produces.

Cheers.

Tim.



More information about the llvm-dev mailing list