-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-127545: Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T) #135209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
encukou
wants to merge
5
commits into
python:main
Choose a base branch
from
encukou:gc_crash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As documented in InternalDocs/garbage_collector.md, the garbage collector stores flags in the least significant two bits of the _gc_prev pointer in struct PyGC_Head. Consequently, this pointer is only capable of storing a location that's aligned to a 4-byte boundary. This alignment requirement is documented but it's not actually encoded. The code only works when python happens to run on a platform that has a sufficiently large minimum alignment for the structs in question. The same problem arises with PyObject pointers because the least significant bits get used for PyStackRef tags. Since we know that 2 bits are needed, we also know the minimum alignment that's needed. Let's make that explicit, so the compiler can then make those bits available. This patch fixes a segfault in _bootstrap_python. In 3.14.0 beta 2 this fixes the "Assertion `!PyStackRef_IsTaggedInt(ref)' failed" when built with --config-pydebug. Also, making the requirements explicit improves clarity. This bug was previously investigated by Adrian Glaubitz here: https://lists.debian.org/debian-68k/2024/11/msg00020.html https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1087600 Although Adrian's patch isn't really correct (because natural alignment is not needed), he deserves full credit for finding the root cause.
This is a common façade for the various `_Alignas` alternatives, which behave in interesting ways. The standard `alignas` errors if it would decrease the alignment; to prevent that it can be used again with the defined variable's type. The standard `alignas` can't be used on a `struct` definition, the workaround is to use it on one of the `struct`'s members. MSVC `declspec(aligned)` only takes integer literals. MSVC `declspec(aligned)` had a bug when applied to a combined struct+member definition. The workaround is to separate the struct definition. Do that for `PyASCIIObject.state`.
🤖 New build scheduled with the buildbot fleet by @encukou for commit 512fe58 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F135209%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
@fthain, would you be able to test this on a m68k? [edit] Buildbot failures look unrelated. |
This was referenced Jun 7, 2025
encukou
commented
Jun 7, 2025
encukou
commented
Jun 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
_Py_ALIGNED_DEF(N, T)
might be a better way to make the various_Alignas
alternatives,which behave in interesting ways, increase (rather than set) a variable's alignment.
The standard
alignas
/_Alignas
error out if they would decrease the alignment. To prevent that, they can be used again with the defined variable's type.The standard
alignas
/_Alignas
can't be used on astruct
definition, the workaround is to use it on one of thestruct
's members.MSVC
declspec(aligned)
only takes integer literals.MSVC
declspec(aligned)
had a bug when applied to a combined struct+member definition; a workaround is to separate the struct definition. This avoids a potentially ABI-breaking bug in older MSVC versions (which newer versions warn about, using code C5274).This PR does that for
PyASCIIObject.state
.