Skip to content

Commit 1430719

Browse files
glaubitzkarcherm
authored andcommitted
pythongh-142342: Fix m68k assembler operand constraints for %fpcr access (pythongh-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. (cherry picked from commit 02c085d) Co-authored-by: John Paul Adrian Glaubitz <[email protected]> Co-authored-by: Michael Karcher <[email protected]>
1 parent 19968c8 commit 1430719

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
@@ -6099,8 +6099,8 @@ AS_VAR_IF([ac_cv_gcc_asm_for_x87], [yes], [
60996099
AC_CACHE_CHECK([whether we can use gcc inline assembler to get and set mc68881 fpcr], [ac_cv_gcc_asm_for_mc68881], [
61006100
AC_LINK_IFELSE( [AC_LANG_PROGRAM([[]], [[
61016101
unsigned int fpcr;
6102-
__asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr));
6103-
__asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr));
6102+
__asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm" (fpcr));
6103+
__asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm" (fpcr));
61046104
]])],[ac_cv_gcc_asm_for_mc68881=yes],[ac_cv_gcc_asm_for_mc68881=no])
61056105
])
61066106
AS_VAR_IF([ac_cv_gcc_asm_for_mc68881], [yes], [

0 commit comments

Comments
 (0)