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

[Mono] Fix Mono Windows x86 build and runtime crash. #74639

Merged

Conversation

lateralusX
Copy link
Member

@lateralusX lateralusX commented Aug 26, 2022

When trying to validate a fix on Mono Windows x86, runtime crashed with stack overflow. After some investigation it turns out that Mono Windows x86 have SIMD disabled, but S.P.C was still build with System.Runtime.Intrinsics support and implementation of methods like get_IsSupported is implemented as follow:

.method public hidebysig specialname static
        bool  get_IsSupported() cil managed
{
  // Code size       6 (0x6)
  .maxstack  8
  IL_0000:  call       bool System.Runtime.Intrinsics.X86.Popcnt::get_IsSupported()
  IL_0005:  ret
} // end of method Popcnt::get_IsSupported

causing a stack overflow when called at runtime.

Fix make sure we won't add support for System.Runtime.Intrinsics in S.P.C for Mono Windows x86 builds.

There was also a warning in debugger-agent.c when building debug that caused build to fail, including fix for that as well.

NOTE, Mono Windows x86 is not an official supported configuration, but can still be used for testing and validation of x86 codegen and runtime behaviors (Mono x86 is still supported on other platforms), so there is still a value fixing it when needed.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost assigned lateralusX Aug 26, 2022
@ghost
Copy link

ghost commented Aug 26, 2022

Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics
See info in area-owners.md if you want to be subscribed.

Issue Details

When trying to validate a fix on Mono Windows x86, runtime crashed with stack overflow. After some investigation it turns out that Mono Windows x86 have SIMD disabled, but S.P.C was still build with System.Runtime.Intrinsics support and implementation of methods like get_IsSupported is implemented as follow:

.method public hidebysig specialname static
        bool  get_IsSupported() cil managed
{
  // Code size       6 (0x6)
  .maxstack  8
  IL_0000:  call       bool System.Runtime.Intrinsics.X86.Popcnt::get_IsSupported()
  IL_0005:  ret
} // end of method Popcnt::get_IsSupported

causing a stack overflow when called at runtime.

There was already a fallback implemented in Mono to handle case where runtime is build without SIMD support but code calls get_IsHardwareAccelerated, fix extends that check to include get_IsSuppored. Fix also make sure we won't add support for System.Runtime.Intrinsics in S.P.C for Mono Windows x86 builds.

There was also a warning in debugger-agent.c when building debug that caused build to fail, including fix for that as well.

NOTE, Mono Windows x86 is not an official supported configuration, but can still be used for testing and validation of x86 codegen and runtime behaviors (Mono x86 is still supported on other platforms), so there is still a value fixing it when needed.

Author: lateralusX
Assignees: lateralusX
Labels:

area-System.Runtime.Intrinsics, runtime-mono

Milestone: -

@lateralusX lateralusX added this to the 8.0.0 milestone Aug 26, 2022
Trying to validate a fix on x86 Windows Mono crashed runtime with
stack overflow. After some investigation it turns out that Mono
Windows x86 have SIMD disabled, but S.P.C was still build with
System.Runtime.Intrinsics support and implementation of methods
like get_IsSupported is implemented as follow:

.method public hidebysig specialname static
        bool  get_IsSupported() cil managed
{
  // Code size       6 (0x6)
  .maxstack  8
  IL_0000:  call       bool System.Runtime.Intrinsics.X86.Popcnt::get_IsSupported()
  IL_0005:  ret
} // end of method Popcnt::get_IsSupported

causing a stack overflow when called at runtime.

There was already a fallback implemented in Mono runtime to handle
case where runtime is build without SIMD support but code calls
get_IsHardwareAccelerated, fix extends that check to include
get_IsSuppored as well. Fix also make sure we won't add support for
System.Runtime.Intrinsics in S.P.C for Mono Windows x86 builds.

There was also a warning in debugger-agent.c when building debug
that caused build to fail, including fix for that as well.
@lateralusX lateralusX force-pushed the lateralusX/fix-windows-x86-simd-intrinsics branch 2 times, most recently from de32ebd to ef43574 Compare September 5, 2022 15:01
@lateralusX
Copy link
Member Author

Looks like we have configurations that assumes fallback through runtime code, so can't add get_IsSupported check in this PR, so PR will only make sure Mono Windows x86 build includes the not supported source files into its build of affected System.Numerics classes.

Several CI landes like llvmfullaot Linux x64 depends on fallback.
@lateralusX lateralusX force-pushed the lateralusX/fix-windows-x86-simd-intrinsics branch from ef43574 to df4fd65 Compare September 6, 2022 08:40
@lateralusX
Copy link
Member Author

Failure in Mono Linux argm64 Debug lane appears on other PR's and not related to changes done in this PR.

@lateralusX lateralusX merged commit 2a74721 into dotnet:main Sep 6, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants