Skip to content

JIT: Illegal return buffer/argument aliasing on native ABIs #72270

Closed

Description

@jakobbotsch

The SysV x64 ABI states the following for returning values:

If the type has class MEMORY, then the caller provides space for the return
value and passes the address of this storage in %rdi as if it were the first
argument to the function. In effect, this address becomes a “hidden” first ar-
gument. This storage must not overlap any data visible to the callee through
other names than this argument.

Yet for

private static void M(Foo* f, delegate* unmanaged[SuppressGCTransition]<Foo*, Foo> fn)
{
    *f = fn(f);
}

public struct Foo
{
    public int A, B, C, D, E;
}

the JIT produces

C:M(long,long):
       push     rbp
       sub      rsp, 16
       lea      rbp, [rsp+10H]
       mov      qword ptr [rbp-08H], rsi
       mov      rsi, rdi
       mov      rax, qword ptr [rbp-08H]
       call     rax
       mov      rax, qword ptr [(reloc)]
       cmp      dword ptr [rax], 0
       jne      SHORT G_M31715_IG05
G_M31715_IG04:
       add      rsp, 16
       pop      rbp
       ret      
G_M31715_IG05:
       call     [CORINFO_HELP_POLL_GC]
       jmp      SHORT G_M31715_IG04

where the argument and return buffer alias.

Godbolt link for comparison with GCC/Clang

Activity

  1. ghost added
    area-CodeGen-coreclr
    on Jul 15, 2022
  2. ghost added
    untriaged
    on Jul 15, 2022
  3. added this to the 8.0.0 milestone on Jul 15, 2022
  4. ghost removed
    untriaged
    on Jul 15, 2022
  5. jakobbotsch commented on Jul 28, 2022

    @jakobbotsch
    MemberAuthor

    Clang and MSVC both make use of this assumption, see this example, so this is not a theoretical issue and also seems to affect win-x64.

  6. self-assigned this
    on Jul 28, 2022
  7. changed the title [-]JIT: Illegal return buffer/argument aliasing in SysV x64 ABI[/-] [+]JIT: Illegal return buffer/argument aliasing on native ABIs[/+] on Jul 28, 2022
  8. modified the milestones: 8.0.0, 7.0.0 on Jul 29, 2022
  9. added a commit that references this issue on Jul 29, 2022
    a1af63b
  10. ghost added
    in-pr
    on Jul 29, 2022
  11. added a commit that references this issue on Aug 2, 2022
    8ac8400
  12. ghost removed
    in-pr
    on Aug 2, 2022
  13. ghost locked as resolved and limited conversation to collaborators on Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrbug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions