dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.16k stars 4.71k forks source link

[feature proposal] Option for removing IL bodies from R2R images #52190

Open raffaeler opened 3 years ago

raffaeler commented 3 years ago

For years, the native vs managed debate was centered around the intellectual property / obfuscation problem. I still periodically discuss with customers about the need to make it harder the decompilation of certain parts of an application. I am very aware that any language can be reversed and therefore this is just a matter of rising the bar. Anyway, talking about .NET adoption, the obfuscation problem is often brought as an example.

In the current versions, .NET is now able to perform AOT on various bases, but still keeping the IL Body of the methods inside the assemblies. In certain cases the runtime still needs them (generics is just an example), but in others the IL could probably be removed without any impact.

I am wondering whether it would be possible, for limited portions of an assembly to:

In addition to the "obfuscation", there could be also a significant gain in terms of assembly size reduction.

I already looked at the CoreRT solution, but this works only if you want to generate a "C" style LIB or fully AOT the entire solution, which is not feasible for many applications and of course libraries.

Thoughts? Comments?

dotnet-issue-labeler[bot] commented 3 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Symbai commented 3 years ago

Thoughts? Comments?

Yes, the .NET team confirmed several times already that the AOT they have is all they deliver and there are no plans for improvements (i.e. making it work for everything else than libraries or console projects). There are even no plans on moving it out of the experimental so far. And there was a survey quite some time ago and obfuscation was ranked very badly while (startup) performance was one of the 1#. Which means removing IL body isn't a big thing (I dont like it either but it is as it is). And regarding our last statement, WPF is dead and won't even get trimming support. Winforms isn't dead but out of the .NET team scope as well. If we're "lucky" the most we might get, in 5 10 years, is Xamarin / Maui / WinUI AOT support.

benaadams commented 3 years ago

there are no plans for improvements

There are 3 variants of AoT being actively worked on in runtimelab https://github.com/dotnet/runtimelab

raffaeler commented 3 years ago

@benaadams Yes, I know. The folks there suggested me to post here

mangod9 commented 3 years ago

Thanks for opening a feature request. In the current model of R2R, pre-compiled code is treated as a "cache" of native code and IL is still required to potentially generate better quality code with Tiering/Dynamic PGO etc. But the request is certainly valid for certain scenarios and we will investigate for .net 6+

raffaeler commented 3 years ago

Thank you @mangod9 I am familiar with tiered compilation and I guess it should not be too tricky for R2R not to try regenerating the code if the IL has been removed.

I am wondering instead what are the challenges in informing the user for a method the user requested to remove but instead is needed by the runtime and cannot be removed. Maybe just reporting the methods that cannot be removed could be enough.

When you say .net 6+, does this mean that is too late for v6 or there is still the chance to fit it?

mangod9 commented 3 years ago

When you say .net 6+, does this mean that is too late for v6 or there is still the chance to fit it?

Correct, .net 6 feature work is expected to complete in the next couple of months so unlikely we have space for any new functionality.