<div dir="ltr">Oh, apparently we did this:<div><br></div><div><div>void WinException::endModule() {</div><div>  auto &OS = *Asm->OutStreamer;</div><div>  const Module *M = MMI->getModule();</div><div>  for (const Function &F : *M)</div><div>    if (F.hasFnAttribute("safeseh"))</div><div>      OS.EmitCOFFSafeSEH(Asm->getSymbol(&F));</div><div>}</div></div><div><br></div><div>And we add the attribute in the state number store insertion pass.  That's not very discoverable. :(</div><div><br></div><div>So, I guess just add the "safeseh" string attribute to your personality declaration and you're set.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 20, 2018 at 11:04 AM Carlo Kok <<a href="mailto:ck@remobjects.com">ck@remobjects.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>





<div><div>Indeed, it's 32bits x86 and there's no .safeseh or anything like it, even readobj -coff-load-config says nothing:<br></div>
<div><br></div>
<div>File: ConsoleApplication830.exe<br></div>
<div>Format: COFF-i386<br></div>
<div>Arch: i386<br></div>
<div>AddressSize: 32bit<br></div>
<div><br></div>
<div><br></div>
<div>Now I know what to look for, thanks!<br></div>
<div><br></div>
<div><br></div>
<div>On Mon, Aug 20, 2018, at 18:46, Reid Kleckner wrote:<br></div>
<blockquote type="cite"><div dir="ltr"><div>This is 32-bit x86, right? Sounds like the exception handler did not appear in the /safeseh table.<br></div>
<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.<br></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.<br></div>
</div>
<div><br></div>
<div><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" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div>
<blockquote style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-color:rgb(204,204,204);border-left-style:solid;border-left-width:1px;padding-left:1ex"><div>Hi,<br></div>
<div> <br></div>
<div> I'm getting:<br></div>
<div> <br></div>
<div> Unhandled exception at 0x00C211F0 in ConsoleApplication830.exe: 0xC00001A5: An invalid exception handler routine has been detected (parameters: 0x00000001).<br></div>
<div> <br></div>
<div> With some fairly simple SEH enabled routine:<br></div>
<div> <br></div>
<div> 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></div>
<div> BasicBlock0:<br></div>
<div>   %1 = alloca %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s*<br></div>
<div>   store %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s* %0, %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s** %1<br></div>
<div>   call void @llvm.dbg.declare(metadata %._gt2a_RemObjects_d_Elements_d_System_d_Array_t_1s** %1, metadata !86, metadata !DIExpression()), !dbg !88<br></div>
<div>   %csLoc0 = alloca i32, !dbg !88<br></div>
<div>   store i32 0, i32* %csLoc0, !dbg !88<br></div>
<div>   br label %BasicBlock1, !dbg !88<br></div>
<div> <br></div>
<div> BasicBlock1:                                      ; preds = %BasicBlock0<br></div>
<div>   call void @llvm.dbg.declare(metadata i32* %csLoc0, metadata !89, metadata !DIExpression()), !dbg !91<br></div>
<div>   store i32 0, i32* %csLoc0, !dbg !91<br></div>
<div>   invoke void @ms_t1d_ConsoleApplication4_d_Program2_m1()<br></div>
<div>           to label %BasicBlock2 unwind label %2, !dbg !92<br></div>
<div> <br></div>
<div> BasicBlock2:                                      ; preds = %BasicBlock1<br></div>
<div>   br label %BasicBlock3, !dbg !93<br></div>
<div> <br></div>
<div> ; <label>:2:                                      ; preds = %BasicBlock1<br></div>
<div>   %3 = catchswitch within none [label %BasicBlock4] unwind to caller, !dbg !93<br></div>
<div> <br></div>
<div> BasicBlock3:                                      ; preds = %BasicBlock5, %BasicBlock2<br></div>
<div>   %4 = load i32, i32* %csLoc0, !dbg !94<br></div>
<div>   ret i32 %4, !dbg !94<br></div>
<div> <br></div>
<div> BasicBlock4:                                      ; preds = %2<br></div>
<div>   %5 = catchpad within %3 [{ i8*, i8* }* @0, i32 0, i8* null], !dbg !93<br></div>
<div>   catchret from %5 to label %BasicBlock5, !dbg !95<br></div>
<div> <br></div>
<div> BasicBlock5:                                      ; preds = %BasicBlock4<br></div>
<div>   br label %BasicBlock3, !dbg !95<br></div>
<div> <br></div>
<div> BasicBlock6:                                      ; No predecessors!<br></div>
<div>   unreachable, !dbg !94<br></div>
<div> }<br></div>
<div> <br></div>
<div> <br></div>
<div> (_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></div>
<div> <br></div>
<div> 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></div>
<div> <br></div>
<div> 0x00C211F0  DOES point to the generated code used for SEH:<br></div>
<div> <br></div>
<div> 00C211F0 | 57                       | push edi                                                   |<br></div>
<div> 00C211F1 | 56                       | push esi                                                   |<br></div>
<div> 00C211F2 | 83EC 10                  | sub esp,10                                                 |<br></div>
<div> 00C211F5 | 8B4424 28                | mov eax,dword ptr ss:[esp+28]                              |<br></div>
<div> 00C211F9 | 8B4C24 24                | mov ecx,dword ptr ss:[esp+24]                              |<br></div>
<div> 00C211FD | 8B5424 20                | mov edx,dword ptr ss:[esp+20]                              |<br></div>
<div> 00C21201 | 8B7424 1C                | mov esi,dword ptr ss:[esp+1C]                              |<br></div>
<div> 00C21205 | BF 54DCC800              | mov edi,consoleapplication830.C8DC54                       |<br></div>
<div> 00C2120A | 894424 0C                | mov dword ptr ss:[esp+C],eax                               |<br></div>
<div> 00C2120E | 89F8                     | mov eax,edi                                                |<br></div>
<div> 00C21210 | 897424 08                | mov dword ptr ss:[esp+8],esi                               |<br></div>
<div> 00C21214 | 894C24 04                | mov dword ptr ss:[esp+4],ecx                               |<br></div>
<div> 00C21218 | 891424                   | mov dword ptr ss:[esp],edx                                 |<br></div>
<div> 00C2121B | 83C4 10                  | add esp,10                                                 |<br></div>
<div> 00C2121E | 5E                       | pop esi                                                    |<br></div>
<div> 00C2121F | 5F                       | pop edi                                                    |<br></div>
<div> 00C21220 | E9 7B270100              | jmp <consoleapplication830.RemObjects.Elements.System.Exte |<br></div>
<div> <br></div>
<div> Which seems fine.<br></div>
<div> _______________________________________________<br></div>
<div> LLVM Developers mailing list<br></div>
<div> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br></div>
<div> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br></div>
</blockquote></div>
</blockquote><div><br></div>
</div>

</blockquote></div>