-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
gh-157468: Validate correct builtins used under JIT #157766
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
base: main
Are you sure you want to change the base?
Changes from all commits
313396f
b3f104f
f77395f
df1e636
f828617
290838c
e4f54de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Fix the JIT optimizer folding a builtin name to a constant taken from the | ||
| interpreter's builtins dictionary even when the running function uses a | ||
| different ``__builtins__`` mapping, such as one created with | ||
| ``vars(builtins).copy()``. The optimizer now only folds when the function's | ||
| builtins is the interpreter's, and the folded constant is guarded at runtime so | ||
| that another function sharing the same code object but a different builtins | ||
| mapping does not use it. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| #include <stdint.h> | ||
|
|
||
| #include "Python.h" | ||
| #include "pycore_long.h" | ||
| #include "pycore_opcode_utils.h" | ||
|
|
@@ -2519,13 +2521,24 @@ dummy_func(void) { | |
| else if (interp->rare_events.builtin_dict >= _Py_MAX_ALLOWED_BUILTINS_MODIFICATIONS) { | ||
| /* Do nothing */ | ||
| } | ||
| else if (ctx->frame->func == NULL || | ||
| ctx->frame->func->func_builtins != builtins) { | ||
| } | ||
| else { | ||
| if (!ctx->builtins_watched) { | ||
| PyDict_Watch(BUILTINS_WATCHER_ID, builtins); | ||
| ctx->builtins_watched = true; | ||
| } | ||
| if (ctx->frame->globals_checked_version != 0 && ctx->frame->globals_watched) { | ||
| if (ctx->frame->globals_checked_version != 0 && | ||
| ctx->frame->globals_watched && | ||
| uop_buffer_remaining_space(&ctx->out_buffer) >= 2) | ||
| { | ||
| cnst = convert_global_to_const(this_instr, builtins); | ||
| if (cnst != NULL && !ctx->frame->builtins_checked) { | ||
| ctx->frame->builtins_checked = true; | ||
| ADD_OP(_GUARD_BUILTINS_IS_CANONICAL, 0, 0); | ||
| ADD_OP(this_instr->opcode, 0, (uintptr_t)cnst); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two // Rewrite this_instr as a constant load; nothing is emitted yet.
cnst = convert_global_to_const(this_instr, builtins);
if (cnst != NULL) {
// Emit the builtins identity guard.
ADD_OP(_GUARD_BUILTINS_IS_CANONICAL, 0, 0);
// Emit the constant load prepared above.
ADD_OP(this_instr->opcode, 0, this_instr->operand0);
} |
||
| } | ||
| } | ||
| } | ||
| if (cnst == NULL) { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always allow enough headroom for small changes like this. No need to check here.