Bridges the worlds of .NET with the native APIs of macOS, iOS, tvOS, and watchOS.
Перейти к файлу
Alex Soto 73038144e7
[net9.0] Reenable dedup optimization for all AOT modes (#20941)
Backport of #20936

---

## Description

As part of the fix for: https://github.com/dotnet/runtime/issues/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:
https://github.com/xamarin/xamarin-macios/issues/20848

However, it turns out that disabling dedup optimization is not required
to fix https://github.com/dotnet/runtime/issues/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
https://github.com/dotnet/runtime/issues/99248 is built with dedup
enabled in hybrid AOT+interpreter mode, the app crashes with:
```
024-07-23 14:32:37.524110+0200 IvansApp[12711:20244208] debug: AOT NOT FOUND: (wrapper other) object:gsharedvt_out_sig (intptr).
2024-07-23 14:32:37.524120+0200 IvansApp[12711:20244208] error: * Assertion at /Users/ivan/repos/runtime-mono-iOS/src/mono/mono/mini/interp/interp.c:2667, condition `is_ok (error)' not met, function:init_jit_call_info, Attempting to JIT compile method '(wrapper other) void object:gsharedvt_out_sig (intptr)' while running in aot-only mode. See https://learn.microsoft.com/xamarin/ios/internals/limitations for more information.
```

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 generated

- In hybrid AOT + interpreter setup - all assemblies AOT compiled:
`MtouchInterpreter=-all`
    - Dedup OFF:
- `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)
    - Dedup ON:
- `gsharedvt_out_sig` methods are generated only in `aot-instances` AOT
image
- during AOT compilation of individual assemblies generation of
`gsharedvt_out_sig` is skipped
- during AOT compilation of `aot-instances` assembly we collect all
`gsharedvt_out_sig` variants from the full program scope and generate
code for them in `aot-instances` AOT image

- In hybrid AOT + interpreter setup - all assemblies interpreted except
a given assembly: `MtouchInterpreter=all,-MyAssembly`
    - Dedup OFF:
- `gsharedvt_out_sig` methods are generated in AOT image of `MyAssembly`
(to enable interpreter calling into it)
    - Dedup ON: <- $${\color{red} ISSUE }$$ 
- `gsharedvt_out_sig` methods *should* be generated only in
`aot-instances` AOT image, but the `aot-instances` image is missing
    - explanation:
- what happens is that generation of `gsharedvt_out_sig` is skipped
during AOT compilation of `MyAssembly` (as expected).
- But, the build does not mark `aot-instances` assembly as the one that
should be AOT compiled.
- The reason for this is that we have a global `_IsDedupEnabled` flag,
but when custom linker step analysis `aot-instances.dll` it does not see
it as an assembly which should not be interpreted.
- To explain that better: we mark *all* assemblies as to be interpreted
(via: `MtouchInterpreter=all`), but exclude only `MyAssembly` (via:
`MtouchInterpreter=all,-MyAssembly`).
- So when custom linker step processes `aot-instaces.dll` it treats it
as an assembly to be interpreted, so it does not mark it for AOT
compilation.
- This further results with `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:
https://github.com/xamarin/xamarin-macios/issues/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.

---------

Co-authored-by: Ivan Povazan <ivan.povazan@gmail.com>
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
2024-07-26 14:47:25 -04:00
.config [main] Update dependencies from dotnet/installer (#15119) 2022-05-26 08:51:49 +02:00
.github [net9.0] Merge main into net9.0. 2024-07-08 18:45:06 +02:00
Localize Update AOTCompile task to handle cycles in up-to-date check (#20103) 2024-02-15 17:29:18 +01:00
builds Merge remote-tracking branch 'xamarin/main' into dev/alex/main-net9.0 2024-07-11 18:53:54 -04:00
docs [net9.0] Merge main into net9.0. 2024-06-12 15:08:25 +02:00
dotnet [net9.0] Reenable dedup optimization for all AOT modes (#20941) 2024-07-26 14:47:25 -04:00
eng [net9.0] Update dependencies from dotnet/sdk (#20898) 2024-07-25 22:00:04 -04:00
external Bump Xamarin.MacDev. (#20518) 2024-04-26 09:09:10 +02:00
fsharp Add config file for libmono-native dllmap 2019-03-13 00:34:47 +01:00
jenkins [jenkins] Jenkins is dead, long live ~Wrench~ Azure Devops. (#16396) 2022-10-21 10:05:59 +02:00
mk [msbuild/dotnet] Automatically link with Swift's system libraries if a binding project has the IsSwift=true property. (#20546) 2024-05-20 20:17:29 +02:00
mono Add config file for libmono-native dllmap 2019-03-13 00:34:47 +01:00
msbuild Merge remote-tracking branch 'origin/main' into net9.0 2024-07-19 15:26:35 -04:00
release [dotnet] Rename packs to contain target framework. (#19765) 2024-02-19 13:14:20 +01:00
runtime [net9.0] Merge main into net9.0. 2024-06-21 11:19:27 +02:00
src Merge remote-tracking branch 'xamarin/main' into dev/alex/main-net9.0 2024-07-11 18:53:54 -04:00
tests [net9.0] Reenable dedup optimization for all AOT modes (#20941) 2024-07-26 14:47:25 -04:00
tools [net9.0] Reenable dedup optimization for all AOT modes (#20941) 2024-07-26 14:47:25 -04:00
.editorconfig Update editorconfig. (#19909) 2024-01-26 08:24:58 +01:00
.gitattributes [dotnet] Fix line endings in template localizations. (#16981) 2022-12-12 17:12:35 +01:00
.gitignore [net8.0] [build] Require using EnablePreviewFeatures=true when using preview releases. Contributes towards #18343. (#18476) 2023-06-22 08:16:50 +02:00
.gitmodules [Build] Update submodules remotes. (#19632) 2023-12-18 11:45:25 -05:00
CODEOWNERS [WebKit] Merge WKWebKit into WebKit. (#17062) 2022-12-19 18:37:53 +01:00
DOWNLOADS.md Update DOWNLOADS.md with new releases. (#19595) 2023-12-11 08:47:13 +01:00
Directory.Build.props [net9.0] Update dependencies from dotnet/installer (#19844) 2024-01-23 07:24:51 +01:00
ISSUE_TEMPLATE.md Add newlines to issue template to fix markdown formatting problems. (#15152) 2022-05-31 18:43:01 +02:00
LICENSE
Make.config Merge remote-tracking branch 'xamarin/main' into dev/alex/main-net9.0 2024-07-11 18:53:54 -04:00
Make.versions [net9.0] Bump to Xcode 15.4 packages instead of Xcode 15.1 packages as the latest .NET 8 stable. (#20888) 2024-07-15 13:55:15 -04:00
Makefile [build] Add support for worktree checkouts (#19240) 2023-10-19 09:22:37 -07:00
NOTICE.txt Add NOTICE.txt and cgmanifest tool (#8843) 2020-06-12 14:30:21 -05:00
NuGet.config [net9.0] Update dependencies from dotnet/sdk (#20898) 2024-07-25 22:00:04 -04:00
README.md Update README (#20536) 2024-05-01 08:29:31 +02:00
SECURITY.MD Add SECURITY.MD to repo (as suggested by OSPO) (#7019) 2019-09-19 17:44:22 -04:00
Versions-ios.plist.in Merge remote-tracking branch 'xamarin/main' into dev/alex/main-net9.0 2024-07-11 18:53:54 -04:00
Versions-mac.plist.in Merge remote-tracking branch 'xamarin/main' into dev/alex/main-net9.0 2024-07-11 18:53:54 -04:00
Xamarin.Mac.sln Fix path to dont link project in Xamarin.Mac.sln. (#8109) 2020-03-16 09:42:52 +01:00
Xamarin.iOS.sln [tests] Make the mtouch test project reference the actual mtouch project. (#11400) 2021-05-04 14:10:03 +02:00
banner.png
configure convert to if ... fi 2023-11-30 21:58:56 -05:00
create-make-config.sh Encode the .NET version we're targeting in the third NuGet version number. (#17818) 2023-03-17 07:39:59 +01:00
global.json [net9.0] Update dependencies from dotnet/sdk (#20898) 2024-07-25 22:00:04 -04:00
mac-entitlements.plist Implement notarization. (#6928) 2019-09-09 00:34:11 -07:00
product.snk
system-dependencies.sh [system-dependencies] Only download the simulators for platforms we target. (#20842) 2024-07-10 12:58:16 +02:00
versions-check.csharp [dotnet] Differentiate between "OS version we support as TargetPlatformVersion" and "OS version we support or have supported". (#19882) 2024-01-23 19:17:25 +01:00

README.md

.NET for iOS, Mac Catalyst, macOS, tvOS

Welcome!

This module is the main repository for:

  • .NET for iOS
  • .NET for Mac Catalyst
  • .NET for macOS
  • .NET for tvOS

These SDKs allow us to create native iOS, Mac Catalyst, macOS and tvOS applications using the same UI controls we would in Objective-C and Xcode, except with the flexibility and elegance of a modern language (C#), the power of the .NET Base Class Library (BCL), and first-class IDEs and editors—Visual Studio and Visual Studio Code—at our fingertips.

This repository is where we do development for the .NET for iOS, Mac Catalyst, macOS, and tvOS SDKs. .NET for iOS, Mac Catalyst, macOS, and tvOS are part of .NET MAUI, and may also be used independently for native iOS and macOS development with .NET.

There are a few ways that you can contribute, for example:

Support

.NET for iOS, Mac Catalyst, macOS, and tvOS are part of .NET MAUI, since it was introduced in May 2022 as part of .NET 6, and is currently supported as described on the .NET MAUI Support Policy.

Support for Xamarin.iOS and Xamarin.Mac ended on May 1, 2024 as per the Xamarin Support Policy:

Xamarin support ended on May 1, 2024 for all Xamarin SDKs including Xamarin.Forms. Android API 34 and Xcode 15 SDKs (iOS and iPadOS 17, macOS 14) are the final versions Xamarin targets from existing Xamarin SDKs (i.e. no new APIs are planned).

Contributing

If you are interested in fixing issues and contributing directly to the code base, please see the document How to Contribute, which covers the following:

Downloads

The preferred method for installing Xamarin.iOS and Mac is to use the Visual Studio installers (Windows, Mac).

The team also strongly recommends using the latest Xamarin SDK and Xcode whenever possible.

However, we provide links to older Xamarin.iOS and Mac packages for macOS downgrades and build machine configuration, see Downloads.

Feedback

Discord

License

Copyright (c) .NET Foundation Contributors. All rights reserved. Licensed under the MIT License.