Microsoft C++ exception handling.

Hi all!

For C++ EH cl build stub __ehhandler$mangled_function_name (for each function with EH).
This stub consist of 2 instructions:
__ehhandler$_main:
mov eax,offset __TI1?AUmy_exception1@@+50h (address of __ehfuncinfo)
jmp @ILT+395(___CxxFrameHandler3)

How can I implement this behavior?

Thanks in advance.
  - Dmitry Sokolov.

Could you be more specific? What are you stuck on?

Is this for SEH or for Win64 exceptions?

John.

Yes, this is SEH.

This code does not use stack to forward __ehfuncinfo to CxxFrameHandler, so my problem is how can I tell llvm that I need store address in
eax and then jump to CxxFrameHandler.

Maybe I need new intrinsic function?

  - Dmitry Sokolov.

For C++ EH cl build stub __ehhandler$mangled_function_name (for each
function with EH).
This stub consist of 2 instructions:
__ehhandler$_main:
mov eax,offset __TI1?AUmy_exception1@@+50h (address of __ehfuncinfo)
jmp @ILT+395(___CxxFrameHandler3)

How can I implement this behavior?

Is this for SEH or for Win64 exceptions?

Yes, this is SEH.

We can't accept code to implement this. If you want to work on this privately, that's your business, of course, but understand that the LLVM project cannot take any such code in our repository until we get legal sign-off.

This code does not use stack to forward __ehfuncinfo to CxxFrameHandler, so my problem is how can I tell llvm that I need store address in
eax and then jump to CxxFrameHandler.

If we ever implement SEH in clang — and my understanding is that all the relevant patents are within a few years of expiring, but that is not a legally informed opinion — then the appropriate design is to lower this in the backend. We've tried to architect the IR for exceptions to support lowering to different formats; of course, it's quite possible that we'll find that we've missed a few subtleties.

John.

I just learned about the inreg LLVM parameter attribute, which seems to do this.

declare external
void @___CxxFrameHandler3(i32* inreg nocapture) nounwind

@EHFuncInfo = global i32 0, align 4

define void @main() {
tail call void @___CxxFrameHandler3(i32* @EHFuncInfo)
ret void
}

generates:

_main: # @main
movl $_EHFuncInfo, %eax
jmp ____CxxFrameHandler3 # TAILCALL

Thnaks, this is what I need.

  - Dmitry Sokolov.

Thanks for clarification.

  - Dmitry Sokolov.