]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-142342: Fix m68k assembler operand constraints for `%fpcr` access (gh-142343)
authorJohn Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Tue, 9 Dec 2025 13:46:40 +0000 (14:46 +0100)
committerGitHub <noreply@github.com>
Tue, 9 Dec 2025 13:46:40 +0000 (13:46 +0000)
On m68k, an fmove instruction accessing %fpcr may only move from
or to a data register or a memory operand. The constraint "g" also
permits the use of address registers, which is invalid. The correct
constraint is "dm". Beginning with GCC 15, the register allocator
picks an address register in the code which causes SIGILL during
runtime.

Co-authored-by: Michael Karcher <github@mkarcher.dialup.fu-berlin.de>
Include/internal/pycore_pymath.h
Misc/NEWS.d/next/Core_and_Builtins/2025-12-08-13-04-37.gh-issue-142343.BTAyML.rst [new file with mode: 0644]
configure
configure.ac

index 4fcac3aab8bf51c8efb21a0c227e6c6cdab1be41..f66325aa59c4c913d554a979c62b5a6ca89098f7 100644 (file)
@@ -146,17 +146,17 @@ extern void _Py_set_387controlword(unsigned short);
     unsigned int old_fpcr, new_fpcr
 #define _Py_SET_53BIT_PRECISION_START                                   \
     do {                                                                \
-        __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr));                \
+        __asm__ ("fmove.l %%fpcr,%0" : "=dm" (old_fpcr));               \
         /* Set double precision / round to nearest.  */                 \
         new_fpcr = (old_fpcr & ~0xf0) | 0x80;                           \
         if (new_fpcr != old_fpcr) {                                     \
-              __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr));\
+            __asm__ volatile ("fmove.l %0,%%fpcr" : : "dm" (new_fpcr)); \
         }                                                               \
     } while (0)
 #define _Py_SET_53BIT_PRECISION_END                                     \
     do {                                                                \
         if (new_fpcr != old_fpcr) {                                     \
-            __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr));  \
+            __asm__ volatile ("fmove.l %0,%%fpcr" : : "dm" (old_fpcr)); \
         }                                                               \
     } while (0)
 #endif
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-12-08-13-04-37.gh-issue-142343.BTAyML.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-12-08-13-04-37.gh-issue-142343.BTAyML.rst
new file mode 100644 (file)
index 0000000..9da936c
--- /dev/null
@@ -0,0 +1 @@
+Fix SIGILL crash on m68k due to incorrect assembly constraint.
index 4f9b9b21ca395e22a0be61cae341cad9c761d790..2fe8186d9fb548db9ab474f55997719809aa2694 100755 (executable)
--- a/configure
+++ b/configure
@@ -26139,8 +26139,8 @@ main (void)
 {
 
   unsigned int fpcr;
-  __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr));
-  __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr));
+  __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm" (fpcr));
+  __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm" (fpcr));
 
   ;
   return 0;
index 046c046ffb5d10e0f9b141564b2054c3e99323fd..25a00ce52e57c9a903f32054a2fcf2bd6db9a545 100644 (file)
@@ -6133,8 +6133,8 @@ AS_VAR_IF([ac_cv_gcc_asm_for_x87], [yes], [
 AC_CACHE_CHECK([whether we can use gcc inline assembler to get and set mc68881 fpcr], [ac_cv_gcc_asm_for_mc68881], [
 AC_LINK_IFELSE(   [AC_LANG_PROGRAM([[]], [[
   unsigned int fpcr;
-  __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr));
-  __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr));
+  __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm" (fpcr));
+  __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm" (fpcr));
 ]])],[ac_cv_gcc_asm_for_mc68881=yes],[ac_cv_gcc_asm_for_mc68881=no])
 ])
 AS_VAR_IF([ac_cv_gcc_asm_for_mc68881], [yes], [