Repository navigation
Conversation
stop_tracing_and_jit() can run a finalizer that invalidates the executor sampled as ENTER_EXECUTOR. Dispatching that stale opcode calls _PyJIT_Entry(NULL).
Member
|
See issue for the rationale. |
lucascouts
added a commit
to obentoo/bentoo
that referenced
this pull request
Nov 13, 2026
…iles/python-3.15.2-jit-stop-tracing-reread.patch, metadata/md5-cache/dev-lang/python-3.15.2_p1-r1), mod(.autoupdate/packages.toml), del(metadata/md5-cache/dev-lang/python-3.15.2_p1): fix the JIT segfault in stop_tracing Carry python/cpython#160853 for gh-160852. label(stop_tracing) dispatched the opcode sampled before stop_tracing_and_jit(); a finalizer run by the optimizer could invalidate that executor, and the stale ENTER_EXECUTOR then called _PyJIT_Entry(NULL). With USE=jit this killed Mozilla's packager.py (mozjar.py genexpr) at "mach install" stage-package, breaking mail-client/thunderbird-160.0. Upstream closed the PR unmerged on 2026-10-28 (JIT work on hold), so the patch lives here. Verified on thunderbird-160.0's packager.py: unpatched python[jit] rc=139, patched rc=0 three times and under PYTHON_JIT_STRESS=1; test_capi.test_opt, test_generators, test_genexps, test_warnings, test_sys_settrace and test_coroutines pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
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.
Fixes the crash in gh-160852.
label(stop_tracing)samplesopcodebeforestop_tracing_and_jit()and thenDISPATCH_GOTO_NON_TRACING()uses that snapshot. The tail-call macro does not re-read the instruction.stop_tracing_and_jit()can drop the last reference to a bound method of an unclosed buffered file. TheResourceWarningwrites__warningregistry__into the current frame's watched globals,executor_invalidate()restores the original bytecode and storesNULLin the executor slot, and the staleENTER_EXECUTORcalls_PyJIT_Entry(NULL).Re-read the opcode and the low byte of
opargafter optimize.EXTENDED_ARGbits already accumulated inopargstay in place, matching the deopt inENTER_EXECUTOR((oparg & ~255) | saved_arg).Tools/cases_generator/tier1_generator.pyemits those two assignments intoPython/generated_cases.c.h.I verified the same change on 3.15.2, built with
--with-tail-call-interp --enable-experimental-jit. The unpatched 3.15.1 interpreter segfaults in_PyJIT_Entrywhile Firefox'spackager.py --minifyevaluatesJarStruct.__init__.<locals>.<genexpr>. The patched interpreter finishes that run, including withPYTHON_JIT_STRESS=1. I do not have a small standalone repro: the finalizer has to run inside_PyOptimizer_Optimizewhile the sampled instruction is anENTER_EXECUTORwhose executor depends on the frame's globals.