Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Add diagnostics mode to linker #592

Closed

Description

@marek-safar

We need to add diagnostics mode to the linker to make it easier for the developers to track down situation where linker removes too much code (for example because of reflection).

We could add a new mode/action like linkdiag where instead of removing the methods we would rewrite the bodies to always throw an exception. It's not exactly matching the link mode output because the metadata are still there but it could help in some cases.

Activity

  1. mrvoorhe commented on Jun 3, 2019

    @mrvoorhe
    Contributor

    I've thought about adding such a feature before. I'd be curious to see how useful it is. I do think you'll have to take the results with a grain of salt. Keeping methods that would previously be removed will still have a considerable knock on effect. Ex: Parameter and return types will be marked. Interfaces will be marked. That could lead to default ctors being fully marked that would have otherwise been removed. That could ripple and cause a lot more stuff to be marked.

  2. MichalStrehovsky commented on Apr 1, 2020

    @MichalStrehovsky
    Member

    I've thought about adding such a feature before. I'd be curious to see how useful it is. I do think you'll have to take the results with a grain of salt. Keeping methods that would previously be removed will still have a considerable knock on effect. Ex: Parameter and return types will be marked. Interfaces will be marked. That could lead to default ctors being fully marked that would have otherwise been removed. That could ripple and cause a lot more stuff to be marked.

    The CoreRT compiler has such option (dotnet/corert#6149) and it pretty much eliminated a class of issues with mysterious NullReferenceException the project was regularly getting (that were pretty much always cause by something like Type.GetMethod returning null).

    CoreRT avoids the knock on effect by generating an (unresolvable) TypeReference for parameter types that wouldn't otherwise be generated. It can afford to do so because the reflection metadata is really only consumed by the reflection stack and the rest of the system doesn't care about it (everything was already done AOT).

    I suspect this is going to be more complicated to pull of when dealing with real metadata that is actually used to build things like vtables and interface dispatch maps at runtime.

    Hopefully with the linker warning infrastructure we're building for .NET 5, the need for this will be reduced enough that it's not necessary.

  3. marek-safar commented on Apr 1, 2020

    @marek-safar
    ContributorAuthor

    Yeah, let's revisit this after we have the reflection warnings/errors support in.

  4. vitek-karas commented on Sep 12, 2022

    @vitek-karas
    Member

    @sbomer, @MichalStrehovsky, @marek-safar do you think something like this still makes sense. Basically everything should be covered by warnings and this would only be useful when ignoring warnings.

  5. sbomer commented on Sep 12, 2022

    @sbomer
    Member

    My opinion - I think with trim analysis warnings this is not needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions