Skip to content

Possible OSX/Linux JIT Inlining Optimization Bug .Net Core 5.0.200 #49078

@kevinmv

Description

@kevinmv

Hello!

We are seeing what looks to be a JIT optimization bug in .Net Core 5.0.200 but only for OSX and Linux, Windows does not present any issues.

Description

We have a function ScheduleFlushSend(JobHandle dep) which takes a small struct as an input parameter:

    [StructLayout(LayoutKind.Sequential)]
    public struct JobHandle
    {
        public IntPtr JobGroup;
        public uint Version;
        //<member functions removed for brevity>
     }

Inside ScheduleFlushSend we pass along the dep JobHandle parameter to an implemented interface method ScheduleSend however depending on optimization levels the dep jobhandle is corrupted.

Release builds can be forced to work by decorating ScheduleFlushSend with [MethodImpl(MethodImplOptions.NoInlining)], or alternatively running with COMPlus_JITMinOpts=1

The crash would only happen after calling ScheduleFlushSend 30+ times, however by running with COMPlus_TieredCompilation=0 the corruption is immediate further supporting our suspicion this is a JIT optimization bug.

Printing out the values of the JobHandle members before passing / after entering functions shows what looks to be an issue where inlining the function results in the parameter being read from a memory address that is off by 8 bytes.

(in this example RPCSystem.OnUpdate calls ScheduleFlushSend which calls ScheduleSend)

RPCSystem:	                jobgroup=76 version=0
   |--ScheduleFlushSend:	jobgroup=76 version=0
      |--ScheduleSend:	        jobgroup=139823864677200 version=76 

Here you can see the JobGroup field's value has shifted into the second member of the struct, and the first member is a random value (it actually looks like a valid, irrelevant, memory address)

I can send a working (forcing noinlining on ScheduleFlushSend) repo and the crashing repo (removing the forced inlining) if provided an address.

Configuration

  • Which version of .NET is the code running on?
    • 5.0.200
  • What OS and version, and what distro if applicable?
    • Ubuntu 20.04
    • OSX Mojave
  • What is the architecture (x64, x86, ARM, ARM64)?
    • x64
  • Do you know whether it is specific to that configuration?
    • Yes, only reproduces with optimizations on. Debug builds work correctly, and forcing inlining off hides the issue

Other information

  • We do not see this issue on Windows, OSX or Linux when using .Net Core 6.0.0-preview.1
  • We are compiling the application as a netstandard 2.0 and running via netcorerun.exe (a netcore app that loads all assemblies into an AssemblyLoadContext and then executes main)

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions