From 6ccb5f0cd44293730c6604184683ac6165f8b055 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 14 May 2021 20:37:23 +0200 Subject: python3: fix segfault importing ctypes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit on this line: CFUNCTYPE(c_int)(lambda:None) python segfaults when compiled with GCC 11. │ 0x7f7e53a5d64c call 0x7f7e53a5c3d0 │ │ 0x7f7e53a5d651 mov %rax,%r13 │ │ 0x7f7e53a5d654 test %rax,%rax │ │ 0x7f7e53a5d657 je 0x7f7e53a5d990 │ │ 0x7f7e53a5d65d mov 0x88(%rsp),%rax │ │ 0x7f7e53a5d665 movq %r15,%xmm0 │ │ 0x7f7e53a5d66a movq %rax,%xmm1 │ │ 0x7f7e53a5d66f addq $0x1,(%rax) │ │ 0x7f7e53a5d673 mov 0x10(%r13),%rax │ │ 0x7f7e53a5d677 punpcklqdq %xmm1,%xmm0 │ │ >0x7f7e53a5d67b movaps %xmm0,0x60(%r13) (rr) p/x ($r13 + 0x60) % 16 $10 = 0x8 (rr) p &self->b_value $11 = (union value *) 0x7f7e53c0fea8 b_value contains "long double" which requires 16 byte alignment so the subsequent 2 pointers have to be 16 byte aligned, so gcc generates "movaps" instruction which requires 16 byte alignment, but they're 8 byte aligned. Change-Id: I8d57311c5dc0d33ab0f7beeb6fee91299bd3de67 (cherry picked from commit 6a38eafc17c7b1b8972e648db19dc841c3f9902e) --- ...ove-long-double-from-ctypes-value-union.patch.1 | 34 ++++++++++++++++++++++ external/python3/UnpackedTarball_python3.mk | 1 + 2 files changed, 35 insertions(+) create mode 100644 external/python3/0001-remove-long-double-from-ctypes-value-union.patch.1 diff --git a/external/python3/0001-remove-long-double-from-ctypes-value-union.patch.1 b/external/python3/0001-remove-long-double-from-ctypes-value-union.patch.1 new file mode 100644 index 000000000000..8cdaf84de37c --- /dev/null +++ b/external/python3/0001-remove-long-double-from-ctypes-value-union.patch.1 @@ -0,0 +1,34 @@ +From 6d999803a07ef5e01f0048d4f276e9cf4401a23d Mon Sep 17 00:00:00 2001 +From: Benjamin Peterson +Date: Mon, 5 Sep 2016 16:24:52 -0700 +Subject: [PATCH] remove long double from ctypes value union + +It is unused. It also forces a 16-byte alignment, which creates problems because +Python's allocator only uses 8-byte alignment. +--- + Modules/_ctypes/ctypes.h | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h +index 0d3f7241ca..d80ea82cee 100644 +--- a/Modules/_ctypes/ctypes.h ++++ b/Modules/_ctypes/ctypes.h +@@ -34,7 +34,6 @@ union value { + #ifdef HAVE_LONG_LONG + PY_LONG_LONG ll; + #endif +- long double D; + }; + + /* +@@ -306,7 +305,6 @@ struct tagPyCArgObject { + #ifdef HAVE_LONG_LONG + PY_LONG_LONG q; + #endif +- long double D; + double d; + float f; + void *p; +-- +2.31.1 + diff --git a/external/python3/UnpackedTarball_python3.mk b/external/python3/UnpackedTarball_python3.mk index f231b5970eaf..41d9e4d78ff5 100644 --- a/external/python3/UnpackedTarball_python3.mk +++ b/external/python3/UnpackedTarball_python3.mk @@ -28,6 +28,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,python3,\ external/python3/darwin.patch.0 \ external/python3/0001-3.6-bpo-17239-Disable-external-entities-in-SAX-parse.patch.1 \ external/python3/0001-3.6-closes-bpo-42938-Replace-snprintf-with-Python-un.patch.1 \ + external/python3/0001-remove-long-double-from-ctypes-value-union.patch.1 \ )) ifneq ($(filter DRAGONFLY FREEBSD LINUX NETBSD OPENBSD SOLARIS,$(OS)),) -- cgit