[3.7] bpo-27987: align PyGC_Head to alignof(long double)#13335
[3.7] bpo-27987: align PyGC_Head to alignof(long double)#13335methane merged 3 commits intopython:3.7from
Conversation
Include/objimpl.h
Outdated
| Py_ssize_t gc_refs; | ||
| } gc; | ||
| double dummy; /* force worst-case alignment */ | ||
| long double dummy; /* force worst-case alignment (16 byte for amd64) */ |
There was a problem hiding this comment.
Can you please elaborate the comment? Add "bpo-27987" and explain that x64-64 ABI requires to align on 16 bytes.
Do you have to align to 16 bytes on x86 (32-bit) as well?
There was a problem hiding this comment.
Can you please elaborate the comment? Add "bpo-27987" and explain that x64-64 ABI requires to align on 16 bytes.
I'm not sure this is really x86-64 ABI requirement...
C99 requires malloc returns memory aligned to be used for any built-in types.
Do you have to align to 16 bytes on x86 (32-bit) as well?
I don't think so. long double may be aligned to 8 byte boundary.
But I am not sure. I don't have 32bit development environment for now.
|
C code: With long double: Without long double: I'm not sure that 12 bytes is great for alignment. 32-bit CPU may be more efficient on SIMD instructions with 8 bytes alignment, no? |
|
PyGC_Head in master branch is two uintptr_t. It is 8 bytes (not 12 bytes) on x86. |
This pull request changes from 12 bytes to 12 or 16 bytes, no? |
|
Sorry @methane, I don't understand this change :-( What is the effect of PyListObject for example? Is the address of ob_item aligned to 16 bytes on x86 (32-bit)? Is it on x86-64 (64 bit)? |
|
@vstinner You wrote: struct {
void *next;
void *prev;
} _gc;But it is actually: struct {
void *next;
void *prev;
ssize_t gc_refs; /* only in Python < 3.8 */
} _gc;This is very big difference between Python 3.7 and 3.8. That's why I closed PR for 3.8 but don't close this. sizeof(PyGC_Head) is 12 byte on x86, regardless alignment is double or long double. (I can now "gcc -m32" on Ubuntu, thank you)
This pull request affects only where |
vstinner
left a comment
There was a problem hiding this comment.
LGTM. I think that I understood the issue and that the fix is correct :-)
|
|
|
this change needs to be undone. followup on the bug. |
…-13569) This reverts commit ea2b76b. See the bug for discussion. https://bugs.python.org/issue27987
|
Do you think missing "build" directory is happened by this change? I thought it just a trouble on the build bot environment. |
|
The resulting python interpreter was crashing on the the PGO bot and a pile of new undefined behavior was happening on the undefined behavior sanitizer (ubsan) bot. PGO bot: undefined behavior sanitizer millions of times: |
|
#13318 fixed it already. |
https://bugs.python.org/issue27987