Skip to content

Commit d866930

Browse files
vstinnerhrnciar
authored andcommitted
00343: Fix test_faulthandler on GCC 10
bpo-38965: Fix faulthandler._stack_overflow() on GCC 10 Fixed upstream and backported from the 3.7 branch: https://bugs.python.org/issue38965 python@f4a21d3 bpo-21131: Fix faulthandler.register(chain=True) stack (pythonGH-15276) https://bugs.python.org/issue21131 python@ac827ed
1 parent 22cb147 commit d866930

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Modules/faulthandler.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -952,18 +952,15 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args)
952952
}
953953

954954
#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION)
955-
#ifdef __INTEL_COMPILER
956-
/* Issue #23654: Turn off ICC's tail call optimization for the
957-
* stack_overflow generator. ICC turns the recursive tail call into
958-
* a loop. */
959-
# pragma intel optimization_level 0
960-
#endif
961955
static
962956
Py_uintptr_t
963957
stack_overflow(Py_uintptr_t min_sp, Py_uintptr_t max_sp, size_t *depth)
964958
{
965-
/* allocate 4096 bytes on the stack at each call */
966-
unsigned char buffer[4096];
959+
/* Allocate (at least) 4096 bytes on the stack at each call.
960+
961+
bpo-23654, bpo-38965: use volatile keyword to prevent tail call
962+
optimization. */
963+
volatile unsigned char buffer[4096];
967964
Py_uintptr_t sp = (Py_uintptr_t)&buffer;
968965
*depth += 1;
969966
if (sp < min_sp || max_sp < sp)
@@ -1146,7 +1143,11 @@ int _PyFaulthandler_Init(void)
11461143
* be able to allocate memory on the stack, even on a stack overflow. If it
11471144
* fails, ignore the error. */
11481145
stack.ss_flags = 0;
1149-
stack.ss_size = SIGSTKSZ;
1146+
/* bpo-21131: allocate dedicated stack of SIGSTKSZ*2 bytes, instead of just
1147+
SIGSTKSZ bytes. Calling the previous signal handler in faulthandler
1148+
signal handler uses more than SIGSTKSZ bytes of stack memory on some
1149+
platforms. */
1150+
stack.ss_size = SIGSTKSZ * 2;
11501151
stack.ss_sp = PyMem_Malloc(stack.ss_size);
11511152
if (stack.ss_sp != NULL) {
11521153
err = sigaltstack(&stack, &old_stack);

0 commit comments

Comments
 (0)