diff -uNr Python-3.6.15.orig/Include/objimpl.h Python-3.6.15/Include/objimpl.h --- Python-3.6.15.orig/Include/objimpl.h 2024-01-22 20:40:32.190635318 +0100 +++ Python-3.6.15/Include/objimpl.h 2024-01-22 20:41:00.330865534 +0100 @@ -255,7 +255,11 @@ 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 -uNr "Python-3.6.15.orig/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst" "Python-3.6.15/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst" --- "Python-3.6.15.orig/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst" 1970-01-01 01:00:00.000000000 +0100 +++ "Python-3.6.15/Misc/NEWS.d/next/Core and Builtins/2019-04-16-11-52-21.bpo-27987.n2_DcQ.rst" 2024-01-22 20:43:37.405496340 +0100 @@ -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. \ No newline at end of file diff -uNr "Python-3.6.15.orig/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst" "Python-3.6.15/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst" --- "Python-3.6.15.orig/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst" 1970-01-01 01:00:00.000000000 +0100 +++ "Python-3.6.15/Misc/NEWS.d/next/Core and Builtins/2019-05-15-18-28-43.bpo-27987.FaxuLy.rst" 2024-01-22 20:44:05.622397005 +0100 @@ -0,0 +1,2 @@ +``PyGC_Head`` structure is aligned to ``long double``. This is needed to +ensure GC-ed objects are aligned properly. Patch by Inada Naoki. \ No newline at end of file diff -uNr Python-3.6.15.orig/Objects/obmalloc.c Python-3.6.15/Objects/obmalloc.c --- Python-3.6.15.orig/Objects/obmalloc.c 2024-01-22 20:40:32.287302775 +0100 +++ Python-3.6.15/Objects/obmalloc.c 2024-01-22 20:42:22.008204376 +0100 @@ -650,8 +650,14 @@ * * 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)