dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.03k stars 4.68k forks source link

[NativeAOT] Build hangs on .NET 3.1 project #67689

Closed smhmhmd closed 2 years ago

smhmhmd commented 2 years ago

Description

Building a 'hello world' program with .NET 3.1 for NativeAOT hangs, the ilc process also consumes a lot of memory. .NET 3.1 will be EOL'ed in December, but, we would like to understand the root cause and also how we can instrument ilc to show more about what could be causing this. Thanks to @beau-gosse-dev for reproducing it.

Reproduction Steps

$ dotnet new console --framework netcoreapp3.1
$ cat hang-sample.csproj 
     <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
       <OutputType>Exe</OutputType>
     <TargetFramework>netcoreapp3.1</TargetFramework>
      <RootNamespace>hang_sample</RootNamespace>
    </PropertyGroup>

     <ItemGroup>
       <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
    </ItemGroup>
   </Project>

$ dotnet clean && dotnet publish -r linux-x64 --self-contained

Expected behavior

'Hello World!' is printed

Actual behavior

Compilation hangs

// In another window run the 'top' command

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                   
   4667 ubuntu    20   0   21.6g   3.2g  65096 R 392.7  20.4   4:19.68 ilc 

Regression?

No response

Known Workarounds

No response

Configuration

   ubuntu@ip-172-31-24-113:~/hang-sample$ dotnet --list-sdks
            3.1.417 [/home/ubuntu/.dotnet/sdk]
            6.0.201 [/home/ubuntu/.dotnet/sdk]
    ubuntu@ip-172-31-24-113:~/hang-sample$ cat /etc/os-release
          NAME="Ubuntu"
          VERSION="20.04.3 LTS (Focal Fossa)"
          ID=ubuntu
          ID_LIKE=debian
          PRETTY_NAME="Ubuntu 20.04.3 LTS"
          VERSION_ID="20.04"
          HOME_URL="https://www.ubuntu.com/"
          SUPPORT_URL="https://help.ubuntu.com/"
          BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
          PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
          VERSION_CODENAME=focal
          UBUNTU_CODENAME=focal
   $ uname -m
        x86_64

Other information

No response

kant2002 commented 2 years ago

NativeAOT supported application for .NET 6.0 and up. .NET core 3.1 is not supported. See this https://github.com/dotnet/runtimelab/issues/1241#issuecomment-1026571480

jkotas commented 2 years ago

The latest nightly packages have an explicit block for compiling applications that are targeting earlier net versions. You should see an error message like this: C:\Users\jkotas\.nuget\packages\microsoft.dotnet.ilcompiler\7.0.0-preview.4.22201.3\build\Microsoft.NETCore.Native.Publ ish.targets(52,5): error : For native compilation, the project needs to target .NET 6 or higher. [C:\repro\repro.csproj ]

Building a 'hello world' program with .NET 3.1 for NativeAOT hang

It is not a hang. The problem is that the compilation is trying to compile all code in .NET runtime, without trimming anything - that is a lot.

we would like to understand the root cause

There are number of known issues with trimming when the application targets earlier net versions. We do not plan to fix them.

how we can instrument ilc to show more about what could be causing this.

You can pass --verbose flag to the compiler. It will show you what the compiler is compiling.