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

Failed to AOT compile Microsoft.Graph.dll, the AOT compiler exited with code 134 #18388

Closed
NickDarvey opened this issue Jun 1, 2023 · 13 comments
Milestone

Comments

@NickDarvey
Copy link

NickDarvey commented Jun 1, 2023

Steps to Reproduce

  1. Clone https://github.com/microsoftgraph/msgraph-sample-maui
  2. Remove bundle resource 'appSettings.Development.json' from project
  3. Run dotnet publish -c Release -f net7.0-ios16.1 -r ios-arm64
  4. Wait ~1 hour because of Build in Release mode never ending microsoftgraph/msgraph-sample-maui#68

Expected Behavior

App is published.

Actual Behavior

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.2.1024/targets/Xamarin.Shared.Sdk.targets(1011,3): Failed to AOT compile Microsoft.Graph.dll, the AOT compiler exited with code 134

If I use <UseInterpreter>true</UseInterpreter>, the build succeeds.

Environment

  • dotnet 7.0.100
  • Microsoft.iOS.Sdk 16.2.1024

Build Logs

msbuild_(6).zip

Example Project

https://github.com/microsoftgraph/msgraph-sample-maui

@NickDarvey
Copy link
Author

NickDarvey commented Jun 1, 2023

Wait ~1 hour because of microsoftgraph/msgraph-sample-maui#68

I'm trying to work around this issue so that we can at least reach the AOT compilation error faster.

Almost all of this 1 hour is spent in the Microsoft.NET.ILLink.targets/ILLink task.

