dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 508 forks source link

Wrong Marshal.SizeOf on CoreRT #8274

Closed mrhelmut closed 4 years ago

mrhelmut commented 4 years ago

Hello there,

I stumbled upon a discrepancy between regular .Net runtimes and CoreRT when it comes to Marshel.SizeOf().

Sorry if I don't have a more precise isolated case than this, but here is a practical example from trying to get one of our project to run properly on CoreRT.

This type: https://github.com/rlabrecque/Steamworks.NET/blob/ee014372d1c1077c6fbbc2d7cb88e38fe4a56453/Plugins/Steamworks.NET/autogen/SteamCallbacks.cs#L1768

is expected to have a Marshel.SizeOf() of 616, but CoreRT returns 612.

Not very workable of an example, I concede, but I hope it helps nonetheless.

Suchiman commented 4 years ago

~On a side note, https://github.com/dotnet/runtime/pull/38632 has not been ported / copied to CoreRT yet but this looks different.~

EDIT: Actually, nevermind that, it seems i can't read diff's the right way around, got ported in #8222

jkotas commented 4 years ago

Thank you for reporting this. #8275 has the fix.

mrhelmut commented 4 years ago

Awesome, that was swift! I'll give it a go whenever I can afford the time to build a local compiler instance.

MichalStrehovsky commented 4 years ago

I'll give it a go whenever I can afford the time to build a local compiler instance.

An updated NuGet package should be out within a day.

yowl commented 4 years ago

Apart from the size, what was the effect of this bug?

jkotas commented 4 years ago

The layout of the marshalled view of the struct was wrong. It means both size and offsets of individual members were wrong.

mrhelmut commented 4 years ago

Confirmed working, thanks!

I guess that means another MonoGame game shipping with CoreRT.

MichalStrehovsky commented 4 years ago

I guess that means another MonoGame game shipping with CoreRT.

Awesome! Are you at liberty to say which one and which platform?

mrhelmut commented 4 years ago

I guess that means another MonoGame game shipping with CoreRT.

Awesome! Are you at liberty to say which one and which platform?

https://store.steampowered.com/app/1037020/ScourgeBringer/

It currently runs on .Net Core 3.1 but the next update will ship with CoreRT on Windows, macOS, and Linux. Having a bloat-free single exe with no JIT'ing is very valuable (we write garbage-free code to avoid GC, but the occasional JIT'ing of .Net Core are still very present despite disabling tiered compilation and ready to run images).