[llvm-dev] setjmp/longjmp and volatile stores, but non-volatile loads

Jonas Maebe via llvm-dev llvm-dev at lists.llvm.org
Sun Dec 18 05:23:01 PST 2016


On 30/09/16 20:10, Reid Kleckner wrote:
> On Mon, Sep 19, 2016 at 4:42 AM, Jonas Maebe <jonas-devlists at watlock.be
> <mailto:jonas-devlists at watlock.be>> wrote:
>
>     So, can I use invoke and landingpad without using any of the other
>     exception handling intrinsics? (in combination with a dummy personality
>     function) Or will LLVM in all cases insist on using ehframe information,
>     a (C++-)ABI-compliant personality function, and possibly linking in
>     parts of its own runtime that depend on this information being correct?
>
>
> I would say that the coupling between LLVM generated code and the HP
> unwind interface is pretty low. The only call LLVM emits is to
> _Unwind_Resume, so you would have to go into
> llvm/lib/CodeGen/DwarfEHPrepare.cpp and teach LLVM what you want it to
> call in your runtime for your EH personality.

I thought I had finally figured out how to dance around this, but while 
I got close, it's not perfect :/

Recap: we use setjmp/longjmp for our exception handling on all platforms 
in our regular (non-LLVM) code generators. I'd like to use the same 
infrastructure with the LLVM code generator for code interoperability 
purposes (the LLVM SjLj personality is not binary-compatible with our 
existing setjump/longjump buffers).

What I did was:
1) create a dummy personality function in our run time library that 
basically always says "no, this frame does not wish to handle this 
exception nor does it have any clean-up code", and specify it as 
personality function for any function that deals with exceptions
2) create a BBL with a landingpad and no other code at the end of every 
try-block
3) in the try-blocks themselves, replace all calls with invokes that 
unwind to this landingpad BBL

Then, I tried the following:
a) if the longjmp for the try-block is taken (i.e., the setjmp right 
before the try-block returns a non-zero value), jump to the landingpad BBL.

-> Problem: LLVM does not allow regular jump edges to landingpad BBLs

b) since the landingpad is empty anyway and falls through into the next 
BBL (which contains the start of our actual exception handling code), 
jump to that next BBL from setjmp.

-> Problem: even though I do not insert code in the landingpad BBLs, 
LLVM may still add code to them, e.g. for (LLVM-created) phi-nodes.

I can't think of any solution to deal with this :/


Jonas



More information about the llvm-dev mailing list