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-8.0/9.0] Cannot compile project with AOT enabled (Assertion at mini-llvm.c, condition `cinfo->ret.nslots == 1' not met) #103628

Closed
vyacheslav-volkov opened this issue Jun 18, 2024 · 7 comments · Fixed by #106013
Assignees
Labels
area-Codegen-AOT-mono in-pr There is an active PR which will close this issue when it is merged os-ios Apple iOS
Milestone

Comments

@vyacheslav-volkov
Copy link

Description

I'm developing a large project and at the very beginning the code compiled without problems, but after a while I checked again and got this error, I don’t have time to look for which specific type breaks the assembly, is it possible to display a more specific error message and how can I debug it?

I tried the latest net9.0-preview 5 but the result is the same.

Reproduction Steps

I can't provide the source code as this is a commercial product.

Expected behavior

No compilation errors

Actual behavior

Mono Ahead of Time compiler - compiling assembly ..../obj/Release/net9.0-ios/ios-arm64/linked/MugenMvvm.dll
AOTID 0D0A964D-FAF6-A1E4-FADC-1F08E0767345

  • Assertion at /Users/runner/work/1/s/src/mono/mono/mini/mini-llvm.c:1605, condition `cinfo->ret.nslots == 1' not met

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jun 18, 2024
@MichalStrehovsky MichalStrehovsky changed the title [ios-8.0/9.0 NativeAot] Cannot compile project with NativeAot enabled (Assertion at mini-llvm.c, condition `cinfo->ret.nslots == 1' not met) [ios-8.0/9.0] Cannot compile project with AOT enabled (Assertion at mini-llvm.c, condition `cinfo->ret.nslots == 1' not met) Jun 18, 2024
@vitek-karas vitek-karas added the os-ios Apple iOS label Jun 18, 2024
@agocke agocke removed this from AppModel Jun 20, 2024
@ivanpovazan
Copy link
Member

Hi @vyacheslav-volkov, you mentioned

at the very beginning the code compiled without problems

Are you referring to .NET8 release or something else?
I am trying to understand if the problem is a regression introduced in .NET8 or .NET9 previews?


Since you cannot provide a smaller repro, you could try increasing the verbosity of the AOT compiler when it compiles the problematic assembly (in your case: MugenMvvm.dll).

To do so:

  1. Build your app with:
dotnet build -c Release -r ios-arm64 -tl:false -v:diag > build.log
  1. Open build.log and search for mono-aot-cross
  2. You should find messages like:
Tool /usr/local/share/dotnet/packs/Microsoft.NETCore.App.Runtime.AOT.osx-arm64.Cross.ios-arm64/9.0.0-preview.6.24327.7/Sdk/../tools/mono-aot-cross 
execution started with arguments: ... 
  • These are the invocations of the AOT compiler with command line arguments for different assemblies
  1. Find the one invocation which compiles MugenMvvm.dll
  2. Get the AOT command
  • Pay attention to the message format and remove command-irrelevant parts:
Tool <path_to_aot_compier> execution started with arguments: <args> `obj/Release/net9.0-ios/ios-arm64/linked/MugenMvvm.dll`
  • Your command should be just:
<path_to_aot_compier> <args> `obj/Release/net9.0-ios/ios-arm64/linked/MugenMvvm.dll` 
  • Include the -v arguments to increase AOT compiler verbosity:
<path_to_aot_compier> <args> -v `obj/Release/net9.0-ios/ios-arm64/linked/MugenMvvm.dll` 
  1. Open the terminal
  2. Run the command
    • This should run the AOT compiler and only compile the problematic assembly with increased verbosity and your output should include which LLVM methods got compiled
    converting llvm method void <Module>:.cctor ()
    void <Module>:.cctor () emitted as Sample__Module__cctor
    converting llvm method void Program:<Main>$ (string[])
    ...
    
    The idea is that you would see the one just before the compiler asserts so hopefully you could backtrack the problem and provide a smaller repro.

Hope this helps and please let me know if you have troubles with the listed steps to increase verbosity.

@ivanpovazan ivanpovazan added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 22, 2024
@vyacheslav-volkov
Copy link
Author

vyacheslav-volkov commented Jul 22, 2024

Hi @ivanpovazan, I think I've found the issue, I had ref type with no fields and marked with [StructLayout(LayoutKind.Auto)] once I removed the attribute the error went away.

    [StructLayout(LayoutKind.Auto)]
    public ref struct Builder<T>
    {
    }

I am trying to understand if the problem is a regression introduced in .NET8 or .NET9 previews?

both versions are affected by the issue

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 22, 2024
@ivanpovazan
Copy link
Member

Is this then still blocking you?

In any case we would appreciate if you could provide a smaller repro, so we could look into generating better error messages.

@vyacheslav-volkov
Copy link
Author

@ivanpovazan thanks for the help, no blockers atm, I just removed [StructLayout(LayoutKind.Auto)] as it is redundant for this struct, I'll try to create a small repo to reproduce the issue.

@ivanpovazan ivanpovazan added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 22, 2024
@vyacheslav-volkov
Copy link
Author

@ivanpovazan I've reproduced this with a simple example:

using System.Runtime.InteropServices;

namespace iOSApp1;

public static class Builder
{
    public static Builder<T> Get<T>() => new();
}

[StructLayout(LayoutKind.Auto)]
public ref struct Builder<T>
{
    public object Build() => "";
}

[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
    public override UIWindow? Window { get; set; }

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        Builder.Get<string>().Build();
        return true;
    }
}

@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jul 22, 2024
@vitek-karas vitek-karas added this to the 9.0.0 milestone Jul 24, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jul 24, 2024
@vitek-karas
Copy link
Member

@jkurdek could you please try to repo and look what's going on?

@jkurdek
Copy link
Member

jkurdek commented Jul 26, 2024

Minimal repro:

[StructLayout(LayoutKind.Auto)] // Also occurs with [StructLayout(LayoutKind.Sequential)] 
public struct Builder
{
    public string Build() => "Hello";
}

namespace HelloWorld
{
    internal class Program
    {
        public static Builder Get() => new Builder();
        private static void Main(string[] args)
        {

        }
    }
}

Initial investigation:

The issue seems to be caused by placing StructLayoutAttribute on a struct with no fields. The size of such struct is then computed to be 0. Then during handling of Get() method , 0 registers are allocated for the return value. Which then leads to failing assertion.

Will follow up with more detailed analyis

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-AOT-mono in-pr There is an active PR which will close this issue when it is merged os-ios Apple iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants