Skip to content

ilc doesn't trim some code referenced only from trimmed methods #105806

@MrJul

Description

@MrJul

Description

In some cases, ilc keeps some code in the final executable, but the only code path accessing it has been trimmed.

Reproduction Steps

Clone https://github.com/MrJul/repro-ilc-not-trimming
Run dotnet publish -r win-x64

This is a very stripped down version of code from Avalonia reproducing the problem.
(Note that in this example, only one type is kept, but in Avalonia there are more.)

Expected behavior

Everything in LinuxLib is trimmed, only WindowsLib is referenced.

Actual behavior

X11RenderingMode from LinuxLib isn't trimmed, but all methods using it have been removed.

In the following screenshots, we can notice that X11RenderingMode is referenced from X11PlatformOptions's constructor, which has been trimmed away:
sizoscope types
sizoscope paths

Regression?

No.

Known Workarounds

No response

Configuration

Latest Microsoft.DotNet.ILCompiler from daily build, 9.0.0-rc.1.24381.5

Other information

For comparison, ILLink works fine in this scenario: no LinuxLib assembly is visible in the trimmed folder.

Note that with .NET 8.0.7, the whole call path (X11PlatformOptions, AvaloniaX11PlatformExtensions, etc.) is incorrectly kept by ilc.

With .NET 9.0.0-rc.1.24381.5, only X11RenderingMode is kept. I couldn't find the PR that fixed the above, but it's probably related to this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclrin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status

    No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions