dotnet / runtime

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

coreclr_initialize failed on RISC-V (error 0x8007000E) #85650

Open mateusrodrigues opened 1 year ago

mateusrodrigues commented 1 year ago

Description

I am investigating the current state of .NET on RISC-V and started by trying to build CoreCLR on a board. So I created a simple Hello World .NET app and tried to run it with corerun. I am currently getting the following error:

GC heap initialization failed with error 0x8007000E                                        
BEGIN: coreclr_initialize failed - Error: 0x8007000e                                       
Exe path: /home/ubuntu/git/runtime/artifacts/bin/coreclr/linux.riscv64.Debug/corerun
Properties:                                                                                
    TRUSTED_PLATFORM_ASSEMBLIES = /home/ubuntu/git/runtime/artifacts/bin/coreclr/linux.risc
v64.Debug//System.Private.CoreLib.dll:                                                     
    APP_PATHS = /home/ubuntu/hello-world/                                                  
    NATIVE_DLL_SEARCH_DIRECTORIES = /home/ubuntu/hello-world/:                             
    HOST_RUNTIME_CONTRACT = 0x3fcdc1f718                                                   
Managed assembly: /home/ubuntu/hello-world/HelloWorld.dll                                 
Arguments (0):                                                                             
END: coreclr_initialize failed - Error: 0x8007000e

As the error code indicates an OOM error, I ran strace on this and got the following output:

36823 sysinfo({uptime=1576, loads=[66528, 43648, 29120], totalram=7523438592, freeram=6651424768, sharedram=1163264, bufferram=39895040, totalswap=0, freeswap=0, procs=131, totalhigh=0, freehigh=0, mem_unit=1}) = 0
36823 mmap(NULL, 274877911040, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)

Apparently, it's trying to allocate 274 GB of memory if I understood this correctly?

Reproduction Steps

  1. ./src/coreclr/build-runtime.sh
  2. On an amd64 machine, built the CoreCLR managed parts from inside the System.Private.CoreLib directory with ../../../.dotnet/dotnet build -r linux-riscv64 -c Debug --no-self-contained /p:PlatformTarget=AnyCpu System.Private.CoreLib.csproj
  3. Created a Hello World app on another machine (with .NET 8 latest preview): 2.1. dotnet new console -o HelloWorld 2.2. dotnet build 2.3. Copied the HelloWorld.dll file over to the board
  4. Went into the artifacts folder and ran ./corerun HelloWorld.dll
  5. Error happened

Expected behavior

Should output Hello, World!

Actual behavior

Outputs the error included in the description.

Regression?

No response

Known Workarounds

No response

Configuration

Other information

No response

hez2010 commented 1 year ago

See https://github.com/dotnet/runtime/issues/84834. GC-related is placed in not planned right now. You may want to set DOTNET_GCgen0size=99999999 and use conservative GC mode for testing.

janvorli commented 1 year ago

Apparently, it's trying to allocate 274 GB of memory if I understood this correctly?

It is trying to reserve virtual memory space of that space, not allocate that much of physical memory. This is expected, but it causes problem on RISC-V as its virtual address space is limited to 256 GB IIRC (other 64 bit platforms have limit of 32TB). Setting DOTNET_GCHeapHardLimit=3C00000000 (the value is a bit below 256GB) might also fix the problem, but maybe using the setting mentioned in the previous comment would be better since this came from the developers of the RISC-V support.

gbalykov commented 1 year ago

@mateusrodrigues There's already fix for this for VisionFive 1/2, please try https://github.com/dotnet/runtime/pull/84797