Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing assemblyref for typeref only kept for debug info in illink #87575

Merged
merged 5 commits into from
Jun 16, 2023

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Jun 14, 2023

Fixes #86462 using the approach suggested in #86462 (comment). Initially I was looking into removing the unused typeref, but since we don't sweep debug info for save assemblies, I think it makes sense to keep it, even though this means the presence of the typeref in the final output depends on whether we are linking the PDB.

The fix also needed to walk up the parent import scopes, discovered by reproducing the issue in our test infra.

The behavior needs to depend on whether we are linking debug symbols, otherwise we will keep the assemblyref (but not the typeref that uses it) when PDBs are present, and I don't think the output should depend on the presence of PDBs. AssemblyOnlyUsedByUsingSaveAction tests this case - see comments in there for more detail.

This includes some unrelated test infra changes (supporting multiple additional compiler arguments) which were useful for iterating on this, even though they aren't necessary in the final version of the testcases.

When linking `save` assemblis with `-b true` (linking debug info), we preserve
all debug info (and don't sweep the debug info like we do for `link` assemblies).

With this change, we now take into account type references that are only referenced
by the debug info, preserving any assembly refs needed by them.

This adds test infra to walk the type references in the output assembly, and
check that they reference assembly refs that also exist in the output.

Includes some test infra changes that were ultimately not necessary for the repro,
but were useful, to allow passing multiple additional compiler args when compiling
testcase dependencies.
This should be adequately covered by NoLinkedOutputAttribute
@sbomer sbomer requested a review from vitek-karas June 14, 2023 19:27
@sbomer sbomer requested a review from marek-safar as a code owner June 14, 2023 19:27
@ghost ghost added the linkable-framework Issues associated with delivering a linker friendly framework label Jun 14, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jun 14, 2023
@ghost ghost assigned sbomer Jun 14, 2023
@ghost
Copy link

ghost commented Jun 14, 2023

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #86462 using the approach suggested in #86462 (comment). Initially I was looking into removing the unused typeref, but since we don't sweep debug info for save assemblies, I think it makes sense to keep it, even though this means the presence of the typeref in the final output depends on whether we are linking the PDB.

The fix also needed to walk up the parent import scopes, discovered by reproducing the issue in our test infra.

The behavior needs to depend on whether we are linking debug symbols, otherwise we will keep the assemblyref (but not the typeref that uses it) when PDBs are present, and I don't think the output should depend on the presence of PDBs. AssemblyOnlyUsedByUsingSaveAction tests this case - see comments in there for more detail.

This includes some unrelated test infra changes (supporting multiple additional compiler arguments) which were useful for iterating on this, even though they aren't necessary in the final version of the testcases.

Author: sbomer
Assignees: -
Labels:

linkable-framework, area-Tools-ILLink

Milestone: -

Copy link
Member

@filipnavara filipnavara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I got stuck on making the unit test for this, so I am glad you tackled it in the end.

@sbomer
Copy link
Member Author

sbomer commented Jun 14, 2023

Yeah, reproducing this in a unit test was challenging. Thanks a lot for the detailed issue report!

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks.

I find it weird that we intentionally leave a type ref/assembly ref in but remove the target from the app - but I guess that's what save is about. I got too used to true trimming recently with AOT and such.

@sbomer
Copy link
Member Author

sbomer commented Jun 16, 2023

It is a bit weird, but it's at least consistent with what we do for the other kept typerefs in save assemblies. It's also a bit weird that if we aren't linking debug symbols, we will actually remove both the typeref and the assemblyref in this example - but I think it makes sense for the reason I gave above.

@vitek-karas
Copy link
Member

I perfectly fine with the behavior regarding stripping symbols - I think it makes sense.

@sbomer sbomer merged commit af70c36 into dotnet:main Jun 16, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 17, 2023
@sbomer sbomer deleted the illinkUnusedUsingFIx branch November 3, 2023 18:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ILLink produces invalid IL metadata with -b switch and Save assembly mode
3 participants