Hello, I was thinking... Should we mark all registered i386 SEH handlers
for clang with .safeseh asm directive? Because otherwise the /safeseh
clang/llvm switch should refuse to link and generate valid EXE file.

I was thinking about this change, but I'm not really sure.


diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index ca9b0069160c..8bb79b4d33ef 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -156,6 +156,9 @@ __tmainCRTStartup (void)
       .Next = (EXCEPTION_REGISTRATION_RECORD *)__readfsdword (0),
       .Handler = (PEXCEPTION_ROUTINE)(INT_PTR)__mingw_SEH_signal_dispatcher,
     };
+#ifdef __clang__
+    asm volatile (".safeseh %c0" :: "i" (__mingw_SEH_signal_dispatcher));
+#endif
     /* dynamically register SEH error handler; it is active until manually 
unregistered */
     __writefsdword (0, (DWORD)&exception_record);
 #elif defined(SEH_INLINE_ASM)
diff --git a/mingw-w64-crt/misc/__mingw_has_sse.c 
b/mingw-w64-crt/misc/__mingw_has_sse.c
index 4c3ab950fbff..45c8191e3c4c 100644
--- a/mingw-w64-crt/misc/__mingw_has_sse.c
+++ b/mingw-w64-crt/misc/__mingw_has_sse.c
@@ -83,6 +83,9 @@ int __mingw_has_sse(void)
     },
     .illegal_instruction_occured = FALSE,
   };
+#ifdef __clang__
+  __asm__ volatile (".safeseh %c0" :: "i" (illegal_instruction_handler));
+#endif
   __writefsdword (0, (DWORD)&establisher_frame);
   __asm__ volatile ("movaps %%xmm0, %%xmm0" :);
   __writefsdword (0, (DWORD)establisher_frame.exception_record.Next);
diff --git a/mingw-w64-crt/misc/_beginthreadex.c 
b/mingw-w64-crt/misc/_beginthreadex.c
index 3264ff05a134..d1e3370d86a8 100644
--- a/mingw-w64-crt/misc/_beginthreadex.c
+++ b/mingw-w64-crt/misc/_beginthreadex.c
@@ -39,6 +39,9 @@ static DWORD WINAPI thread_func(void *data)
     .Next = (EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0),
     .Handler = (PEXCEPTION_ROUTINE)(INT_PTR)__mingw_SEH_signal_dispatcher,
   };
+#ifdef __clang__
+  asm volatile (".safeseh %c0" :: "i" (__mingw_SEH_signal_dispatcher));
+#endif
   __writefsdword(0, (DWORD)&exception_record);
 #elif defined(SEH_INLINE_ASM)
   asm volatile (".seh_handler %c0, " ASM_SEH_EXCEPT :: "i" 
(__mingw_SEH_signal_dispatcher));
diff --git a/mingw-w64-crt/misc/i386__beginthread.c 
b/mingw-w64-crt/misc/i386__beginthread.c
index 150b0f3d6ec6..6bc8298baad2 100644
--- a/mingw-w64-crt/misc/i386__beginthread.c
+++ b/mingw-w64-crt/misc/i386__beginthread.c
@@ -27,6 +27,9 @@ static void __cdecl thread_func(void *data)
     .Next = (EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0),
     .Handler = (PEXCEPTION_ROUTINE)(INT_PTR)sse_float_exception_handler,
   };
+#ifdef __clang__
+  asm volatile (".safeseh %c0" :: "i" (sse_float_exception_handler));
+#endif
   __writefsdword(0, (DWORD)&exception_record);
   start_address(arglist);
   __writefsdword(0, (DWORD)exception_record.Next);
diff --git a/mingw-w64-crt/misc/i386__beginthreadex.c 
b/mingw-w64-crt/misc/i386__beginthreadex.c
index de5a07c27c76..c0fecc5aa093 100644
--- a/mingw-w64-crt/misc/i386__beginthreadex.c
+++ b/mingw-w64-crt/misc/i386__beginthreadex.c
@@ -28,6 +28,9 @@ static unsigned __stdcall thread_func(void *data)
     .Next = (EXCEPTION_REGISTRATION_RECORD *)__readfsdword(0),
     .Handler = (PEXCEPTION_ROUTINE)(INT_PTR)sse_float_exception_handler,
   };
+#ifdef __clang__
+  asm volatile (".safeseh %c0" :: "i" (sse_float_exception_handler));
+#endif
   __writefsdword(0, (DWORD)&exception_record);
   ret = start_address(arglist);
   __writefsdword(0, (DWORD)exception_record.Next);
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c 
b/mingw-w64-libraries/winpthreads/src/thread.c
index 09d6a732a4c1..3955b4faf316 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -143,6 +143,9 @@ SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
      .Next = (EXCEPTION_REGISTRATION_RECORD *) __readfsdword (0), /* current 
SEH handler */
      .Handler = (PEXCEPTION_ROUTINE)(void*) SetThreadName_SEH,
    };
+#ifdef __clang__
+   asm volatile (".safeseh %c0" :: "i" (SetThreadName_SEH));
+#endif
    __writefsdword (0, (DWORD) &exception_record); /* register our SEH handler 
*/
    RaiseException (EXCEPTION_SET_THREAD_NAME, 0, infosize, (ULONG_PTR *) 
&info);
    __writefsdword (0, (DWORD) exception_record.Next); /* unregister our SEH 
handler */



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to