-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
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:
- Unpack bootstrap tar in ./bootstrap directory
- Attempt to build newtonsoft-json via:
./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
from2048
to16384
and rebuilding mono
Configuration
- 7.0.100-rc1 crosscompiled to
linux-musl-s390x
fromlinux-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:
runtime/src/coreclr/pal/src/init/pal.cpp
Lines 246 to 269 in 2201016
#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