Remove unnecessary pinning over non-unloadable RVA fields

Open
#118,802 1 comment 2 reactions 1 assignee View on GitHub

@EgorBo is already working on this.

Since Aug 16, 2025.

Assessment

This issue has not been assessed yet.

Description

area-CodeGen-coreclr
    unsafe void Test()
    {
        ReadOnlySpan<byte> utfStr = "hello"u8;
        fixed (byte* ptr = utfStr)
        {
            Console.WriteLine((nint)ptr);
        }
    }

Actual codegen (in an non-unloadable assembly):

; Method Test_DevDiv_255294:Test():this (FullOpts)
       sub      rsp, 40
       mov      rcx, 0x16992A529E8      ; static handle
       mov      bword ptr [rsp+0x20], rcx
       mov      rcx, 0x16992A529E8
       call     [System.Console:WriteLine(long)]
       xor      eax, eax
       mov      bword ptr [rsp+0x20], rax
       add      rsp, 40
       ret      
; Total bytes of code: 47

Expected codegen:

; Method Test_DevDiv_255294:Test():this (FullOpts)
       sub      rsp, 40
       mov      rcx, 0x29658B929E8
       call     [System.Console:WriteLine(long)]
       nop
       add      rsp, 40
       ret      
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.