diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index ace8fd5fe426f3..7543194c58932c 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -350,8 +350,38 @@ elseif(CLR_CMAKE_HOST_APPLE) endif() endif() elseif(CLR_CMAKE_HOST_HAIKU) + # Haiku uses the GNU toolchain, which supports WHOLE_ARCHIVE, but only CMake 3.31.0+ recognizes this. + if(CMAKE_VERSION VERSION_LESS 3.31) + if(NOT DEFINED _CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED) + execute_process(COMMAND "${CMAKE_LINKER}" --help + OUTPUT_VARIABLE __linker_help + ERROR_VARIABLE __linker_help) + if(__linker_help MATCHES "--push-state" AND __linker_help MATCHES "--pop-state") + set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED TRUE CACHE INTERNAL "linker supports push/pop state") + else() + set(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED FALSE CACHE INTERNAL "linker supports push/pop state") + endif() + unset(__linker_help) + endif() + if(_CMAKE_LINKER_PUSHPOP_STATE_SUPPORTED) + set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--push-state,--whole-archive" + "" + "LINKER:--pop-state") + else() + set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE "LINKER:--whole-archive" + "" + "LINKER:--no-whole-archive") + endif() + set(CMAKE_LINK_LIBRARY_USING_WHOLE_ARCHIVE_SUPPORTED TRUE) + set(CMAKE_LINK_LIBRARY_WHOLE_ARCHIVE_ATTRIBUTES LIBRARY_TYPE=STATIC DEDUPLICATION=YES OVERRIDE=DEFAULT) + endif() + # Haiku uses the GNU toolchain, which supports RESCAN, but only CMake 4.4.0+ recognizes this. + if(CMAKE_VERSION VERSION_LESS 4.4) + set(CMAKE_LINK_GROUP_USING_RESCAN "LINKER:--start-group" "LINKER:--end-group") + set(CMAKE_LINK_GROUP_USING_RESCAN_SUPPORTED TRUE) + endif() add_compile_options($<$:-Wa,--noexecstack>) - add_linker_flag("-Wl,--no-undefined") + add_linker_flag("-Wl,--build-id=sha1") endif() #------------------------------------ diff --git a/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs b/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs index 8134e38145590a..8c4ce4d07d3360 100644 --- a/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs +++ b/src/libraries/System.Private.CoreLib/src/System/OperatingSystem.cs @@ -209,6 +209,17 @@ internal static bool IsOpenBSD() => false; #endif + /// + /// Indicates whether the current application is running on Haiku. + /// + [NonVersionable] + internal static bool IsHaiku() => +#if TARGET_HAIKU + true; +#else + false; +#endif + /// /// Indicates whether the current application is running on Android. /// diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs index 46ddab7933869f..c6771d8909ca67 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs @@ -81,7 +81,8 @@ internal abstract class NamedMutexProcessDataBase(SharedMemoryProcessDataHeader< // On FreeBSD, pthread process-shared robust mutexes cannot be placed in shared memory mapped // independently by the processes involved. See https://github.com/dotnet/runtime/issues/10519. // On OpenBSD, cross process mutexes are not supported in the pthread implementation. See https://github.com/dotnet/runtime/pull/125089. - private static bool UsePThreadMutexes => !OperatingSystem.IsApplePlatform() && !OperatingSystem.IsFreeBSD() && !OperatingSystem.IsOpenBSD(); + // On Haiku, robust mutexes are WIP. See https://github.com/dotnet/runtime/pull/126701#issuecomment-4334338213. + private static bool UsePThreadMutexes => !OperatingSystem.IsApplePlatform() && !OperatingSystem.IsFreeBSD() && !OperatingSystem.IsOpenBSD() && !OperatingSystem.IsHaiku(); private readonly SharedMemoryProcessDataHeader _processDataHeader = header; protected nuint _lockCount; diff --git a/src/native/libs/System.Native/CMakeLists.txt b/src/native/libs/System.Native/CMakeLists.txt index 52a4dccbdd9b96..5930703021940b 100644 --- a/src/native/libs/System.Native/CMakeLists.txt +++ b/src/native/libs/System.Native/CMakeLists.txt @@ -57,7 +57,11 @@ else() # WASI ) endif() -if (CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI OR CLR_CMAKE_TARGET_OPENBSD) +if (CLR_CMAKE_TARGET_APPLE OR CLR_CMAKE_TARGET_ANDROID OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI OR CLR_CMAKE_TARGET_OPENBSD OR CLR_CMAKE_TARGET_HAIKU) + # These platforms do not support robust mutexes. + # Keep an OS list instead of CMake configure checks since we also need to synchronize this with + # the compile-time guards on the managed code side at + # src/libraries/System.Private.CoreLib/src/System/Threading/NamedMutex.Unix.cs. list (APPEND NATIVE_SOURCES pal_crossprocessmutex_unsupported.c) else()