-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark UnmanagedCallersOnlyTest as NativeAOT incompatible #74546
Conversation
We try to prevent compiler crashes and aborts as much as reasonable. The justification is that if the problematic codepath exists, but it's unreachable with a JIT based runtime, the app would work despite having the problem. We take this stance for missing references and other invalidness. In .NET Native times we saw a lot of invalid code being generated by non-C# compilers. When building the interop tests, I saw a compiler crash when compiling UnmanagedCallersOnly tests. What happens is that we try to compile the problematic method and hit the throw. We then go down to the fallback logic that tries to recompile the method as a throwing stub, but hit the throw again. This is unrecoverable and crashes the compiler. It's hard to come up with a JIT compatible behavior for this, but I think this is as close as possible. It would have been easier to emulate if the check happened when the method address is taken, but we only do this check once we try to JIT the method. In either case this likely produces a pretty unrecoverable runtime exception.
I have tried a simple repro:
It still fails compilation with this change with:
|
Yes, to the limit. I agree with this stance for stuff you can write in C#. If you can only generate the bad IL using ilasm or some other non-C# compiler, I think it is fine for the compiler crash on it. We have not been trying to 100% match behavior for bad IL between runtime and AOT compilers.
The goal for .NET Native for UWP was to get all apps, no matter how broken, AOT compiled and working. We do not have to the same bar for the current native AOT project. The runtime failure mode if somebody tries to call this method is AV in stackwalk:
I think it is better to crash the compiler instead of being exposed to this failure mode. |
This will be reachable by user written code once we fix the TODO to make this also throw when marshalling is needed (I'm touching that code here). Just make an unmanagedcallersonly with a bool or something... |
We can make the UnmanagedCallersOnly with bool fail gracefully by skipping the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
No description provided.