Skip to content

Commit 02c085d

Browse files
glaubitzkarcherm
andauthored
gh-142342: Fix m68k assembler operand constraints for %fpcr access (gh-142343)
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 <[email protected]>
1 parent 4279785 commit 02c085d

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

‎Include/internal/pycore_pymath.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ extern void _Py_set_387controlword(unsigned short);
146146
unsigned int old_fpcr, new_fpcr
147147
#define _Py_SET_53BIT_PRECISION_START \
148148
do { \
149-
__asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \
149+
__asm__ ("fmove.l %%fpcr,%0" : "=dm" (old_fpcr)); \
150150
/* Set double precision / round to nearest. */ \
151151
new_fpcr = (old_fpcr & ~0xf0) | 0x80; \
152152
if (new_fpcr != old_fpcr) { \
153-
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr));\
153+
__asm__ volatile ("fmove.l %0,%%fpcr" : : "dm" (new_fpcr)); \
154154
} \
155155
} while (0)
156156
#define _Py_SET_53BIT_PRECISION_END \
157157
do { \
158158
if (new_fpcr != old_fpcr) { \
159-
__asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \
159+
__asm__ volatile ("fmove.l %0,%%fpcr" : : "dm" (old_fpcr)); \
160160
} \
161161
} while (0)
162162
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix SIGILL crash on m68k due to incorrect assembly constraint.

‎configure‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6133,8 +6133,8 @@ AS_VAR_IF([ac_cv_gcc_asm_for_x87], [yes], [
61336133
AC_CACHE_CHECK([whether we can use gcc inline assembler to get and set mc68881 fpcr], [ac_cv_gcc_asm_for_mc68881], [
61346134
AC_LINK_IFELSE( [AC_LANG_PROGRAM([[]], [[
61356135
unsigned int fpcr;
6136-
__asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr));
6137-
__asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr));
6136+
__asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm" (fpcr));
6137+
__asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm" (fpcr));
61386138
]])],[ac_cv_gcc_asm_for_mc68881=yes],[ac_cv_gcc_asm_for_mc68881=no])
61396139
])
61406140
AS_VAR_IF([ac_cv_gcc_asm_for_mc68881], [yes], [

0 commit comments

Comments
 (0)