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

Most upvoted comments

we don’t necessary want to trim them by default.

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:

  • People just building normal apps with F# - the resources are not needed in this case and should be removed to save size.
  • People using F# for some specialized tools - some of these might want to keep the resources.

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.