What is __builtin_dwarf_cfa()?

Hi All,

  While compiling libgcc with LLVM for our target, it seems I don't
get __builtin_dwarf_cfa() right. That causes uw_init_context_1 [1]
initialize the wrong context, and the overall exception handling fail.
I find Hal provided patch years ago adding ISD::EH_DWARF_CFA, which
corresponding to __builtin_dwarf_cfa(), and let us have the
opportunity to handle __builtin_dwarf_cfa() for our own [2].

  I copy Mips' lowerEH_DWARF_CFA for our target, and it *just* works
[3]. I have to admit that I don't understand what Hal explained in his
patch, also don't know why Mips code work for ours. Here I have two

    1. What is __builtin_dwarf_cfa()?

          What I know about CFA (Canonical Frame Address) is, it's a
base address which we can restore registers for the caller frame. Why
do we have to call __builtin_dwarf_cfa() for uw_init_context_1, I
don't see the connection between them.

    2. Why Mips code works for our target?

         Okay... Maybe when I fully understand the answer of question
1, I can answer this by myself. But what does Mips' lowerEH_DWARF_CFA?
And why only PowerPC and Mips have to lower EH_DWARF_CFA by


P.S. ASCII art might be help on explaining the whole thing. :wink:

[1] gcc/unwind-dw2.c at master · gcc-mirror/gcc · GitHub
[2] rG5081ac27c755
[3] http://llvm.org/doxygen/MipsISelLowering_8cpp_source.html