From 89ea5509b00d244f11fb2ebd06743f638d95eee4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Feb 13 2020 15:06:17 +0000 Subject: [PATCH 1/2] Fix test_faulthandler on GCC 10 Fix also faulthandler.register(chain=True) stack. Resolves: rhbz#1799090 --- diff --git a/00343-faulthandler-gcc10.patch b/00343-faulthandler-gcc10.patch new file mode 100644 index 0000000..7df547c --- /dev/null +++ b/00343-faulthandler-gcc10.patch @@ -0,0 +1,65 @@ +commit 5044c889dfced2f43e2cccb673d889a4882f6b3b +Author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> +Date: Wed Dec 4 12:29:22 2019 -0800 + + bpo-38965: Fix faulthandler._stack_overflow() on GCC 10 (GH-17467) + + Use the "volatile" keyword to prevent tail call optimization + on any compiler, rather than relying on compiler specific pragma. + (cherry picked from commit 8b787964e0a647caa0558b7c29ae501470d727d9) + + Co-authored-by: Victor Stinner + +commit ac827edc493d3ac3f5b9b0cc353df1d4b418a9aa +Author: Victor Stinner +Date: Wed Aug 14 23:35:27 2019 +0200 + + bpo-21131: Fix faulthandler.register(chain=True) stack (GH-15276) + + faulthandler now allocates a dedicated stack of SIGSTKSZ*2 bytes, + instead of just SIGSTKSZ bytes. Calling the previous signal handler + in faulthandler signal handler uses more than SIGSTKSZ bytes of stack + memory on some platforms. + +diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c +index 1493f8d..eb22e40 100644 +--- a/Modules/faulthandler.c ++++ b/Modules/faulthandler.c +@@ -910,19 +910,15 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args) + Py_RETURN_NONE; + } + +-#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) +-#ifdef __INTEL_COMPILER +- /* Issue #23654: Turn off ICC's tail call optimization for the +- * stack_overflow generator. ICC turns the recursive tail call into +- * a loop. */ +-# pragma intel optimization_level 0 +-#endif + static + Py_uintptr_t + stack_overflow(Py_uintptr_t min_sp, Py_uintptr_t max_sp, size_t *depth) + { +- /* allocate 4096 bytes on the stack at each call */ +- unsigned char buffer[4096]; ++ /* Allocate (at least) 4096 bytes on the stack at each call. ++ ++ bpo-23654, bpo-38965: use volatile keyword to prevent tail call ++ optimization. */ ++ volatile unsigned char buffer[4096]; + Py_uintptr_t sp = (Py_uintptr_t)&buffer; + *depth += 1; + if (sp < min_sp || max_sp < sp) +@@ -1112,7 +1108,11 @@ int _PyFaulthandler_Init(void) + * be able to allocate memory on the stack, even on a stack overflow. If it + * fails, ignore the error. */ + stack.ss_flags = 0; +- stack.ss_size = SIGSTKSZ; ++ /* bpo-21131: allocate dedicated stack of SIGSTKSZ*2 bytes, instead of just ++ SIGSTKSZ bytes. Calling the previous signal handler in faulthandler ++ signal handler uses more than SIGSTKSZ bytes of stack memory on some ++ platforms. */ ++ stack.ss_size = SIGSTKSZ * 2; + stack.ss_sp = PyMem_Malloc(stack.ss_size); + if (stack.ss_sp != NULL) { + err = sigaltstack(&stack, NULL); diff --git a/python34.spec b/python34.spec index 22dd4c3..0c900d1 100644 --- a/python34.spec +++ b/python34.spec @@ -113,7 +113,7 @@ Name: python%{pyshortver} #global prerel ... %global upstream_version %{general_version}%{?prerel} Version: %{general_version}%{?prerel:~%{prerel}} -Release: 8%{?dist} +Release: 9%{?dist} License: Python # Whether to use RPM build wheels from the python-{pip,setuptools}-wheel package @@ -537,6 +537,13 @@ Patch322: 00322-test_ssl-skip-openssl111.patch # Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1750457 Patch332: 00332-CVE-2019-16056.patch +# 00343 # +# bpo-38965: Fix faulthandler._stack_overflow() on GCC 10 +# Fixed upstream and backported from the 3.7 branch: +# https://bugs.python.org/issue38965 +# https://github.com/python/cpython/commit/f4a21d3b239bf4f4e4e2a8a5936b9b040645b246 +Patch343: 00343-faulthandler-gcc10.patch + # (New patches go here ^^^) # # When adding new patches to "python" and "python3" in Fedora 17 onwards, @@ -705,6 +712,7 @@ rmdir Lib/ensurepip/_bundled %patch321 -p1 %patch322 -p1 %patch332 -p1 +#%patch343 -p1 # Currently (2010-01-15), http://docs.python.org/library is for 2.6, and there # are many differences between 2.6 and the Python 3 library. @@ -1242,6 +1250,10 @@ CheckPython optimized # ====================================================== %changelog +* Thu Feb 13 2020 Victor Stinner - 3.4.10-9 +- Fix test_faulthandler for GCC 10 (rhbz#1799090) +- Fix also faulthandler.register(chain=True) stack. + * Thu Jan 30 2020 Fedora Release Engineering - 3.4.10-8 - Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild From 2354870090fdf0da0dd37bbe95a7875e9dc12ae2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Feb 17 2020 15:52:11 +0000 Subject: [PATCH 2/2] Fix patch and fix specfile --- diff --git a/00343-faulthandler-gcc10.patch b/00343-faulthandler-gcc10.patch index 7df547c..daec72a 100644 --- a/00343-faulthandler-gcc10.patch +++ b/00343-faulthandler-gcc10.patch @@ -22,14 +22,13 @@ Date: Wed Aug 14 23:35:27 2019 +0200 memory on some platforms. diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c -index 1493f8d..eb22e40 100644 +index 1493f8d..6da354a 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c -@@ -910,19 +910,15 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args) - Py_RETURN_NONE; +@@ -911,18 +911,15 @@ faulthandler_fatal_error_py(PyObject *self, PyObject *args) } --#if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) + #if defined(HAVE_SIGALTSTACK) && defined(HAVE_SIGACTION) -#ifdef __INTEL_COMPILER - /* Issue #23654: Turn off ICC's tail call optimization for the - * stack_overflow generator. ICC turns the recursive tail call into @@ -50,7 +49,7 @@ index 1493f8d..eb22e40 100644 Py_uintptr_t sp = (Py_uintptr_t)&buffer; *depth += 1; if (sp < min_sp || max_sp < sp) -@@ -1112,7 +1108,11 @@ int _PyFaulthandler_Init(void) +@@ -1112,7 +1109,11 @@ int _PyFaulthandler_Init(void) * be able to allocate memory on the stack, even on a stack overflow. If it * fails, ignore the error. */ stack.ss_flags = 0; diff --git a/python34.spec b/python34.spec index 0c900d1..8919a89 100644 --- a/python34.spec +++ b/python34.spec @@ -712,7 +712,7 @@ rmdir Lib/ensurepip/_bundled %patch321 -p1 %patch322 -p1 %patch332 -p1 -#%patch343 -p1 +%patch343 -p1 # Currently (2010-01-15), http://docs.python.org/library is for 2.6, and there # are many differences between 2.6 and the Python 3 library.