[release/8.0.1xx-xcode15.4] Reenable dedup optimization for all AOT modes #20940
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.
Description
As part of the fix for: dotnet/runtime#99248 we disabled dedup optimization in partial/hybrid AOT mode (when both interpreter and AOT compiler are enabled). This change got backported to .NET 8 and with the latest servicing release regressed build times and app sizes significantly as reported in: #20848
However, it turns out that disabling dedup optimization is not required to fix dotnet/runtime#99248 but instead we should correct the Xamarin SDK integration with this optimization which this PR is doing. The following section describes the initial problem in more details.
Overview of AOT modes and dedup optimization
When the repro project from dotnet/runtime#99248 is built with dedup enabled in hybrid AOT+interpreter mode, the app crashes with:
To track down why these wrappers which are used to transition from interpreter to AOT code, are not generated we need to understand when they are compiled in different AOT modes with and without dedup optimization enabled:
In full AOT setup - all assemblies AOT compiled
gsharedvt_out_sig
methods are never generatedIn hybrid AOT + interpreter setup - all assemblies AOT compiled:
MtouchInterpreter=-all
gsharedvt_out_sig
methods are generated in AOT images of every assembly (to enable interpreter calling into each specific assembly - here wrappers with same signatures are duplicated)gsharedvt_out_sig
methods are generated only inaot-instances
AOT imagegsharedvt_out_sig
is skippedaot-instances
assembly we collect allgsharedvt_out_sig
variants from the full program scope and generate code for them inaot-instances
AOT imageIn hybrid AOT + interpreter setup - all assemblies interpreted except a given assembly:
MtouchInterpreter=all,-MyAssembly
gsharedvt_out_sig
methods are generated in AOT image ofMyAssembly
(to enable interpreter calling into it)gsharedvt_out_sig
methods should be generated only inaot-instances
AOT image, but theaot-instances
image is missinggsharedvt_out_sig
is skipped during AOT compilation ofMyAssembly
(as expected).aot-instances
assembly as the one that should be AOT compiled._IsDedupEnabled
flag, but when custom linker step analysisaot-instances.dll
it does not see it as an assembly which should not be interpreted.MtouchInterpreter=all
), but exclude onlyMyAssembly
(via:MtouchInterpreter=all,-MyAssembly
).aot-instaces.dll
it treats it as an assembly to be interpreted, so it does not mark it for AOT compilation.aot-instances
AOT image missing, and all the methods which we skipped during AOT compilation never get generated.The fix
To fix this and address regressions reported in: #20848 we are reenabling dedup optimization whenever AOT compilation is requested and fixing the issue where the custom linker step for generating AOT parameters always treates the dedup assembly as the one to be AOTed.
Once approved this should be backported to .NET 8 as servicing releases are also affected with it.
Backport of #20936