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

[android] trimmer warning for System.Private.CoreLib.dll #100256

Closed
jonathanpeppers opened this issue Mar 25, 2024 · 2 comments · Fixed by #100263
Closed

[android] trimmer warning for System.Private.CoreLib.dll #100256

jonathanpeppers opened this issue Mar 25, 2024 · 2 comments · Fixed by #100263
Assignees
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Mar 25, 2024

Description

This appeared here:

dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.android-x86\9.0.0-preview.4.24173.6\runtimes\android-x86\native\System.Private.CoreLib.dll : warning IL2104: Assembly 'System.Private.CoreLib' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries 

-p:TrimmerSingleWarn=false yields additional information:

ILLink warning IL2045: System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled: Attribute 'System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute' is being referenced in code but the trimmer was instructed to remove all instances of this attribute. If the attribute instances are necessary make sure to either remove the trimmer attribute XML portion which removes the attribute instances, or override the removal by using the trimmer XML descriptor to keep the attribute type (which in turn keeps all of its instances).

Reproduction Steps

  • dotnet new android
  • dotnet build -c Release

Add -p:TrimmerSingleWarn=false to get a more detailed warning.

Expected behavior

No trimmer warnings.

Actual behavior

Trimmer warning about System.Private.CoreLib.dll.

Regression?

Yes

Known Workarounds

I suppose you could set -p:SuppressTrimAnalysisWarnings=true, but that is not ideal.

Configuration

.NET SDK: 9.0.100-preview.4.24175.5
.NET Runtime 9.0.0-preview.4.24173.6: 596a1f7...17f8138

Other information

Build logs: android-trimmer.zip

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Mar 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 25, 2024
@akoeplinger akoeplinger added area-Tools-ILLink .NET linker development as well as trimming analyzers and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Mar 25, 2024
@akoeplinger akoeplinger added the linkable-framework Issues associated with delivering a linker friendly framework label Mar 25, 2024
@filipnavara
Copy link
Member

Introduced by #99641. /cc @sbomer

@jonathanpeppers
Copy link
Member Author

jonathanpeppers commented Mar 27, 2024

This is happening here (.NET 9 Preview 3) as well: dotnet/android#8838

jonathanpeppers added a commit to dotnet/android that referenced this issue Mar 27, 2024
jonathanpeppers added a commit to dotnet/android that referenced this issue Mar 27, 2024
dalexsoto added a commit to xamarin/xamarin-macios that referenced this issue Mar 28, 2024
dalexsoto added a commit to xamarin/xamarin-macios that referenced this issue Mar 28, 2024
jonathanpeppers added a commit to dotnet/android that referenced this issue Mar 28, 2024
Changes: dotnet/installer@0752378...09d6f38
Changes: dotnet/runtime@596a1f7...9e6ba1f
Changes: dotnet/emsdk@a5f4de7...cf04702
Changes: dotnet/cecil@ba53c75...896cafe

Updates:

* Microsoft.Dotnet.Sdk.Internal: from 9.0.100-preview.3.24175.18 to 9.0.100-preview.3.24175.24
* Microsoft.NETCore.App.Ref: from 9.0.0-preview.3.24162.31 to 9.0.0-preview.3.24172.9
* Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport: from 9.0.0-preview.3.24156.3 to 9.0.0-preview.3.24171.4
* Microsoft.NET.ILLink.Tasks: from 9.0.0-preview.3.24162.31 to 9.0.0-preview.3.24172.9
* Microsoft.DotNet.Cecil: from 0.11.4-alpha.24158.1 to 0.11.4-alpha.24161.3

Other changes:

* [tests] set `$(TrimmerSingleWarn)` to false

This allows us to get more information, in the case of new trimmer warnings.

* Default `$(_AndroidIncludeSystemGlobalizationNative)` to true

Prevents runtime crash:

    03-25 19:42:25.386  8502  8502 W Mono    : DllImport unable to load library 'libSystem.Globalization.Native'.
    03-25 19:42:25.409  8502  8502 W         : Process terminated.

* Update `.apkdesc` files for `libSystem.Globalization.Native.so`

* FIXME: dotnet/runtime#100256

Various tests have the trimmer warning:

    dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.android-x86\9.0.0-preview.4.24173.6\runtimes\android-x86\native\System.Private.CoreLib.dll : warning IL2104: Assembly 'System.Private.CoreLib' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries 

    ILLink warning IL2045: System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled: Attribute 'System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute' is being referenced in code but the trimmer was instructed to remove all instances of this attribute. If the attribute instances are necessary make sure to either remove the trimmer attribute XML portion which removes the attribute instances, or override the removal by using the trimmer XML descriptor to keep the attribute type (which in turn keeps all of its instances).

For now, we can assert there are 4 warnings (one per RID).

When this is fixed in the future, we can go back to asserting 0 warnings.

Co-authored-by: Jonathan Peppers <[email protected]>
jonathanpeppers added a commit to dotnet/android that referenced this issue Mar 28, 2024
Changes: dotnet/installer@b40c445...dc43d36
Changes: dotnet/runtime@596a1f7...17f8138
Changes: dotnet/emsdk@a5f4de7...5dd0620
Changes: dotnet/cecil@ba53c75...9c8ea96

