Crash when Netcore ConsoleApp use LibraryImport to call a function in a so generated by Native AOT in linux-arm64
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- csharp, linux
- Domain
- compilers, operating-systems
Research direction
Reproduce the linux-arm64 case using the NativeAOT publish commands for grgbanking_io and ConsoleTest, then run the published app under gdb. Start at the native_add and ReversePInvokeAttachOrTrapThread frames and compare the result with linux-x64. Done means the same LibraryImport call completes on linux-arm64 and prints Result: 8 without an abort.
Written by the indexing model from the issue text.
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
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
:watch: Not Triaged 11.0 fundamentals/subsvc
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
dotnet/AspNetCore.Docs#37699 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15108 · 1 comment ·
-
area/docs-content Bug pulumi/docs
Difficulty 1/5 1-3 hours Newbie friendliness 94/100
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PowerShell/PSResourceGet#2056 ·