[llvm-dev] How do SJLJ-Exceptions works?

Gaier, Bjoern via llvm-dev llvm-dev at lists.llvm.org
Mon Feb 10 07:30:43 PST 2020


Hello Clang- and LLVM-Experts,

I was not sure which list is the right one, so I tried both - sorry for any inconvenient >o<
Lately I was working a lot with exceptions under Windows and especially with the Clang compiler. Out of curiosity I came along "Exception Handling in LLVM" and tried to understand the SJLJ exception handling. At first glance this made total sense to me! Store important registers and when the exception occurs - restore the saved registers. Kinda like setjump and longjump but with less registers.

However, there are two things I really don't understand (about exception handling in general). I guess it works something like that:
When I execute a function with a try-catch segment, as soon as I hit the try statement (Pretending I'm a Debugger or so), I would save the registerts (RSP, RIP of the catch block) on the stack I guess and keep doing what I do. However, when I encounter an exception now - how do I know where to find my stored registers on the stack? In the mean time I could had millions of push instructions so it can't be an offset. Also I can't imagine that the stack is marked somehow - like with a special bit pattern, risk would be to high that someone else uses that pattern. So I wonder... what is the secret behind it? Also is that the mysterious 'stack unwinding' I often heard about?

Thank you for any tip and help in advance!
Kind greetings
Björn


Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200210/ddad12e9/attachment-0001.html>


More information about the llvm-dev mailing list