The Microsoft.Graph.dll is only copied/skipped by the linker, but if I remove it from ManagedAssemblyToLink (the argument to ILLink's AssemblyPaths parameter) the time drops to ~10 minutes.

<ItemGroup>
    <UnanalyzableAssembly Include="Microsoft.Graph" />
</ItemGroup>

<Target Name="ConfigureTrimming"
    BeforeTargets="PrepareForILLink">
    <ItemGroup>
        <_UnanalyzableManagedAssemblyToLink Include="@(UnanalyzableAssembly)" NuGetPackageId="%(Identity)" />
        <ManagedAssemblyToLink Remove="@(_UnanalyzableManagedAssemblyToLink)" MatchOnMetadata="NuGetPackageId" />
    </ItemGroup>
</Target>

However, in our project (not the sample project) doing so then causes the AOT compilation to fail on the app instead.

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/16.2.1024/targets/Xamarin.Shared.Sdk.targets(1011,3): Failed to AOT compile MyApp.dll, the AOT compiler exited with code 139

It looks like excluding an assembly from ManagedAssemblyToLink causes it to be omitted from _AssembliesToAOT and my assumptions is that is what is causing the compiler to fail on GraphMAUI.dll. So, my next step is to see if I can reinstate it after the linker runs but before the AOT compiler runs.


Edit:

So, my next step is to see if I can reinstate it after the linker runs but before the AOT compiler runs.

I can add the UnanalyzableAssembly back ManagedAssemblyToLink to make sure it's there before the AOT compiler runs. Even though it's now in the ManagedAssemblyToLink list, it does not appear in the list of assemblies to AOT.

<ItemGroup>
    <UnanalyzableAssembly Include="Microsoft.Graph" />
</ItemGroup>

<Target Name="ConfigureLinkingWorkaround" BeforeTargets="PrepareForILLink">
    <ItemGroup>
        <UnanalyzableManagedAssemblyToLink Include="@(ManagedAssemblyToLink)" Condition="'%(ManagedAssemblyToLink.NuGetPackageId)' == '@(UnanalyzableAssembly)'" />
        <ManagedAssemblyToLink Remove="@(UnanalyzableManagedAssemblyToLink)" />
    </ItemGroup>
</Target>

<Target Name="ConfigureAOTCompilationWorkaround" BeforeTargets="ComputeFilesToPublish">
    <ItemGroup>
        <ManagedAssemblyToLink Include="@(UnanalyzableManagedAssemblyToLink)" />
    </ItemGroup>
</Target>

msbuild_(1777d9).zip

I'm struggling to follow the path from

https://github.com/xamarin/xamarin-macios/blob/722bc0c555becb5baf53af3cd52472d53c00f9c3/tools/dotnet-linker/Steps/ComputeAOTArguments.cs#L24

to the context

https://github.com/xamarin/xamarin-macios/blob/2606b2341e1014bdf0549b264fe07d9b572fb6f7/tools/common/Target.cs#L44

to the declaration of the step

https://github.com/xamarin/xamarin-macios/blob/d2b6a5afb6fca81d5a624ca035e4b001e888e032/dotnet/targets/Xamarin.Shared.Sdk.targets#L636

to the use of the steps.

https://github.com/xamarin/xamarin-macios/blob/722bc0c555becb5baf53af3cd52472d53c00f9c3/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets#L389

(I'm on macOS so I'm not sure if the last one being 'Windows' means I've taken a wrong turn somewhere.

@Soap-141
Copy link

Soap-141 commented Jun 2, 2023

I'm having the same issue and mtouchInterpreter does nothing

@rolfbjarne
Copy link
Member

The AOT compiler asserts:

  • Assertion at /Users/runner/work/1/s/src/mono/mono/mini/aot-compiler.c:11219, condition `table_size < 65000' not met

which is from around here:

https://github.com/dotnet/runtime/blob/release/7.0/src/mono/mono/mini/aot-compiler.c#L11219

@rolfbjarne
Copy link
Member

I'm not sure if the resulting app works as expected, but asking the linker to trim Microsoft.Graph.dll makes the build succeed:

<ItemGroup>
    <TrimmableAssembly Include="Microsoft.Graph" />
</ItemGroup>

@Soap-141
Copy link

Soap-141 commented Jun 2, 2023

For me CommunityToolkit.WinUI.UI.dll

  • Assertion at /Users/runner/work/1/s/src/mono/mono/mini/mini-llvm.c:6004, condition `lhs' not met

https://github.com/dotnet/runtime/blob/417a01523fb75fa2688b6407db2e71ded7063f72/src/mono/mono/mini/mini-llvm.c#L6004

Let me try your workaround @rolfbjarne

@rolfbjarne
Copy link
Member

Disabling LLVM makes the build noticeable faster:

<PropertyGroup>
    <MtouchUseLlvm>false</MtouchUseLlvm>
</PropertyGroup>

@Soap-141 disabling llvm might also work around your crash

@Soap-141
Copy link

Soap-141 commented Jun 2, 2023

@rolfbjarne You think it's a good idea to disable llvm?

@rolfbjarne
Copy link
Member

@Soap-141 there might be perf hit, but if you don't notice / don't care, then it won't be a problem

@Soap-141
Copy link

Soap-141 commented Jun 2, 2023

@rolfbjarne I'll test it out to and compare it to UseInterpreter=true

@rolfbjarne
Copy link
Member

Almost all of this 1 hour is spent in the Microsoft.NET.ILLink.targets/ILLink task.

That's not what I see, although it takes a while for me too (~1m30s) - on a 6 years old iMac Pro.

Not passing Microsoft.Graph.dll to the illinker is not a good idea, you're likely to run into a lot of weird issues.

If it works, it's probably better to ask illink to trim Microsoft.Graph.dll (as I mentioned above).

This means there are really two separate issues here:

  1. The AOT compiler crashing.
  2. ILLink being quite slow.

@rolfbjarne
Copy link
Member

I've filed:

Feel free to CC yourself on these issues to be updated.

I'll also close this issue, since I don't think there's any other issue here relative to this repo.

@Soap-141
Copy link

Soap-141 commented Jun 2, 2023

I'm not sure if the resulting app works as expected, but asking the linker to trim Microsoft.Graph.dll makes the build succeed:

<ItemGroup>
    <TrimmableAssembly Include="Microsoft.Graph" />
</ItemGroup>

This worked thanks!

@NickDarvey
Copy link
Author

@rolfbjarne, thanks for investigating.

To summarize:

  1. The AOT compiler crashing.
    Fixed in main, so eventually part of dotnet 8.
    [mono] Avoid an assert if the class name table is too large. runtime#85952
    Workaround with <TrimmableAssembly Include="Microsoft.Graph" />
  2. ILLink being quite slow.
    Already fixed, update to dotnet >7.0.302
    ILLink takes a mysteriously long time to process Microsoft.Graph runtime#87050 (comment)

@ghost ghost locked as resolved and limited conversation to collaborators Jul 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants