Repository navigation
Open
Labels
Milestone
Description
Description
In linux-arm64, I generated a simple test so by Native AOT. But when I call the so function in a netcore ConsoleApp, it crash.
But i test it in linux-x64, it works fine.
Reproduction Steps
- Create a C# Library project "grgbanking_io", with the simple code:
using System.Runtime.InteropServices;
namespace grgbanking_io
{
public class StdApi
{
[UnmanagedCallersOnly(EntryPoint = "native_add")]
public static int NativeAdd(int a, int b) => a + b;
}
}- Publish the NativeAOT so with the command:
dotnet publish -c Release -r linux-arm64 --self-contained /p:PublishAot=true- Create a netcore ConsoleApp project "ConsoleTest", with the simple code:
using System.Runtime.InteropServices;
namespace ConsoleTest
{
public partial class Program
{
private const string _soName = "grgbanking_io";
[LibraryImport(_soName, EntryPoint = "native_add")]
private static partial int _nativeAdd(int a, int b);
static void Main(string[] args)
{
try
{
int result = _nativeAdd(3, 5);
Console.WriteLine($"Result: {result}");
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}", ex);
}
}
}
}- Publish the ConsoleApp with the same command:
dotnet publish -c Release -r linux-arm64 --self-contained /p:PublishAot=true- Copy the so and so.dbg files into the ConsoleApp's publish dir
- Run the ConsoleApp in gdb, will find the crash info.
Expected behavior
work normal
Actual behavior
The gdb info:
Thread 1 "ConsoleTest" received signal SIGABRT, Aborted.
0x0000007ff7d68eac in raise () from /lib/aarch64-linux-gnu/libc.so.6
(gdb) bt
#0 0x0000007ff7d68eac in raise () from /lib/aarch64-linux-gnu/libc.so.6
#1 0x0000007ff7d55aa0 in abort () from /lib/aarch64-linux-gnu/libc.so.6
#2 0x0000007ff4c3da20 in RhFailFast() () from /root/grgbanking_io/ConsoleTest/bin/Release/net10.0/linux-arm64/publish/grgbanking_io.so
#3 0x0000007ff4c4f85c in Thread::ReversePInvokeAttachOrTrapThread(ReversePInvokeFrame*) () from /root/grgbanking_io/ConsoleTest/bin/Release/net10.0/linux-arm64/publish/grgbanking_io.so
#4 0x0000007ff4cf9a7c in native_add () from /root/grgbanking_io/ConsoleTest/bin/Release/net10.0/linux-arm64/publish/grgbanking_io.so
#5 0x00000055555bfa64 in ConsoleTest_ConsoleTest_Program___nativeAdd ()
#6 0x00000055555bfabc in ConsoleTest_ConsoleTest_Program__Main ()
#7 0x0000005555626c30 in __managed__Main ()
#8 0x0000007ff7d55e18 in __libc_start_main () from /lib/aarch64-linux-gnu/libc.so.6
#9 0x0000005555556d3c in _start () #Regression?
I test in net8 ,net9 and net10preview6,it all crashed.
But in net10preview6, it shows the error info:
Fatal error. .NET runtime failed to initialize.Known Workarounds
No response
Configuration
.NET Version: net8 ,net9 and net10preview6
OS: linux-arm64, Debian 11
Other information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
MihuBot commentedon Aug 6, 2025
Possible related and/or duplicate issue:
MichalStrehovsky commentedon Aug 6, 2025
Can you try setting the
DOTNET_GCHeapHardLimitPercentenvironment variable to 8 before you run the program?Run
export DOTNET_GCHeapHardLimitPercent=8before launching the executable.shshheyi commentedon Aug 7, 2025
@MichalStrehovsky , Thanks, I tried to set the environment variable DOTNET_GCHeapHardLimitPercent, and then run the consoleApp, it worked.
MichalStrehovsky commentedon Aug 7, 2025
Thank you! Moving this to the GC area path. This is an ongoing support cost.
dotnet-policy-service commentedon Aug 7, 2025
Tagging subscribers to this area: @dotnet/gc
See info in area-owners.md if you want to be subscribed.
mangod9 commentedon Aug 7, 2025
@MichalStrehovsky, assume this is the same issue of large reservation size?
MichalStrehovsky commentedon Aug 7, 2025
We have two GCs in the process (JIT-based CoreCLR and native AOT), the runtime is failing to initialize in the second, and everything gets fixed with the
export DOTNET_GCHeapHardLimitPercent=8workaround, so my guess is that.mangod9 commentedon Aug 8, 2025
Is there anything special about
DOTNET_GCHeapHardLimitPercent=8, so generally any smaller value would do?We are planning to change the reservation size to 2x Physical Memory for NativeAOT case, wonder if that would help alleviate this issue?
shshheyi commentedon Aug 8, 2025
@mangod9 When use only one NativeAOT so lib, I tested the DOTNET_GCHeapHardLimitPercent, if < 50%, it can work normal.But in my final App, may use 3 or more NativeAOT so libs. Can share the size in one process no matter how many NativeAOT so libs it used?
MichalStrehovsky commentedon Aug 8, 2025
Why only for native AOT?
Most reports (including this and #95257 linked above by the bot) involve JIT-based CoreCLR loading a native AOT library. We know that 256 GB + 256 GB reservation is too much for many systems. Do we have data that 256 GB + 2 * Physical Memory would work?
We have data that even the first 256 GB (without native AOT in the picture at all) is problematic:
I haven't tried following all the linked issues, looks like there is more to it.
Cc @agocke
The number is a copypaste from #95257 (comment), I haven't put thought into it.
mangod9 commentedon Aug 8, 2025
We cannot change the default for SVR or WKS since it might cause regressions for larger applications. As an initial step we can update it for NativeAOT.
We could also improve the error message and provide the configuration needed to get the scenario to work per the specific app requirements.
@Maoni0
MichalStrehovsky commentedon Aug 8, 2025
Having different defaults for things that affect GC perf makes it very hard to root cause perf issues between native AOT and CoreCLR. Random perf differences are even more expensive for us to root cause than a failure to initialize the runtime. I don't find a native AOT specific fix acceptable and I would prefer not to do anything then.
mangod9 commentedon Aug 8, 2025
@shshheyi, assuming the workaround to manually configure the hard limit works for you. We have another issue tracking the case of multiple runtimes within the same process case.