Skip to content
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

Fix stack unwinding for NativeAOT on Unix #74673

Merged
merged 1 commit into from
Aug 27, 2022

Conversation

AntonLapounov
Copy link
Member

@AntonLapounov AntonLapounov commented Aug 26, 2022

Fix intermittent failures for running ./build.sh on Unix:

  crossgen2 -> /runtime/artifacts/bin/coreclr/Linux.x64.Debug/crossgen2/linux-x64/publish/
  crossgen2: /runtime/src/coreclr/nativeaot/Runtime/unix/UnixNativeCodeManager.cpp:296: virtual bool UnixNativeCodeManager::UnwindStackFrame(MethodInfo *, REGDISPLAY *, PInvokeTransitionFrame **): Assertion `pNativeMethodInfo->pMainLSDA == pNativeMethodInfo->pLSDA' failed.
  Aborted
/runtime/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj(70,5): error MSB3073: The command "/runtime/artifacts/bin/coreclr/Linux.x64.Debug/crossgen2/linux-x64/publish/crossgen2 /runtime/artifacts/bin/coreclr/Linux.x64.Debug/IL/System.Private.CoreLib.dll --out /runtime/artifacts/obj/Microsoft.NETCore.App.Crossgen2/Debug/net7.0/linux-x64/S.P.C.tmp" exited with code 134.

Below is an example of the call stack that fails the assertion when being unwound:

#38 S_P_CoreLib_System_Exception__ToString ()
    at /runtime/src/libraries/System.Private.CoreLib/src/System/Exception.cs:124
#39 ILCompiler_ReadyToRun_Internal_JitInterface_CorInfoImpl__AllocException_0 ()
    at /runtime/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs:160
#40 ILCompiler_ReadyToRun_Internal_JitInterface_CorInfoImpl___canGetCookieForPInvokeCalliSig ()
    at /runtime/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs:2063
#41 RhpCallCatchFunclet ()
    at /runtime/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S:335
#42 S_P_CoreLib_System_Runtime_EH__DispatchEx ()
    at /runtime/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs:700
#43 S_P_CoreLib_System_Runtime_EH__RhThrowEx ()
    at /runtime/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs:570
#44 RhpThrowEx () at /runtime/src/coreclr/nativeaot/Runtime/amd64/ExceptionHandling.S:152
#45 ILCompiler_ReadyToRun_Internal_JitInterface_CorInfoImpl__canGetCookieForPInvokeCalliSig ()
    at /runtime/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs:2811
#46 ILCompiler_ReadyToRun_Internal_JitInterface_CorInfoImpl___canGetCookieForPInvokeCalliSig ()
    at /runtime/src/coreclr/tools/Common/JitInterface/CorInfoBase.cs:2059
#47 ?? ()
   from /runtime/artifacts/bin/coreclr/Linux.x64.Debug/crossgen2/linux-x64/publish/libjitinterface_x64.so

Note that frame 40 above corresponds to the catch funclet of this reverse P/Invoke method:

[UnmanagedCallersOnly]
static byte _canGetCookieForPInvokeCalliSig(IntPtr thisHandle, IntPtr* ppException, CORINFO_SIG_INFO* szMetaSig)
{
var _this = GetThis(thisHandle);
try
{
return _this.canGetCookieForPInvokeCalliSig(szMetaSig) ? (byte)1 : (byte)0;
}
catch (Exception ex)
{
*ppException = _this.AllocException(ex);
return default;
}
}

The fix is to use the funclet's LSDA instead of the main LSDA — similar to what we do on Windows.

Related changes: dotnet/corert#2157, dotnet/corert#4487.
Fixes #70543.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this! We should backport to the fix to 7.0.

@AntonLapounov
Copy link
Member Author

The failure in WasmBuildTests is #74328.

@AntonLapounov AntonLapounov merged commit 9a1debd into dotnet:main Aug 27, 2022
@AntonLapounov AntonLapounov deleted the FixNativeAotUnwinding branch August 27, 2022 00:06
@AntonLapounov
Copy link
Member Author

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/2937328274

@AntonLapounov AntonLapounov changed the title Fix stack unwinding for NativeAOT on Unix x64 Fix stack unwinding for NativeAOT on Unix Aug 27, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr os-linux Linux OS (any supported distro)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crossgen2 crashes on linux-x64
2 participants