Updates:

* Microsoft.Dotnet.Sdk.Internal: from 9.0.100-preview.3.24165.20 to 9.0.100-preview.4.24175.5
* Microsoft.NETCore.App.Ref: from 9.0.0-preview.3.24162.31 to 9.0.0-preview.4.24173.6
* Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport: from 9.0.0-preview.3.24156.3 to 9.0.0-preview.3.24160.1
* Microsoft.NET.ILLink.Tasks: from 9.0.0-preview.3.24162.31 to 9.0.0-preview.4.24173.6
* Microsoft.DotNet.Cecil: from 0.11.4-alpha.24158.1 to 0.11.4-alpha.24168.1

Other changes:

* [tests] set `$(TrimmerSingleWarn)` to false

This allows us to get more information, in the case of new trimmer warnings.

* Default `$(_AndroidIncludeSystemGlobalizationNative)` to true

Prevents runtime crash:

    03-25 19:42:25.386  8502  8502 W Mono    : DllImport unable to load library 'libSystem.Globalization.Native'.
    03-25 19:42:25.409  8502  8502 W         : Process terminated.

* Update `.apkdesc` files for `libSystem.Globalization.Native.so`

* FIXME: dotnet/runtime#100256

Various tests have the trimmer warning:

    dotnet\packs\Microsoft.NETCore.App.Runtime.Mono.android-x86\9.0.0-preview.4.24173.6\runtimes\android-x86\native\System.Private.CoreLib.dll : warning IL2104: Assembly 'System.Private.CoreLib' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries 

    ILLink warning IL2045: System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled: Attribute 'System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute' is being referenced in code but the trimmer was instructed to remove all instances of this attribute. If the attribute instances are necessary make sure to either remove the trimmer attribute XML portion which removes the attribute instances, or override the removal by using the trimmer XML descriptor to keep the attribute type (which in turn keeps all of its instances).

For now, we can assert there are 4 warnings (one per RID).

When this is fixed in the future, we can go back to asserting 0 warnings.

Co-authored-by: Jonathan Peppers <[email protected]>
sbomer added a commit that referenced this issue Mar 28, 2024
…100263)

Under AggressiveAttributeTrimming setting.

Fixes
#100256. AggressiveAttributeTrimming
was attempting to remove RequiresDynamicCode attributes, but the
type was still referenced by FeatureGuardAttribute on
IsDynamicCodeCompiled.

Adding FeatureGuardAttribute to the set of attributes that get
removed with AggressiveAttributeTrimming fixes this. Also adding
FeatureSwitchDefinitionAttribute because that one can be removed
as well.
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Mar 28, 2024
jonathanpeppers added a commit to dotnet/android that referenced this issue Apr 8, 2024
jonathanpeppers added a commit to dotnet/android that referenced this issue Apr 9, 2024
Changes: dotnet/installer@dc43d36...0bfd2dd
Changes: dotnet/runtime@17f8138...ffb2578
Changes: dotnet/emsdk@5dd0620...bd79d3d

Updates:

* Microsoft.Dotnet.Sdk.Internal: from 9.0.100-preview.4.24175.5 to 9.0.100-preview.4.24208.2
* Microsoft.NETCore.App.Ref: from 9.0.0-preview.4.24173.6 to 9.0.0-preview.4.24204.3
* Microsoft.NET.Workload.Emscripten.Current.Manifest-9.0.100.Transport: from 9.0.0-preview.3.24160.1 to 9.0.0-preview.4.24201.2
* Microsoft.NET.ILLink.Tasks: from 9.0.0-preview.4.24173.6 to 9.0.0-preview.4.24204.3

Other changes:

* [tests] we can assert 0 trimmer warnings again

This is fixed: dotnet/runtime#100256

Co-authored-by: Jonathan Peppers <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 28, 2024
matouskozak pushed a commit to matouskozak/runtime that referenced this issue Apr 30, 2024
…otnet#100263)

Under AggressiveAttributeTrimming setting.

Fixes
dotnet#100256. AggressiveAttributeTrimming
was attempting to remove RequiresDynamicCode attributes, but the
type was still referenced by FeatureGuardAttribute on
IsDynamicCodeCompiled.

Adding FeatureGuardAttribute to the set of attributes that get
removed with AggressiveAttributeTrimming fixes this. Also adding
FeatureSwitchDefinitionAttribute because that one can be removed
as well.
Ruihan-Yin pushed a commit to Ruihan-Yin/runtime that referenced this issue May 30, 2024
…otnet#100263)

Under AggressiveAttributeTrimming setting.

Fixes
dotnet#100256. AggressiveAttributeTrimming
was attempting to remove RequiresDynamicCode attributes, but the
type was still referenced by FeatureGuardAttribute on
IsDynamicCodeCompiled.

Adding FeatureGuardAttribute to the set of attributes that get
removed with AggressiveAttributeTrimming fixes this. Also adding
FeatureSwitchDefinitionAttribute because that one can be removed
as well.
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
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants