Repository navigation
Emit conv.i for pointer constants in instantiating and unboxing IL stubs - #137931
Conversation
…ontexts On 64-bit targets the interpreter used an int32 stack value directly as the native int calli target or SetNextCallGenericContext argument, leaving the upper half of the slot stale. Widen it as other native int consumers do. Instantiating and unboxing IL stubs hit this: the stub linker lowers their pointer constants to ldc.i4 when they fit in 32 bits. That is common on wasm64, where it crashed on the first shared generic method called through such a stub. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli |
This sounds like a bug in the stub linker. int32 and int64 are not interchangable in IL. |
EmitLDC(DWORD_PTR) emits ldc.i8 on 64-bit, which the stub linker lowers to ldc.i4 when the value fits in 32 bits. The calli target and the SetNextCallGenericContext argument then reach their consumer as int32, not native int. Follow the pointer constant with conv.i like the other IL stubs do, and revert the interpreter-side widening. Co-authored-by: Copilot App <[email protected]>
@jakobbotsch Agreed, the lowering turns an int64 into an int32, and those aren't interchangeable. I've moved the fix into the stubs: the pointer constants are now followed by Note This reply was generated with GitHub Copilot. |
|
I audited the other
Only the JIT consumes this stub; the interpreter uses Note This comment was generated with GitHub Copilot. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the IL-stub pointer-typing changes.
No open issues 🎉
What changed in this PR
This PR corrects pointer typing in CoreCLR-generated IL stubs by emitting conv.i after pointer constants, addressing the reported wasm64 interpreter crash when those constants are encoded as 32-bit integers.
Changes:
- Converts call targets to native integers in unboxing and instantiating stubs.
- Converts the hidden generic-context argument to a native integer before passing it to the runtime helper.
| File | Description |
|---|---|
src/coreclr/vm/prestub.cpp |
Adds three EmitCONV_I() calls after pointer constants in the IL stub generators. |
Review effort: Balanced
|
I believe the initial state of the PR was ok to match JIT behavior, allowing implicit conversion from I believe @jakobbotsch comment is about not blindly transforming |
jakobbotsch
left a comment
There was a problem hiding this comment.
This looks good to me, and I believe other places use this pattern too.
I agree, matching JIT behavior here also sounds fine to me. But it's not totally clear to me from the spec that this implicit coercion for the target to
Yeah, if the stub linker is doing that it seems odd. But I see we have a large number of places using |
yeah, it is clear the jit does this and it is also clear that most stubs add the |
EmitLDC(DWORD_PTR)emitsldc.i8on 64-bit, which the stub linker lowers toldc.i4when the value fits in 32 bits. The unboxing and instantiating IL stubs pushed theircallitarget and generic context this way withoutconv.i, so the consumer saw an int32 rather than a native int. On wasm64, where most pointers fit in 32 bits, the interpreter then left the upper half of the slot stale and crashed. Follow the constants withconv.i, as the other IL stubs do.Note
This PR description was generated with GitHub Copilot.