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

[ios] Modifying code in library referenced by application results in AOT module loading failure #17708

Closed
frenzibyte opened this issue Mar 5, 2023 · 8 comments · Fixed by #18509
Labels
bug If an issue is a bug or a pull request a bug fix
Milestone

Comments

@frenzibyte
Copy link

Steps to Reproduce

  1. Clone https://github.com/frenzibyte/MissingAOTModule
  2. Deploy and run MissingAOTModule on physical device
  3. Edit string value of local variable in Class1.Something() to anything else
  4. Deploy and run again

Expected Behavior

Application runs again successfully after performing all steps above.

Actual Behavior

Application fails to run with the following error message:

2023-03-05 05:28:46.764 MissingAOTModule[2257:588544] error: Failed to load AOT module 'MissingAOTModule' while running in aot-only mode because a dependency cannot be found or it is out of date.

=================================================================
	Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

=================================================================
	Native stacktrace:
=================================================================
	0x10339c51c - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x103387618 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x1033dc62c - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x10339bd30 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x20db95a90 - /usr/lib/system/libsystem_platform.dylib : <redacted>
	0x20dc2f1ac - /usr/lib/system/libsystem_pthread.dylib : pthread_kill
	0x1c87e9ca0 - /usr/lib/system/libsystem_c.dylib : abort
	0x1030fe628 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : xamarin_find_protocol_wrapper_type
	0x1033d65f0 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x1033d6724 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x1033765a8 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x103262de4 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x103262904 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x103264500 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x1030fda98 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : xamarin_get_block_descriptor
	0x1030fd808 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : xamarin_get_block_descriptor
	0x1030fdc78 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : xamarin_get_block_descriptor
	0x10310f404 - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : xamarin_log
	0x1033d9e2c - /private/var/containers/Bundle/Application/20CB850F-E81B-4290-94D3-44EAFA0BBDD2/MissingAOTModule.app/MissingAOTModule : _ZNK3icu6number23NumberFormatterSettingsINS0_24LocalizedNumberFormatterEE10toSkeletonER10UErrorCode
	0x1df6a5948 - /usr/lib/dyld : <redacted>

=================================================================
	Basic Fault Address Reporting
