<div dir="ltr">This is 32-bit x86, right? Sounds like the exception handler did not appear in the /safeseh table.<div><br></div><div>If you emit a standalone .s file, do you see something like `.safeseh 

_elements_exception_handler` somewhere in there? If not, that's a problem. I think it would also be a problem if 

_elements_exception_handler is imported. If so, try making a thunk for it.</div><div><br></div><div>You can also try running `dumpbin /loadconfig` (or equivalently llvm-readobj -coff-load-config) on your binary to confirm that the RVA of _elements_exception_handler appears in the safe seh table.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 20, 2018 at 7:00 AM Carlo Kok via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm getting:<br>
<br>
Unhandled exception at 0x00C211F0 in ConsoleApplication830.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000001).<br>
<br>
With some fairly simple SEH enabled routine:<br>
<br>
define i32 @__elements_entry_point_main(%._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s*) #0 personality i8* bitcast (i32 ()* @_elements_exception_handler to i8*) !dbg !61 {<br>
BasicBlock0:<br>
  %1 = alloca %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s*<br>
  store %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s* %0, %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s** %1<br>
  call void @llvm.dbg.declare(metadata %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s** %1, metadata !86, metadata !DIExpression()), !dbg !88<br>
  %csLoc0 = alloca i32, !dbg !88<br>
  store i32 0, i32* %csLoc0, !dbg !88<br>
  br label %BasicBlock1, !dbg !88<br>
<br>
BasicBlock1:                                      ; preds = %BasicBlock0<br>
  call void @llvm.dbg.declare(metadata i32* %csLoc0, metadata !89, metadata !DIExpression()), !dbg !91<br>
  store i32 0, i32* %csLoc0, !dbg !91<br>
  invoke void @ms_t1d_ConsoleApplication4_d_Program2_m1()<br>
          to label %BasicBlock2 unwind label %2, !dbg !92<br>
<br>
BasicBlock2:                                      ; preds = %BasicBlock1<br>
  br label %BasicBlock3, !dbg !93<br>
<br>
; <label>:2:                                      ; preds = %BasicBlock1<br>
  %3 = catchswitch within none [label %BasicBlock4] unwind to caller, !dbg !93<br>
<br>
BasicBlock3:                                      ; preds = %BasicBlock5, %BasicBlock2<br>
  %4 = load i32, i32* %csLoc0, !dbg !94<br>
  ret i32 %4, !dbg !94<br>
<br>
BasicBlock4:                                      ; preds = %2<br>
  %5 = catchpad within %3 [{ i8*, i8* }* @0, i32 0, i8* null], !dbg !93<br>
  catchret from %5 to label %BasicBlock5, !dbg !95<br>
<br>
BasicBlock5:                                      ; preds = %BasicBlock4<br>
  br label %BasicBlock3, !dbg !95<br>
<br>
BasicBlock6:                                      ; No predecessors!<br>
  unreachable, !dbg !94<br>
}<br>
<br>
<br>
(_elements_exception_handler  is my exception handler routine which I added to the LLVM source, compatible with the standard VC++ one). My question is,<br>
<br>
is there something special I need to do to make SEH work (I'm using LLVM LLD to compile it, from 3 months ago, but latest doesn't give a different result)? I can't find anything real about that exception code.<br>
<br>
0x00C211F0  DOES point to the generated code used for SEH:<br>
<br>
00C211F0 | 57                       | push edi                                                   |<br>
00C211F1 | 56                       | push esi                                                   |<br>
00C211F2 | 83EC 10                  | sub esp,10                                                 |<br>
00C211F5 | 8B4424 28                | mov eax,dword ptr ss:[esp+28]                              |<br>
00C211F9 | 8B4C24 24                | mov ecx,dword ptr ss:[esp+24]                              |<br>
00C211FD | 8B5424 20                | mov edx,dword ptr ss:[esp+20]                              |<br>
00C21201 | 8B7424 1C                | mov esi,dword ptr ss:[esp+1C]                              |<br>
00C21205 | BF 54DCC800              | mov edi,consoleapplication830.C8DC54                       |<br>
00C2120A | 894424 0C                | mov dword ptr ss:[esp+C],eax                               |<br>
00C2120E | 89F8                     | mov eax,edi                                                |<br>
00C21210 | 897424 08                | mov dword ptr ss:[esp+8],esi                               |<br>
00C21214 | 894C24 04                | mov dword ptr ss:[esp+4],ecx                               |<br>
00C21218 | 891424                   | mov dword ptr ss:[esp],edx                                 |<br>
00C2121B | 83C4 10                  | add esp,10                                                 |<br>
00C2121E | 5E                       | pop esi                                                    |<br>
00C2121F | 5F                       | pop edi                                                    |<br>
00C21220 | E9 7B270100              | jmp <consoleapplication830.RemObjects.Elements.System.Exte |<br>
<br>
Which seems fine.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>