[Python-Dev] Python 2.7, long double vs allocator alignment, GCC 8 on x86-64 (original) (raw)
Florian Weimer fw at deneb.enyo.de
Tue Jan 30 13:56:40 EST 2018
- Previous message (by thread): [Python-Dev] OS-X builds for 3.7.0
- Next message (by thread): [Python-Dev] Python 2.7, long double vs allocator alignment, GCC 8 on x86-64
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I hope this is the right list for this kind of question. We recently tried to build Python 2.6 with GCC 8, and ran into this issue:
<https://bugzilla.redhat.com/show_bug.cgi?id=1540316>
Also quoting for context:
| PyInstanceNewRaw contains this code: || inst = PyObjectGCNew(PyInstanceObject, &PyInstanceType); | if (inst == NULL) { | PyDECREF(dict); | return NULL; | } | inst->inweakreflist = NULL; | PyINCREF(klass); | inst->inclass = (PyClassObject *)klass; | inst->indict = dict; | PyObjectGCTRACK(inst); || PyObjectGCTRACK expands to: || _#define PyObjectGCTRACK(o) do { _ | _PyGCHead g = PyASGC(o); _ | _if (g->gc.gcrefs != PyGCREFSUNTRACKED) _ | _PyFatalError("GC object already tracked"); _ | … || Via: || #define PyASGC(o) ((PyGCHead *)(o)-1) || We get to this: || /* GC information is stored BEFORE the object structure. */ | typedef union gchead { | struct { | union gchead *gcnext; | union gchead *gcprev; | Pyssizet gcrefs; | } gc; | long double dummy; /* force worst-case alignment */ | } PyGCHead; || PyGCHead has 16-byte alignment. The net result is that || PyObjectGCTRACK(inst); || promises to the compiler that inst is properly aligned for the | PyGCHead type, but it is not: PyObjectGCNew returns a pointer which | is only 8-byte-aligned. || Objects/obmalloc.c contains this: || /* | * Alignment of addresses returned to the user. 8-bytes alignment works | * on most current architectures (with 32-bit or 64-bit address busses). | _ The alignment value is also used for grouping small requests in size_ | * classes spaced ALIGNMENT bytes apart. | * | * You shouldn't change this unless you know what you are doing. | */ | #define ALIGNMENT 8 /* must be 2^N */ | #define ALIGNMENTSHIFT 3 | #define ALIGNMENTMASK (ALIGNMENT - 1) || So either the allocator alignment needs to be increased, or the | PyGCHead alignment needs to be decreased.
Is this a known issue? As far as I can see, it has not been fixed on the 2.7 branch.
(Store merging is a relatively new GCC feature. Among other things, this means that on x86-64, for sufficiently aligned pointers, vector instructions are used to update multiple struct fields at once. These vector instructions can trigger alignment traps, similar to what happens on some other architectures for scalars.)
- Previous message (by thread): [Python-Dev] OS-X builds for 3.7.0
- Next message (by thread): [Python-Dev] Python 2.7, long double vs allocator alignment, GCC 8 on x86-64
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]