Skip to content

Commit ed9b577

Browse files
committed
YJIT: Fix crash when Kernel is prepended before JIT init
Use RCLASS_ORIGIN when looking up methods to register for specialized codegen. Module#prepend moves original methods to an origin iclass, so rb_method_entry_at on the module itself returns NULL after prepend. This happens in practice when BUNDLER_SETUP triggers Kernel.prepend during ruby_init_prelude, before rb_yjit_init runs.
1 parent 997bc70 commit ed9b577

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

yjit/src/codegen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10910,7 +10910,8 @@ pub fn yjit_reg_method_codegen_fns() {
1091010910
/// See also: [lookup_cfunc_codegen].
1091110911
fn reg_method_codegen(klass: VALUE, method_name: &str, gen_fn: MethodGenFn) {
1091210912
let mid = unsafe { rb_intern2(method_name.as_ptr().cast(), method_name.len().try_into().unwrap()) };
10913-
let me = unsafe { rb_method_entry_at(klass, mid) };
10913+
// Use RCLASS_ORIGIN to find methods that were moved by Module#prepend
10914+
let me = unsafe { rb_method_entry_at(RCLASS_ORIGIN(klass), mid) };
1091410915

1091510916
if me.is_null() {
1091610917
panic!("undefined optimized method!: {method_name}");

0 commit comments

Comments
 (0)