-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
NativeAOT staticlib crashes with SIGSEGV inside RhpNewArray
when linked with -dead_strip
#96663
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionWhen I linked nativeaot static lib with Reproduction Stepstest.cs using System.Runtime.InteropServices;
public class Class1
{
[UnmanagedCallersOnly(EntryPoint = "add_dotnet")]
public static int Add(int a, int b)
{
return a + b;
}
} test.csproj <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>test</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<PublishTrimmed>true</PublishTrimmed>
<NativeLib>Static</NativeLib>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
</Project> test.c #include <stdio.h>
int add_dotnet(int, int);
int main(void) {
printf("%d\n", add_dotnet(1, 2));
} build script (bash) dotnet publish -r osx-arm64 -c Release
cc \
-o test \
test.c \
./bin/release/net8.0/osx-arm64/publish/test.a \
"$HOME"/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Native.a \
"$HOME"/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libRuntime.ServerGC.a \
"$HOME"/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libstdc++compat.a \
"$HOME"/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/framework/libSystem.Globalization.Native.a \
"$HOME"/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libeventpipe-disabled.a \
"$HOME"/.nuget/packages/runtime.osx-arm64.microsoft.dotnet.ilcompiler/8.0.0/sdk/libbootstrapperdll.o \
-framework Foundation \
-Wl,-dead_strip Expected behaviorNo crash and prints Actual behaviorCrashes with Segmentation Fault with Here is lldb registers and backtrace
Regression?I tested no other version of .NET so I don't know if this is regression or not. This might be because medium using CoreRT linked from NativeLib sample uses rust and it doesn't mention about dead_strip however if this problem is os-dependent, this isn't. Known Workaroundsnot passing Configuration
With cross-arch-compiling to x64/x86_64 and running on rosetta will cause same problem so this problem is not arch specific. Other informationI encountered this problem trying to link C# to rust. In NativeLibrary sample, I have to pass
|
Another dead_strip issue here: #88032 |
I found that contents of (the following is lldb console breaking at the start of the
|
@MichalStrehovsky I assigned this to myself as I will be working on the iOS issue #88032 Feel free to change this if needed. |
I found another workaround(?) for this problem. I can make it working by setting |
Hi! Is there are workaround that I can use as an end user? (macOS, clang #97501) |
In my project, disabling dehydration and adding NO_STRIP flag to all sections of nativeaot object file wil workaround this problem. |
I've tried your workaround, and it works. |
Hi @ivanpovazan ! |
@JCash sorry I was a bit side-tracked recently. |
Q: Will this be backported to dotnet 8? And if so, in which version/timeframe would that happen? Regards, |
Correct me if I'm wrong but If the above is correct, I don't think it would pass the bar for servicing. The servicing bar is pretty high. |
Sure. However as we provide a service to others, we can't remove the flag for them. I needed to ask the question, as I'm new to this dotnet eco system. I'll sync with the team in our private chat as well, to see what the recommended course of action is for us. |
Description
When I linked nativeaot static lib with
-Wl,-dead_strip
, the C# function crashed with SIGSEGV / Segmentation fault insideRhpNewArray
Reproduction Steps
test.cs
test.csproj
test.c
build script (bash)
Expected behavior
No crash and prints
3
Actual behavior
Crashes with Segmentation Fault with
RhpNewArray
Here is lldb registers and backtrace
Regression?
I tested no other version of .NET so I don't know if this is regression or not.
This might be because medium using CoreRT linked from NativeLib sample uses rust and it doesn't mention about dead_strip however if this problem is os-dependent, this isn't.
Known Workarounds
not passing
-dead_strip
to the linkerConfiguration
With cross-arch-compiling to x64/x86_64 and running on rosetta will cause same problem so this problem is not arch specific.
No other oses are tested so I don't know if this is os-specific
Other information
I encountered this problem trying to link C# to rust.
Rust passes
-dead_strip
by default.For rust users, you can omit
-dead_strip
by settingrustflags = ["-C", "link-dead-code"]
but this will increase final binaryIn NativeLibrary sample, I have to pass
-Wl,-u,_NativeAOT_StaticInitialization
if it's built with .NET 7.My project is .NET 8 so I think this is not related, and when I passed that option to compiler, linker says
_NativeAOT_StaticInitialization
is undefined.The text was updated successfully, but these errors were encountered: