Hello,

We currently have pretty useless chunk of assembly in mingwex that recently caused problems with Wine mingw builds. The problem is that we have longjmp symbol defined in mingwex which in fact forwards the call to the imported function on x64 non-SEH and x86. I did some digging in git history, but it doesn't explain much about why it's needed.

The one thing I'm not sure is non-SEH x64 build. In this case, it sets frame stored in jmp_buf to 0 before calling the actual implementation. There is absolutely no explanation for it. Maybe it was needed at some point for sjlj exception handling? Even if that's the case, it would be a pretty broken design. If such nulling is needed, it should be done before calling longjmp; intercepting an existing function is definitely not the right way to do it. Maybe it's not really needed?

And yet another question is, is non-SEH x64 build still something we need to care about?

If we still care about non-SEH x64 builds and really need to carry this hack, that could be preserved at the cost of complexity. But my guess is that we don't need it and that's what this patch does.

Jacek

---
 .../def-include/msvcrt-common.def.in          |  2 +-
 .../api-ms-win-crt-private-l1-1-0.def.in      |  2 +-
 mingw-w64-crt/lib-common/msvcrt.def.in        |  1 -
 mingw-w64-crt/lib-common/ucrtbase.def.in      |  2 +-
 .../lib-common/vcruntime140_app.def.in        |  2 +-
 mingw-w64-crt/lib32/crtdll.def                |  2 +-
 mingw-w64-crt/lib64/ntdllcrt.def              |  2 +-
 mingw-w64-crt/misc/longjmp.S                  | 23 -------------------
 mingw-w64-headers/crt/setjmp.h                |  3 +--
 9 files changed, 7 insertions(+), 32 deletions(-)


diff --git a/mingw-w64-crt/def-include/msvcrt-common.def.in b/mingw-w64-crt/def-include/msvcrt-common.def.in
index 364e4409..d96aeb68 100644
--- a/mingw-w64-crt/def-include/msvcrt-common.def.in
+++ b/mingw-w64-crt/def-include/msvcrt-common.def.in
@@ -141,5 +141,5 @@ ADD_UNDERSCORE(tzname)
 
 ADD_UNDERSCORE(vsnprintf_s)
 
-longjmp DATA
+longjmp
 #endif
diff --git a/mingw-w64-crt/lib-common/api-ms-win-crt-private-l1-1-0.def.in b/mingw-w64-crt/lib-common/api-ms-win-crt-private-l1-1-0.def.in
index 67e0e1a8..669638b9 100644
--- a/mingw-w64-crt/lib-common/api-ms-win-crt-private-l1-1-0.def.in
+++ b/mingw-w64-crt/lib-common/api-ms-win-crt-private-l1-1-0.def.in
@@ -1158,7 +1158,7 @@ F_I386(_seh_longjmp_unwind4@4)
 _set_purecall_handler
 _set_se_translator
 F_I386(_setjmp3)
-longjmp F_X86_ANY(DATA)
+longjmp
 memchr
 memcmp
 memcpy
diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in b/mingw-w64-crt/lib-common/msvcrt.def.in
index b45f3f5a..5ca5325d 100644
--- a/mingw-w64-crt/lib-common/msvcrt.def.in
+++ b/mingw-w64-crt/lib-common/msvcrt.def.in
@@ -1413,7 +1413,6 @@ log F_X86_ANY(DATA)
 log10
 F_NON_I386(log10f F_X86_ANY(DATA))
 F_NON_I386(logf F_X86_ANY(DATA))
-F_ARM_ANY(longjmp)
 malloc
 mblen
 F_ARM_ANY(mbrlen)
diff --git a/mingw-w64-crt/lib-common/ucrtbase.def.in b/mingw-w64-crt/lib-common/ucrtbase.def.in
index beee3dde..afe24d81 100644
--- a/mingw-w64-crt/lib-common/ucrtbase.def.in
+++ b/mingw-w64-crt/lib-common/ucrtbase.def.in
@@ -2431,7 +2431,7 @@ logb
 logbf
 logbl
 F_NON_I386(logf F_X86_ANY(DATA))
-longjmp F_X86_ANY(DATA)
+longjmp
 lrint
 lrintf
 lrintl
diff --git a/mingw-w64-crt/lib-common/vcruntime140_app.def.in b/mingw-w64-crt/lib-common/vcruntime140_app.def.in
index 27f79bd4..3ad3e51a 100644
--- a/mingw-w64-crt/lib-common/vcruntime140_app.def.in
+++ b/mingw-w64-crt/lib-common/vcruntime140_app.def.in
@@ -80,7 +80,7 @@ F_I386(_seh_longjmp_unwind@4)
 _set_purecall_handler
 _set_se_translator
 F_I386(_setjmp3)
-longjmp F_X86_ANY(DATA)
+longjmp
 memchr
 memcmp
 memcpy
diff --git a/mingw-w64-crt/lib32/crtdll.def b/mingw-w64-crt/lib32/crtdll.def
index 18aeb0bf..1b330686 100644
--- a/mingw-w64-crt/lib32/crtdll.def
+++ b/mingw-w64-crt/lib32/crtdll.def
@@ -599,7 +599,7 @@ localtime DATA
 ;_localtime32 = localtime
 log
 log10
-longjmp DATA
+longjmp
 malloc
 mblen
 mbstowcs
diff --git a/mingw-w64-crt/lib64/ntdllcrt.def b/mingw-w64-crt/lib64/ntdllcrt.def
index 679a79be..4a7402c2 100644
--- a/mingw-w64-crt/lib64/ntdllcrt.def
+++ b/mingw-w64-crt/lib64/ntdllcrt.def
@@ -118,7 +118,7 @@ iswxdigit
 isxdigit
 labs
 log
-longjmp DATA
+longjmp
 mbstowcs
 memchr
 memcmp
diff --git a/mingw-w64-crt/misc/longjmp.S b/mingw-w64-crt/misc/longjmp.S
index e3a13453..bec0ae15 100644
--- a/mingw-w64-crt/misc/longjmp.S
+++ b/mingw-w64-crt/misc/longjmp.S
@@ -5,29 +5,6 @@
  */
 #include <_mingw_mac.h>
 
-/* On ARM:
- * Error: cannot represent BFD_RELOC_32_PCREL relocation in this object file format
- * But anyway, nothing is needed here as libarm32/libmsvcrt.a is exporting longjmp
-  ldr ip, 1f
-  ldr pc, [pc, ip]
-  1: .long __imp_longjmp - (1b + 4)
-*/
-#if !(defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__))
-	.globl __MINGW_USYMBOL(longjmp)
-	.def	__MINGW_USYMBOL(longjmp);	.scl	2;	.type	32;	.endef
-__MINGW_USYMBOL(longjmp):
-#if defined(_AMD64_) || defined(__x86_64__)
-#ifndef __SEH__
-  xorq %rax,%rax
-  movq %rax, (%rcx)
-#endif
-  leaq __MINGW_IMP_LSYMBOL(longjmp)(%rip), %rax
-  jmpq *(%rax)
-#elif defined(_X86_) || defined(__i386__)
-  jmp *__imp__longjmp
-#endif
-#endif /* !(defined(_ARM_) || defined(__arm__)) */
-
 #if defined(_ARM_) || defined(__arm__) || defined(_ARM64_) || defined(__aarch64__)
 	.globl __MINGW_USYMBOL(__mingw_setjmp)
 	.def	__MINGW_USYMBOL(__mingw_setjmp);	.scl	2;	.type	32;	.endef
diff --git a/mingw-w64-headers/crt/setjmp.h b/mingw-w64-headers/crt/setjmp.h
index fc79f109..039c93f0 100644
--- a/mingw-w64-headers/crt/setjmp.h
+++ b/mingw-w64-headers/crt/setjmp.h
@@ -252,8 +252,7 @@ void * __cdecl __attribute__ ((__nothrow__)) mingw_getsp (void);
   int __cdecl __attribute__ ((__nothrow__,__returns_twice__)) setjmp(jmp_buf _Buf);
 #endif
 
-  __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__)) void __cdecl ms_longjmp(jmp_buf _Buf,int _Value)/* throw(...)*/;
-  __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__)) void __cdecl longjmp(jmp_buf _Buf,int _Value);
+  _CRTIMP __MINGW_ATTRIB_NORETURN __attribute__ ((__nothrow__)) void __cdecl longjmp(jmp_buf _Buf,int _Value);
 
 #ifdef __cplusplus
 }

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to