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

Does/can OPT:ICF work? #5229

Open mikedn opened 6 years ago

mikedn commented 6 years ago

I see in the linker response file that is generated when publishing that /OPT:ICF (and /OPT:REF) are specified. However, the final exe appears to contain identical method bodies that are not folded (e.g. Array<int>.get_Count() and Array<byte>.get_Count().

Is it even possible to use /OPT:ICF with managed code? Won't it affect callstacks somehow?

MichalStrehovsky commented 6 years ago

Code folding affects delegate equality (a delegate to Array<int>.get_Count() cannot be equal to a delegate to Array<byte>.get_Count() even though the code is the same, or bad things will happen).

On Project N, we do code folding, but we create a jump stub whenever a unique code address is needed (e.g. when expanding the LDFTN instruction). Having confusing stack traces is less of an issue (but people do notice it in their UWP apps and it does raise support questions from time to time).

For the open source CoreRT compiler, this is something that is on our radar but we don't do it yet.