Skip to content

[Mono]: Tailcall p/invoke using struct value type together with jmp IL instruction fails on Mono Windows x64. #65702

Open
@lateralusX

Description

@lateralusX

Description

Mono runtime currently fails to execute the following CoreCLR runtime tests:

JIT/jit64/mcc/interop/mcc_i37/
JIT/jit64/mcc/interop/mcc_i57/
JIT/jit64/mcc/interop/mcc_i67/
JIT/jit64/mcc/interop/mcc_i77/
JIT/jit64/mcc/interop/mcc_i87/

The tests fails since Mono Windows since value type x64 ABI pass pointer to stack allocated struct (3, 5, 6, 7 or bigger than 8 bytes) in register or in stack slot when calling another method. In the tests above, a tail call is performed using a jmp IL instruction to a p/invoke method. As part of lowering the tail call we copy converted arguments into the calling functions argument area and then restore RSP,

amd64_push_reg (code, AMD64_RAX);
. Since Windows x64 ABI pass addresses to stack area for value types (of size different than 1,2,4,8), the copied arguments will now point into the collapsed frame, leading to unknown behavior. This might not be as big of an issue on other ABI's that always pass full value type value directly on stack, since the complete value will be copied by current code and there will be no references to stack memory in arguments passed to function.

These tests have been marked as not supported on none Windows platforms have not been previously run on Mono. Issue detected when enabling CoreCLR runtime tests running on Mono Windows, #64281. As part of that PR, the tests have been disabled on Mono and marked with this issue for future tracking.

Reproduction Steps

Build and run individual runtime test on Windows Mono as described here, https://github.com/dotnet/runtime/blob/main/docs/workflow/testing/mono/testing.md

Expected behavior

Following tests should pass:

JIT/jit64/mcc/interop/mcc_i37/
JIT/jit64/mcc/interop/mcc_i57/
JIT/jit64/mcc/interop/mcc_i67/
JIT/jit64/mcc/interop/mcc_i77/
JIT/jit64/mcc/interop/mcc_i87/

Actual behavior

Following tests fails and have been disabled due to this issue:

JIT/jit64/mcc/interop/mcc_i37/
JIT/jit64/mcc/interop/mcc_i57/
JIT/jit64/mcc/interop/mcc_i67/
JIT/jit64/mcc/interop/mcc_i77/
JIT/jit64/mcc/interop/mcc_i87/

Regression?

No, this has never worked on Mono.

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions