Skip to content

System.InsufficientExecutionStackException when using Mono on linux-musl #76523

@ayakael

Description

@ayakael

Description

Encountering System.InsufficientExecutionStackException errors on linux-musl-s390x which seems to be caused by mono not dealing with musl's low default stack size.

Reproduction Steps

Within Alpine Linux linux-musl-s390x environment:

./bootstrap/dotnet build Src/Newtonsoft.Json/Newtonsoft.Json.csproj /v:diag
  • Watch the world burn

Expected behavior

Build should be successful

Actual behavior

Fails with System.InsufficientExecutionStackException errors after csc.dll process

Regression?

The same issue occurs on dotnet 6.0.109 and 6.0.401 for what its worth.

Known Workarounds

Unknown, currently trying to find ways to force a higher stack size, but so far the following approches have failed

  • find "$_cli_root" -type f -exec "$srcdir"/muslstack -s 0x800000 '{}' \; 2>&1 | grep stackSize which used muslstack to set every file in bootstrap with an 8MB stacksize
  • Building mono with -Wl,-z,stack-size=8198144 ld flag
  • Setting PTHREAD_STACK_MIN in /usr/include/limits.h from 2048 to 16384 and rebuilding mono

Configuration

  • 7.0.100-rc1 crosscompiled to linux-musl-s390x from linux-musl-x64
  • Alpine Linux Edge
  • Can be reproducedis in Alpine Linux build pipelines

Other information

Fix likely involves implementing ENSURE_PRIMARY_STACK_SIZE from coreclr to mono:

#ifdef ENSURE_PRIMARY_STACK_SIZE
/*++
Function:
EnsureStackSize
Abstract:
This fixes a problem on MUSL where the initial stack size reported by the
pthread_attr_getstack is about 128kB, but this limit is not fixed and
the stack can grow dynamically. The problem is that it makes the
functions ReflectionInvocation::[Try]EnsureSufficientExecutionStack
to fail for real life scenarios like e.g. compilation of corefx.
Since there is no real fixed limit for the stack, the code below
ensures moving the stack limit to a value that makes reasonable
real life scenarios work.
--*/
__attribute__((noinline,NOOPT_ATTRIBUTE))
void
EnsureStackSize(SIZE_T stackSize)
{
volatile uint8_t *s = (uint8_t *)_alloca(stackSize);
*s = 0;
}
#endif // ENSURE_PRIMARY_STACK_SIZE

Relevant issues:
dotnet/roslyn#64423
#72920

Full log file: newtonsoft.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-s390xRelated to s390x architecture (unsupported)area-Build-monoos-linux-muslLinux distributions using musl library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions