This is the first attempt to write down a guideline on adding exception handling support for a target. The content basically bases on the discussion on . If you guys know who is exception handling expert, please add him as the reviewer. Thanks.
Thank you very much for making a start on this!
|853 ↗||(On Diff #130166)|
Most of this is generic code. The important thing for the back end is to make sure that every register has a unique DWARF number.
In your TargetFrameLowering's emitPrologue method, you must add the .cfi_def_cfa_offset directive for the frame and then the .cfi_def_cfa_register or similar to tell the unwinder the base address for all subsequent offsets.
|860 ↗||(On Diff #130166)|
Perhaps note that the first of these contains a pointer and the second an integer. On most platforms, they will be GPRs, but on any architecture with distinct address and integer registers the first will likely be an address.
|865 ↗||(On Diff #130166)|
Perhaps document what this does? I believe that it's an undocumented GCC extension that is used only in the GNU unwinder (LLVM's libUnwind doesn't use it). According to comments in the MIPS back end, it is of the form __builtin_eh_return (offset, handler) and adjusts the stack by offset and then jumps to the handler.
|870 ↗||(On Diff #130166)|
It would be good to enumerate the things that are needed to get this working. This diff adds 64-bit MIPS support (soft-float only):
It contains a bug where a couple of registers that should have been saved weren't, but it provides an example of all of the things that you need to add to support a new architecture.
The only difficult thing is correctly setting _LIBUNWIND_CONTEXT_SIZE and _LIBUNWIND_CURSOR_SIZE - you get a compile error that tells you if you got them wrong, but it doesn't tell you what the correct size should be. I did this by temporarily replacing the static_assert with a template that invoked static_assert and gave me the arguments in the failure backtrace.
I'm inclined to recommend that you commit this. It's not perfect, but it's a *lot* better than what was there before, and hopefully having something there will encourage other people to improve it.