2018-01-16 21:03 GMT+08:00 Tim Northover <t.p.northover at gmail.com>:> On 16 January 2018 at 12:23, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> wrote: > > Do we have to emit directives in the epilogue, too? One of my test case > fail > > due to the directives in the epilogue have been executed. After removing > > them from epilogue, the exception is caught as expected. > > Emitting directives in the epilogue is hard because the directives > apply to all instructions after in program-counter order. So if you > have an epilogue in the middle of a function and emit CFI directives > saying the registers are back where they were then the unwinder will > think that applies to the rest of the function too. > > To fix that you'd have to emit yet more directives in the basic block > immeditately following the epilogue. Most people don't bother with > either because you'd only really need it if you expected to have to > catch an exception in the epilogue (which is impossible on most > platforms).My test case is: void foo() { throw 0; } void bar() { try { foo(); } catch (...) { throw 0; } } int main() { try { bar(); } catch (...) { return 0; // fail to catch exception thrown by bar } return 0; } , and the assembly of bar looks like bar: .cfi_def_cfa_offset 16 epilogue _Unwind_Resume The lookup phase of exception handling is fine. However, something goes wrong in cleanup phase. The reason is the unwinder evaluates CFI directives until _Unwind_Resume, and `.cfi_def_cfa_offset 16` is the culprit. I think this is what you were saying "have an epilogue in the middle of a function", right? -- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180116/2ed0f8f9/attachment.html>
Tim Northover via llvm-dev
2018-Jan-16 19:41 UTC
[llvm-dev] Exception handling support for a target
On 16 January 2018 at 13:41, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> wrote:> bar: > > .cfi_def_cfa_offset 16 > epilogue > > _Unwind_Resume > > > > The lookup phase of exception handling is fine. However, something goes > wrong in cleanup phase. The reason is the unwinder evaluates CFI directives > until _Unwind_Resume, and `.cfi_def_cfa_offset 16` is the culprit. I think > this is what you were saying "have an epilogue in the middle of a function", > right?I think so, though the assembly isn't really complete enough to tell. In this case if the .cfi_def_cfa_offset is describing the epilogue it would mean that all code in what you've labelled _Unwind_Resume (assuming that's actually a cleanup landing pad or something) will use the wrong SP to load the saved registers from. The unwinder will think it's executing directly after the epilogue since it's later on in the function. Cheers. Tim.
Time, David and Nemanja, I add you as the reviewer for https://reviews.llvm.org/D42178 , feel free to comment on it. Alex, could you add D42178 into your review corner? I hope someone who has more exception handling experience can review on it as well. Thanks. 2018-01-17 3:41 GMT+08:00 Tim Northover <t.p.northover at gmail.com>:> On 16 January 2018 at 13:41, 陳韋任 <chenwj.cs97g at g2.nctu.edu.tw> wrote: > > bar: > > > > .cfi_def_cfa_offset 16 > > epilogue > > > > _Unwind_Resume > > > > > > > > The lookup phase of exception handling is fine. However, something goes > > wrong in cleanup phase. The reason is the unwinder evaluates CFI > directives > > until _Unwind_Resume, and `.cfi_def_cfa_offset 16` is the culprit. I > think > > this is what you were saying "have an epilogue in the middle of a > function", > > right? > > I think so, though the assembly isn't really complete enough to tell. > In this case if the .cfi_def_cfa_offset is describing the epilogue it > would mean that all code in what you've labelled _Unwind_Resume > (assuming that's actually a cleanup landing pad or something) will use > the wrong SP to load the saved registers from. The unwinder will think > it's executing directly after the epilogue since it's later on in the > function. > > Cheers. > > Tim. >-- Wei-Ren Chen (陳韋任) Homepage: https://people.cs.nctu.edu.tw/~chenwj -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180117/6ab3a042/attachment.html>