-
Notifications
You must be signed in to change notification settings - Fork 520
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
[net10.0] Aggressive attribute trimming breaks NativeAOT builds #22065
Comments
Isn't the workaround setting the feature to |
Context: xamarin/xamarin-macios#22065 The introduction of a new `$(MobileAggressiveAttributeTrimming)` MSBuild property in .NET 10 breaks NativeAOT builds in two ways: * C# attributes are stripped away by ILLink, hence: * Trimmer warnings are introduced. * App crashes can result, with IL removed that *shouldn't* be. Let's set `$(MobileAggressiveAttributeTrimming)` to `false` for now to avoid these issues. In a future PR, we can address xamarin-macios#22065 in the iOS workload.
Context: xamarin/xamarin-macios#22065 The introduction of a new `$(MobileAggressiveAttributeTrimming)` MSBuild property in .NET 10 breaks NativeAOT builds in two ways: * C# attributes are stripped away by ILLink, hence: * Trimmer warnings are introduced. * App crashes can result, with IL removed that *shouldn't* be. Let's set `$(MobileAggressiveAttributeTrimming)` to `false` for now to avoid these issues. In a future PR, we can address xamarin-macios#22065 in the iOS workload.
If we really need this (personally I would prefer slightly bigger apps which work more often, over slightly smaller apps which break more often, but this is up to the iOS team to decide) I think we should make two changes to this:
|
…ativeAOT. Fixes #22065. Aggressive attribute trimming removes attributes used by the trimmer. This is fine as long as we don't run _two_ trimmers - because then the first pass would remove attributes needed by the second pass, which is exactly what happens when we're building using NativeAOT: we first run ILLink, then NativeAOT's trimmer. If aggressive attribute trimming is enabled in this scenario, ILLink will remove attributes required by NativeAOT to work correctly, so disable aggressive attribute trimming. Fixes #22065.
This might result in a rather unintuitive result:
I've created a PR with this change. We have fewer compatibility concerns with NativeAOT, while at the same time we have a bigger correctness promise, so this seemed like the best way forward. |
I think the same thing you mentioned for NativeAOT applies to TrimMode=full: "We have fewer compatibility concerns with NativeAOT, while at the same time we have a bigger correctness promise". |
Apple platform
Mac Catalyst, iOS
Framework version
net10.0-*
Affected platform version
.NET 10 P1
Description
The recent addition of the switch/build property
MobileAggressiveAttributeTrimming
which enables aggressive attribute trimming in .NET 10 (#21314) causes problems with NativeAOT builds. This problem surfaced in dotnet/maui#27103When the feature switch is enabled (the default behavior), ILLink removes all
[DynamicallyAccessedMembers]
and when ILC builds a NativeAOT binary, it cannot see these annotations anymore and it produces trim warnings and the final binary most likely won't work as expected.I see two possible fixes:
MobileAggressiveAttributeTrimming
for NativeAOT builds and let ILC trim unnecessary attributesDynamicallyAccessedMembersAttribute
fromTrimAttributes.LinkDescription.xml
.System.Diagnostics.CodeAnalysis
namespace for static analysis of the program, such as theFeatureGuardAttribute
./cc @rolfbjarne @jonathanpeppers @sbomer
Steps to Reproduce
<PublishAot Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">true</PublishAot>
to the project filenet10.0
branch with this command:$(MAUI_DIR)/dotnet-local.sh publish -f net10.0-maccatalyst -r maccatalyst-arm64 -p:TrimmerSingleWarn=false
Did you find any workaround?
Set
$(MobileAggressiveAttributeTrimming)=false
in the MAUI project.Build logs
The text was updated successfully, but these errors were encountered: