David Chisnall via llvm-dev
2018-Jan-16 10:39 UTC
[llvm-dev] Exception handling support for a target
On 16 Jan 2018, at 10:18, Tim Northover via llvm-dev <llvm-dev at lists.llvm.org> wrote:> >> Is the above list complete? Do I understand their purpose correctly (sort >> of)? > > There are components in libunwind (especially) and compiler-rt you'll > also need to look at if you're not on top of an existing runtime.The libUnwind parts are relatively small. You need to write two assembly functions, one which dumps all registers to memory and one which restores them. Next you need to add enum values for all of your registers that correspond to their DWARF register numbres. You then need to implement a C++ class that sets and gets register values from the in-memory structure based on the DWARF number. This is usually quite small because the easiest way of dumping the registers is to store each register set contiguously in memory in the same order that as their DWARF numbers, so you end up with a struct something like this: struct MyArch_Regs { int64_t GPRs[32]; }; And the get function is just doing GPRs[RegNo - MyArch_GPR0]. LLVM’s libUnwind has a very clean structure. Adding MIPS support took a couple of hours. All of the unwinder support is generic other than the mapping from DWARF register numbers to some concrete mechanism for getting and setting them. David
Nemanja Ivanovic via llvm-dev
2018-Jan-16 11:28 UTC
[llvm-dev] Exception handling support for a target
I'd like to thank Tim and David for answering this and Chenwj for asking. I personally don't know much at all about exception handling in LLVM - it's something that was implemented for my target before I started working on it. The information you provided is concise, clear and a great start for getting a handle on how it all comes together in the back end. In addition to thanking you for providing the info, I'm writing in the hopes that there is some documentation that exists or that someone is willing to add to http://llvm.org/docs/ExceptionHandling.html (or a more appropriate place with a link there) that would cover the back end (target-specific) aspects of EH. Perhaps just a quick description of what a target needs to do to get EH working. Nemanja On Tue, Jan 16, 2018 at 11:39 AM, David Chisnall via llvm-dev < llvm-dev at lists.llvm.org> wrote:> On 16 Jan 2018, at 10:18, Tim Northover via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > > >> Is the above list complete? Do I understand their purpose correctly > (sort > >> of)? > > > > There are components in libunwind (especially) and compiler-rt you'll > > also need to look at if you're not on top of an existing runtime. > > The libUnwind parts are relatively small. You need to write two assembly > functions, one which dumps all registers to memory and one which restores > them. Next you need to add enum values for all of your registers that > correspond to their DWARF register numbres. You then need to implement a > C++ class that sets and gets register values from the in-memory structure > based on the DWARF number. This is usually quite small because the easiest > way of dumping the registers is to store each register set contiguously in > memory in the same order that as their DWARF numbers, so you end up with a > struct something like this: > > struct MyArch_Regs > { > int64_t GPRs[32]; > }; > > And the get function is just doing GPRs[RegNo - MyArch_GPR0]. > > LLVM’s libUnwind has a very clean structure. Adding MIPS support took a > couple of hours. All of the unwinder support is generic other than the > mapping from DWARF register numbers to some concrete mechanism for getting > and setting them. > > David > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180116/6919d1a9/attachment.html>
2018-01-16 18:39 GMT+08:00 David Chisnall <David.Chisnall at cl.cam.ac.uk>:> On 16 Jan 2018, at 10:18, Tim Northover via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > > > >> Is the above list complete? Do I understand their purpose correctly > (sort > >> of)? > > > > There are components in libunwind (especially) and compiler-rt you'll > > also need to look at if you're not on top of an existing runtime. > > The libUnwind parts are relatively small. You need to write two assembly > functions, one which dumps all registers to memory and one which restores > them. Next you need to add enum values for all of your registers that > correspond to their DWARF register numbres. You then need to implement a > C++ class that sets and gets register values from the in-memory structure > based on the DWARF number. This is usually quite small because the easiest > way of dumping the registers is to store each register set contiguously in > memory in the same order that as their DWARF numbers, so you end up with a > struct something like this: > > struct MyArch_Regs > { > int64_t GPRs[32]; > }; > > And the get function is just doing GPRs[RegNo - MyArch_GPR0]. > > LLVM’s libUnwind has a very clean structure. Adding MIPS support took a > couple of hours. All of the unwinder support is generic other than the > mapping from DWARF register numbers to some concrete mechanism for getting > and setting them.Thanks for the hint, David. Right now I just leverage on existing runtime (libstdc++ and libgcc). Your hint would help if I move to libUwind. -- 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/5e8879cd/attachment.html>
> In addition to thanking you for providing the info, I'm writing in the > hopes that there is some documentation that exists or that someone is > willing to add to http://llvm.org/docs/ExceptionHandling.html (or a more > appropriate place with a link there) that would cover the back end > (target-specific) aspects of EH. Perhaps just a quick description of what a > target needs to do to get EH working. >The link you gave mostly focus on IR level , I believe. http://llvm.org/docs/WritingAnLLVMBackend.html would be more appropriate. -- 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/3b21da08/attachment.html>