Skip to content

Commit

Permalink
Set stack size on MUSL with PT_GNU_STACK header (#92465)
Browse files Browse the repository at this point in the history
Fixes #72920.
  • Loading branch information
MichalStrehovsky authored Sep 25, 2023
1 parent 46209b0 commit 3b6142c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 34 deletions.
14 changes: 0 additions & 14 deletions src/coreclr/nativeaot/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,12 @@ static int InitializeRuntime()

#ifndef NATIVEAOT_DLL

#ifdef ENSURE_PRIMARY_STACK_SIZE
__attribute__((noinline, optnone))
static void EnsureStackSize(int stackSize)
{
volatile char* s = (char*)_alloca(stackSize);
*s = 0;
}
#endif // ENSURE_PRIMARY_STACK_SIZE

#if defined(_WIN32)
int __cdecl wmain(int argc, wchar_t* argv[])
#else
int main(int argc, char* argv[])
#endif
{
#ifdef ENSURE_PRIMARY_STACK_SIZE
// TODO: https://github.com/dotnet/runtimelab/issues/791
EnsureStackSize(1536 * 1024);
#endif

int initval = InitializeRuntime();
if (initval != 0)
return initval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>
<IlcDefaultStackSize Condition="'$(_linuxLibcFlavor)' == 'musl'">1572864</IlcDefaultStackSize>
</PropertyGroup>

<Target Name="SetupOSSpecificProps" DependsOnTargets="$(IlcDynamicBuildPropertyDependencies)">
Expand Down Expand Up @@ -156,6 +157,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<LinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
<LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
<LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" />
<!-- this workaround can be deleted once the minimum supported glibc version
(runtime's official build machine's glibc version) is at least 2.33
see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/nativeaot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ if(CLR_CMAKE_HOST_UNIX)
endif(CLR_CMAKE_TARGET_ARCH_AMD64 OR CLR_CMAKE_TARGET_ARCH_I386)
endif (CLR_CMAKE_HOST_UNIX)

if(CLR_CMAKE_TARGET_LINUX_MUSL)
# Fix up the main thread stack size for MUSL to more reasonable size.
# TODO: https://github.com/dotnet/runtimelab/issues/791
add_definitions(-DENSURE_PRIMARY_STACK_SIZE)
endif()

if(CLR_CMAKE_TARGET_ANDROID)
add_definitions(-DFEATURE_EMULATED_TLS)
endif()
Expand Down
6 changes: 0 additions & 6 deletions src/native/libs/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM
add_definitions(-DHAS_CONSOLE_SIGNALS)
endif ()

if (CLR_CMAKE_TARGET_LINUX_MUSL)
# Fix up the thread stack size for MUSL to more reasonable size.
# TODO: https://github.com/dotnet/runtimelab/issues/791
add_definitions(-DENSURE_PRIMARY_STACK_SIZE)
endif ()

if (CLR_CMAKE_TARGET_OSX)
add_definitions(-D_DARWIN_C_SOURCE)
endif ()
Expand Down
8 changes: 0 additions & 8 deletions src/native/libs/System.Native/pal_threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,6 @@ int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(voi
error = pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
assert(error == 0);

#ifdef ENSURE_PRIMARY_STACK_SIZE
// TODO: https://github.com/dotnet/runtimelab/issues/791
if (stackSize == 0)
{
stackSize = 1536 * 1024;
}
#endif

if (stackSize > 0)
{
if (stackSize < (uintptr_t)PTHREAD_STACK_MIN)
Expand Down

0 comments on commit 3b6142c

Please sign in to comment.