=================================================================
Memory around native instruction pointer (0x1fd9f2200):0x1fd9f21f0  ff 0f 5f d6 c0 03 5f d6 10 29 80 d2 01 10 00 d4  .._..._..)......
0x1fd9f2200  03 01 00 54 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  ...T.#...{......
0x1fd9f2210  8e ed ff 97 bf 03 00 91 fd 7b c1 a8 ff 0f 5f d6  .........{...._.
0x1fd9f2220  c0 03 5f d6 7f 23 03 d5 fd 7b bf a9 fd 03 00 91  .._..#...{......

=================================================================
	Managed Stacktrace:
=================================================================
=================================================================
Application 'sh.ppy.MissingAOTModule' terminated (with exit code '' and/or crashing signal '6).

Environment

Version information
Visual Studio Community 2022 for Mac
Version 17.5 (build 1802)
Installation UUID: bceb643f-0f9e-497c-95b2-707c97319415

Runtime
.NET 7.0.1 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3

Roslyn (Language Service)
4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431

NuGet
Version: 6.4.0.117

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.201/Sdks
SDK Versions:
	7.0.201
	6.0.406
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.3
	6.0.14

Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Xamarin.Android
Version: 13.2.0.0 (Visual Studio Community)
Commit: xamarin-android/d17-5/797e2e1
Android SDK: Not found

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.5.0.33
Hash: f0c0c52
Branch: remotes/origin/d17-5~2
Build date: 1444-07-23 00:26:05 UTC

Android Device Manager
Version: 0.0.0.1245
Hash: 7f8a990
Branch: 7f8a990
Build date: 1444-07-23 00:26:05 UTC

Xamarin Designer
Version: 17.5.3.47
Hash: e8b5d371c3
Branch: remotes/origin/d17-5
Build date: 1444-07-23 00:26:00 UTC

Apple Developer Tools
Xcode: 14.2 21534
Build: 14C18

Xamarin.Mac
Version: 9.1.0.5 Visual Studio Community
Hash: 7738c90c9
Branch: xcode14.2
Build date: 2023-01-25 15:56:14-0500

Xamarin.iOS
Version: 16.2.0.5 Visual Studio Community
Hash: 7738c90c9
Branch: xcode14.2
Build date: 2023-01-25 15:56:15-0500

Build Information
Release ID: 1705001802
Git revision: bfdc90915981031f5bdda171c7eebf116a558598
Build date: 2023-02-14 00:24:08+00
Build branch: release-17.5
Build lane: release-17.5

Operating System
Mac OS X 13.0.1
Darwin 22.1.0 Darwin Kernel Version 22.1.0
    Sun Oct  9 20:15:09 PDT 2022
    root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64


Build Logs

msbuild-binlogs.zip

Example Project (If Possible)

MissingAOTModule.zip

@rolfbjarne
Copy link
Member

rolfbjarne commented Mar 6, 2023

I can reproduce this.

Helper script to reproduce:

git clean -xfd
git checkout iOSLibrary/Class1.cs
dotnet build /bl:build1.binlog MissingAOTModule/MissingAOTModule.csproj /p:RuntimeIdentifier=ios-arm64
sed -i '' s/\"test.*\"/\"test2\"/  iOSLibrary/Class1.cs
dotnet build /bl:build2.binlog MissingAOTModule/MissingAOTModule.csproj /p:RuntimeIdentifier=ios-arm64
launch-on-device

binlogs:
binlogs.zip

@rolfbjarne rolfbjarne added this to the .NET 8 milestone Mar 6, 2023
@rolfbjarne rolfbjarne added the bug If an issue is a bug or a pull request a bug fix label Mar 6, 2023
@rolfbjarne
Copy link
Member

The problem is that when iOSLibrary.dll changes, we must not only re-AOT iOSLibrary.dll (which we do), but also any assembly that references iOSLibrary.dll (which we don't).

@rolfbjarne
Copy link
Member

@kotlarmilos @ivanpovazan does the dedup feature (#17766) mean that if any assembly has changed, then every assembly needs to be AOT-compiled again?

@kotlarmilos
Copy link
Contributor

kotlarmilos commented Jun 29, 2023

The dedup assembly contains methods which have been removed from other assemblies. The compilation of the dedup assembly has two phases: in the first phase, methods are collected but not emitted, and in the second phase, the collected methods are emitted.

If any assembly has changed and AOT compiled with the dedup-skip flag, the dedup assembly must be AOT compiled again. This requires passing all assemblies for collection phase with the dedup-include flag, but not for the AOT compilation of the assemblies.

@ivanpovazan
Copy link
Contributor

@kotlarmilos so basically from the example above:

The problem is that when iOSLibrary.dll changes, we must not only re-AOT iOSLibrary.dll (which we do), but also any assembly that references iOSLibrary.dll (which we don't).

The rebuild should also reAOT the aot-instances.dll when _IsDedupEnabled=true right?

@kotlarmilos
Copy link
Contributor

Correct.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 29, 2023
If an assembly changes, then we must AOT compile that assembly again (which we already
did), in addition to any assembly that references the modified assembly (which we
didn't do).

So rework the AOTCompile target: remove the Inputs and Outputs (because the dependency
tracking is too complicated for MSBuild to resolve), and instead move the logic to
detect if an assembly must be AOT-compiled again into the AOTCompile task.

Fixes xamarin#17708.
rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 29, 2023
If an assembly changes, then we must AOT compile that assembly again (which we already
did), in addition to any assembly that references the modified assembly (which we
didn't do).

So rework the AOTCompile target: remove the Inputs and Outputs (because the dependency
tracking is too complicated for MSBuild to resolve), and instead move the logic to
detect if an assembly must be AOT-compiled again into the AOTCompile task.

This is a port of the [original fix for main][1] to .NET 8, where we have to
take the dedup assembly into account too: if any assembly has changed, then we
must re-aot the dedup assembly as well.

Fixes xamarin#17708.

[1]: xamarin#18509
rolfbjarne added a commit that referenced this issue Aug 7, 2023
If an assembly changes, then we must AOT compile that assembly again (which we already
did), in addition to any assembly that references the modified assembly (which we
didn't do).

So rework the AOTCompile target: remove the Inputs and Outputs (because the dependency
tracking is too complicated for MSBuild to resolve), and instead move the logic to
detect if an assembly must be AOT-compiled again into the AOTCompile task.

This is a port of the [original fix for main][1] to .NET 8, where we have to
take the dedup assembly into account too: if any assembly has changed, then we
must re-aot the dedup assembly as well.

Fixes #17708.

[1]: #18509

---------

Co-authored-by: Alex Soto <[email protected]>
rolfbjarne added a commit that referenced this issue Aug 7, 2023
If an assembly changes, then we must AOT compile that assembly again (which we already
did), in addition to any assembly that references the modified assembly (which we
didn't do).

So rework the AOTCompile target: remove the Inputs and Outputs (because the dependency
tracking is too complicated for MSBuild to resolve), and instead move the logic to
detect if an assembly must be AOT-compiled again into the AOTCompile task.

Note that this PR has a custom port to .NET 8: #18518.

Fixes #17708.

---------

Co-authored-by: Alex Soto <[email protected]>
vs-mobiletools-engineering-service2 pushed a commit to vs-mobiletools-engineering-service2/xamarin-macios that referenced this issue Aug 7, 2023
If an assembly changes, then we must AOT compile that assembly again (which we already
did), in addition to any assembly that references the modified assembly (which we
didn't do).

So rework the AOTCompile target: remove the Inputs and Outputs (because the dependency
tracking is too complicated for MSBuild to resolve), and instead move the logic to
detect if an assembly must be AOT-compiled again into the AOTCompile task.

Fixes xamarin#17708.
rolfbjarne added a commit that referenced this issue Sep 13, 2023
…. (#18654)

If an assembly changes, then we must AOT compile that assembly again (which we already
did), in addition to any assembly that references the modified assembly (which we
didn't do).

So rework the AOTCompile target: remove the Inputs and Outputs (because the dependency
tracking is too complicated for MSBuild to resolve), and instead move the logic to
detect if an assembly must be AOT-compiled again into the AOTCompile task.

Fixes #17708.

Backport of #18509

---------

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
@marcojak
Copy link

marcojak commented Nov 4, 2024

Is this bug still present in .NET 9 RC2? Because I'm experiencing the same issue.

@rolfbjarne
Copy link
Member

@marcojak no, this particular bug is fixed in .NET 9.

If you're still experiencing it, it's probably a different bug that looks the same, so please file a new issue and we'll have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants