-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Trimming] Fix startup crash when TypeMapAssemblyTarget attribute survives but target assembly is fully trimmed #130589
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c30fd11
Initial plan
Copilot dcf1d89
Fix TypeMapAssemblyTarget attribute removal when target assembly has …
Copilot 2c9bb9f
Address code review: rename param, improve comments in TypeMapHandler…
Copilot 516910c
Revert CoreCLR assemblynative.cpp changes - fix is trimmer-only
Copilot 1a5f5d0
Potential fix for pull request finding
jtschuster 27cd6c1
Fix ordering: call TriggerPendingAssemblyTargets from MarkAssembly in…
Copilot 0d63a40
Remove redundant TriggerPendingAssemblyTargets call from MarkTypeMapA…
Copilot e25f2fb
Preserve TypeMap assembly target fast path
jtschuster a5eaec7
Add TypeMap test to ILTrim expected failures
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...k/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/TypeMapAllConditionalEntriesDep.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| // All TypeMap entries in this assembly are conditional (3-argument form). | ||
| // The trim target (AllConditionalTrimTarget) is never referenced by the test assembly, | ||
| // so ILLink drops the entry, which leaves this assembly with no surviving TypeMap entries. | ||
| // The test verifies that the TypeMapAssemblyTarget attribute pointing here is also removed. | ||
| using System.Runtime.InteropServices; | ||
| using Mono.Linker.Tests.Cases.Reflection.Dependencies; | ||
|
|
||
| [assembly: TypeMap<AllConditionalGroupType>("ConditionalEntry", typeof(AllConditionalTarget), typeof(AllConditionalTrimTarget))] | ||
|
|
||
| namespace Mono.Linker.Tests.Cases.Reflection.Dependencies | ||
| { | ||
| public class AllConditionalTarget; | ||
| public class AllConditionalTrimTarget; | ||
| } |
10 changes: 10 additions & 0 deletions
10
...ink/test/Mono.Linker.Tests.Cases/Reflection/Dependencies/TypeMapAllConditionalGroupDep.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Mono.Linker.Tests.Cases.Reflection.Dependencies | ||
| { | ||
| // Group marker type used by TypeMapAssemblyTargetRemovedWhenAllEntriesTrimmed. | ||
| // Lives in its own assembly so the test assembly's TypeMapAssemblyTarget<AllConditionalGroupType> | ||
| // generic argument does not create a compile-time reference to the conditional.dll dependency. | ||
| public class AllConditionalGroupType; | ||
| } |
37 changes: 37 additions & 0 deletions
37
...t/Mono.Linker.Tests.Cases/Reflection/TypeMapAssemblyTargetRemovedWhenAllEntriesTrimmed.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
| using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
| using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
| using Mono.Linker.Tests.Cases.Reflection.Dependencies; | ||
|
|
||
| // The test assembly references "conditional.dll" only by the assembly name string. | ||
| // All TypeMap entries in conditional.dll are conditional on AllConditionalTrimTarget, | ||
| // which is never marked. So conditional.dll ends up with no surviving TypeMap entries. | ||
| // The fix should cause this TypeMapAssemblyTarget attribute to be removed from the linked output. | ||
| [assembly: TypeMapAssemblyTarget<AllConditionalGroupType>("conditional")] | ||
|
|
||
| namespace Mono.Linker.Tests.Cases.Reflection | ||
| { | ||
| // Compile the group-type assembly first so both the test assembly and conditional.dll can reference it. | ||
| // Compile conditional.dll second with addAsReference:false so the test assembly has no compile-time | ||
| // dependency on it (only the string reference in TypeMapAssemblyTarget). | ||
| [SetupCompileBefore("allconditionalgroup.dll", new[] { "Dependencies/TypeMapAllConditionalGroupDep.cs" })] | ||
| [SetupCompileBefore("conditional.dll", new[] { "Dependencies/TypeMapAllConditionalEntriesDep.cs" }, | ||
| references: new[] { "allconditionalgroup.dll" }, addAsReference: false)] | ||
| [SetupLinkerAction("link", "System.Private.CoreLib")] // Needed to apply embedded XML (RemoveAttributeInstances) | ||
| [SetupLinkerArgument("--ignore-link-attributes", "false")] | ||
| [RemovedAssembly("conditional.dll")] | ||
| [RemovedAttributeInAssembly("test", typeof(TypeMapAssemblyTargetAttribute<AllConditionalGroupType>))] | ||
| [Kept] | ||
| class TypeMapAssemblyTargetRemovedWhenAllEntriesTrimmed | ||
|
Copilot marked this conversation as resolved.
|
||
| { | ||
| [Kept] | ||
| static void Main() | ||
| { | ||
| // Use the group so the trimmer processes the TypeMapAssemblyTarget attribute. | ||
| _ = TypeMapping.GetOrCreateExternalTypeMapping<AllConditionalGroupType>(); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.