From 28be65992d9cae0dae43482f7df685587b3d2ddd Mon Sep 17 00:00:00 2001 From: Chaim Halbert Date: Fri, 24 Feb 2023 12:19:13 -0700 Subject: [PATCH] bpo-27987 for v3.5.10 and v3.6.15: align by 16bytes on 64bit platforms --- ...oc-align-by-16bytes-on-64bit-platfor.patch | 43 +++++++++++++++++++ ...PyGC_Head-to-alignof-long-double-GH-.patch | 40 +++++++++++++++++ ...oc-align-by-16bytes-on-64bit-platfor.patch | 43 +++++++++++++++++++ ...PyGC_Head-to-alignof-long-double-GH-.patch | 40 +++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0001-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch create mode 100644 plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0002-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch create mode 100644 plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0009-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch create mode 100644 plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0010-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch diff --git a/plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0001-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch b/plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0001-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch new file mode 100644 index 00000000..66a873cd --- /dev/null +++ b/plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0001-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch @@ -0,0 +1,43 @@ +From 112cceb514e79b4c9805f9e5ea037a205be428da Mon Sep 17 00:00:00 2001 +From: Inada Naoki +Date: Tue, 14 May 2019 18:51:15 +0900 +Subject: [PATCH 1/2] bpo-27987: pymalloc: align by 16bytes on 64bit platform + (GH-12850) + +--- + .../2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst | 3 +++ + Objects/obmalloc.c | 6 ++++++ + 2 files changed, 9 insertions(+) + create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst + +diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst +new file mode 100644 +index 0000000000..b0f32a5c6c +--- /dev/null ++++ b/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst +@@ -0,0 +1,3 @@ ++pymalloc returns memory blocks aligned by 16 bytes, instead of 8 bytes, on ++64-bit platforms to conform x86-64 ABI. Recent compilers assume this alignment ++more often. Patch by Inada Naoki. +diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c +index 9dd8421a33..da9029c4a6 100644 +--- a/Objects/obmalloc.c ++++ b/Objects/obmalloc.c +@@ -540,8 +540,14 @@ static int running_on_valgrind = -1; + * + * You shouldn't change this unless you know what you are doing. + */ ++ ++#if SIZEOF_VOID_P > 4 ++#define ALIGNMENT 16 /* must be 2^N */ ++#define ALIGNMENT_SHIFT 4 ++#else + #define ALIGNMENT 8 /* must be 2^N */ + #define ALIGNMENT_SHIFT 3 ++#endif + + /* Return the number of bytes in size class I, as a uint. */ + #define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT) +-- +2.38.4 + diff --git a/plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0002-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch b/plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0002-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch new file mode 100644 index 00000000..ace6e275 --- /dev/null +++ b/plugins/python-build/share/python-build/patches/3.5.10/Python-3.5.10/0002-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch @@ -0,0 +1,40 @@ +From 618ef35426ecc57da1bee50f8dc5896f5fb178a9 Mon Sep 17 00:00:00 2001 +From: Inada Naoki +Date: Sat, 25 May 2019 21:13:33 +0900 +Subject: [PATCH 2/2] bpo-27987: align PyGC_Head to alignof(long double) + (GH-13335) + +--- + Include/objimpl.h | 6 +++++- + .../2019-05-15-18-28-43.bpo-27987.FaxuLy.rst | 2 ++ + 2 files changed, 7 insertions(+), 1 deletion(-) + create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst + +diff --git a/Include/objimpl.h b/Include/objimpl.h +index 65b6d91c36..eaf57975c8 100644 +--- a/Include/objimpl.h ++++ b/Include/objimpl.h +@@ -250,7 +250,11 @@ typedef union _gc_head { + union _gc_head *gc_prev; + Py_ssize_t gc_refs; + } gc; +- double dummy; /* force worst-case alignment */ ++ long double dummy; /* force worst-case alignment */ ++ // malloc returns memory block aligned for any built-in types and ++ // long double is the largest standard C type. ++ // On amd64 linux, long double requires 16 byte alignment. ++ // See bpo-27987 for more discussion. + } PyGC_Head; + + extern PyGC_Head *_PyGC_generation0; +diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst b/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst +new file mode 100644 +index 0000000000..97ca37b262 +--- /dev/null ++++ b/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst +@@ -0,0 +1,2 @@ ++``PyGC_Head`` structure is aligned to ``long double``. This is needed to ++GC-ed objects are aligned properly. Patch by Inada Naoki. +-- +2.38.4 + diff --git a/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0009-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch b/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0009-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch new file mode 100644 index 00000000..ef8d1d45 --- /dev/null +++ b/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0009-bpo-27987-pymalloc-align-by-16bytes-on-64bit-platfor.patch @@ -0,0 +1,43 @@ +From 54dc627769bf112b0181972a52c4b45e4a02da57 Mon Sep 17 00:00:00 2001 +From: Inada Naoki +Date: Tue, 14 May 2019 18:51:15 +0900 +Subject: [PATCH 09/10] bpo-27987: pymalloc: align by 16bytes on 64bit platform + (GH-12850) + +--- + .../2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst | 3 +++ + Objects/obmalloc.c | 6 ++++++ + 2 files changed, 9 insertions(+) + create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst + +diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst b/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst +new file mode 100644 +index 0000000000..b0f32a5c6c +--- /dev/null ++++ b/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst +@@ -0,0 +1,3 @@ ++pymalloc returns memory blocks aligned by 16 bytes, instead of 8 bytes, on ++64-bit platforms to conform x86-64 ABI. Recent compilers assume this alignment ++more often. Patch by Inada Naoki. +diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c +index d46d149311..47283354f4 100644 +--- a/Objects/obmalloc.c ++++ b/Objects/obmalloc.c +@@ -650,8 +650,14 @@ static int running_on_valgrind = -1; + * + * You shouldn't change this unless you know what you are doing. + */ ++ ++#if SIZEOF_VOID_P > 4 ++#define ALIGNMENT 16 /* must be 2^N */ ++#define ALIGNMENT_SHIFT 4 ++#else + #define ALIGNMENT 8 /* must be 2^N */ + #define ALIGNMENT_SHIFT 3 ++#endif + + /* Return the number of bytes in size class I, as a uint. */ + #define INDEX2SIZE(I) (((uint)(I) + 1) << ALIGNMENT_SHIFT) +-- +2.38.4 + diff --git a/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0010-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch b/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0010-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch new file mode 100644 index 00000000..f9da87aa --- /dev/null +++ b/plugins/python-build/share/python-build/patches/3.6.15/Python-3.6.15/0010-bpo-27987-align-PyGC_Head-to-alignof-long-double-GH-.patch @@ -0,0 +1,40 @@ +From e68ff170dc6764b22886e703f583fb53e90367ef Mon Sep 17 00:00:00 2001 +From: Inada Naoki +Date: Sat, 25 May 2019 21:13:33 +0900 +Subject: [PATCH 10/10] bpo-27987: align PyGC_Head to alignof(long double) + (GH-13335) + +--- + Include/objimpl.h | 6 +++++- + .../2019-05-15-18-28-43.bpo-27987.FaxuLy.rst | 2 ++ + 2 files changed, 7 insertions(+), 1 deletion(-) + create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst + +diff --git a/Include/objimpl.h b/Include/objimpl.h +index e7a3696d7a..90d71b87ea 100644 +--- a/Include/objimpl.h ++++ b/Include/objimpl.h +@@ -255,7 +255,11 @@ typedef union _gc_head { + union _gc_head *gc_prev; + Py_ssize_t gc_refs; + } gc; +- double dummy; /* force worst-case alignment */ ++ long double dummy; /* force worst-case alignment */ ++ // malloc returns memory block aligned for any built-in types and ++ // long double is the largest standard C type. ++ // On amd64 linux, long double requires 16 byte alignment. ++ // See bpo-27987 for more discussion. + } PyGC_Head; + + extern PyGC_Head *_PyGC_generation0; +diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst b/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst +new file mode 100644 +index 0000000000..97ca37b262 +--- /dev/null ++++ b/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst +@@ -0,0 +1,2 @@ ++``PyGC_Head`` structure is aligned to ``long double``. This is needed to ++GC-ed objects are aligned properly. Patch by Inada Naoki. +-- +2.38.4 +