runtime: ILLink fails to resolve method's base interface method if the interface method doesn't have newslot
This is based of a repro from F#. The interface definition of a method in F# looks like this:
.method public hidebysig specialname abstract virtual
instance valuetype MyLib.OS get_OS () cil managed
{
} // end of method IPlatformData::get_OS
Note that it doesn’t have a newslot
flag.
Similar interface definition in C# looks basically the same except that it has newslot
as well.
When illink resolves methods and their base methods, it will not consider interface methods which don’t have newslot
on them (I don’t know why).
https://github.com/dotnet/runtime/blob/64862501b238512db10eff9ed4b05ba94412974d/src/tools/illink/src/linker/Linker/TypeMapInfo.cs#L154
As a result, implementing the above interface in C# and trimming the result will create the implementation type without any of the interface method implementations.
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 1
- Comments: 22 (19 by maintainers)
Commits related to this issue
- ILLink: Allow interface methods to not have newslot Fixes https://github.com/dotnet/runtime/issues/93008 This comes from F#, where interface method defined in F# doesn't have `newslot` flag in its m... — committed to vitek-karas/runtime by vitek-karas 8 months ago
- ILLink: Allow interface methods to not have newslot (#93662) Fixes https://github.com/dotnet/runtime/issues/93008 This comes from F#, where interface method defined in F# doesn't have `newslot` fl... — committed to dotnet/runtime by vitek-karas 8 months ago
- ILLink: Allow interface methods to not have newslot (#93662) Fixes https://github.com/dotnet/runtime/issues/93008 This comes from F#, where interface method defined in F# doesn't have `newslot` fl... — committed to liveans/dotnet-runtime by vitek-karas 8 months ago
- ILLink: Allow interface methods to not have newslot Fixes https://github.com/dotnet/runtime/issues/93008 This comes from F#, where interface method defined in F# doesn't have `newslot` flag in its m... — committed to dotnet/runtime by vitek-karas 8 months ago
But that’s exactly what the XML does today - if the resource is there, the trimmer will remove it. That’s what the XML tells it to do. Based on your description there are two cases:
If this is the goal, I personally would prefer we trim them by default but allow for an override, probably via a feature switch (like) setting. The second group (tools which want the resources) would have to opt-in to keep them if they do trim their tool.
I tested the same sample with ILC and NativeAOT trimming does not seem to have this problem. Therefore, I believe we should try to fix this in the linker.