From 3aff3f31ef37736c776772d93a9487ed334d371b Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Sun, 26 Apr 2026 13:25:19 +1000 Subject: [PATCH 1/4] Haiku: Initial NativeAOT and Crossgen2 support Add the required configuration to support NativeAOT and Crossgen2 for Haiku targets. This includes: - Enabling NativeAOT and Crossgen2 for Haiku in MSBuild scripts, - Adding "Haiku" to relevant enumerations and switch blocks, - Defining correct linker flags for Haiku targets, - Adding `0x0B05` as the PE native image type constant for Haiku - This is a reference to Haiku's origins as "**O**pen**B**e**OS**". - Ensuring that .NET's `llvm-libunwind` works correctly on Haiku. - `llvm-libunwind` needs to pull in `libbsd` for `dl_iterate_phdr`. Otherwise, basic functionality will not work. --- eng/Subsets.props | 2 +- src/coreclr/crossgen-corelib.proj | 4 ++-- src/coreclr/inc/pedecoder.h | 2 ++ .../Microsoft.NETCore.Native.Unix.targets | 13 ++++++++----- src/coreclr/nativeaot/Runtime/CMakeLists.txt | 1 + src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp | 8 ++++---- src/coreclr/tools/Common/CommandLineHelpers.cs | 3 +++ .../Compiler/ObjectWriter/PETargetExtensions.cs | 4 ++++ .../tools/Common/TypeSystem/Common/TargetDetails.cs | 1 + .../aot/ILCompiler.Diagnostics/PerfMapWriter.cs | 1 + .../ReadyToRunDiagnosticsConstants.cs | 1 + .../ObjectWriter/TargetExtensions.cs | 4 ++++ .../ReadyToRunReader.cs | 1 + .../TestCasesRunner/TrimmingDriver.cs | 2 ++ .../tools/aot/ILCompiler/ILCompilerRootCommand.cs | 2 +- .../tools/aot/crossgen2/Crossgen2RootCommand.cs | 2 +- src/coreclr/tools/r2rdump/Program.cs | 1 + .../Microsoft.NETCore.App.Runtime.CoreCLR.sfxproj | 4 ++-- 18 files changed, 40 insertions(+), 16 deletions(-) diff --git a/eng/Subsets.props b/eng/Subsets.props index ba8bc03906a1cb..c88f4a573ec09b 100644 --- a/eng/Subsets.props +++ b/eng/Subsets.props @@ -48,7 +48,7 @@ true - <_NativeAotSupportedOS Condition="'$(TargetOS)' != 'browser' and '$(TargetOS)' != 'haiku' and '$(TargetOS)' != 'illumos' and '$(TargetOS)' != 'netbsd' and '$(TargetOS)' != 'solaris'">true + <_NativeAotSupportedOS Condition="'$(TargetOS)' != 'browser' and '$(TargetOS)' != 'illumos' and '$(TargetOS)' != 'netbsd' and '$(TargetOS)' != 'solaris'">true <_NativeAotSupportedArch Condition="'$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64' or '$(TargetArchitecture)' == 'arm' or '$(TargetArchitecture)' == 'loongarch64' or '$(TargetArchitecture)' == 'riscv64' or ('$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'x86')">true true diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 069d3b7278e143..9289297f90ce5e 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -20,8 +20,8 @@ InvokeCrossgen2 true - - false + + false false diff --git a/src/coreclr/inc/pedecoder.h b/src/coreclr/inc/pedecoder.h index a373f90d55d3b1..44cf1e52c50184 100644 --- a/src/coreclr/inc/pedecoder.h +++ b/src/coreclr/inc/pedecoder.h @@ -108,6 +108,8 @@ inline CHECK CheckOverflow(RVA value1, COUNT_T value2) #define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x1993 #elif defined(__sun) #define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x1992 +#elif defined(__HAIKU__) +#define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0x0B05 #else #define IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE 0 #endif diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 6ec997d6c237ae..8184ae074e039e 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -65,6 +65,7 @@ The .NET Foundation licenses this file to you under the MIT license. $(CrossCompileArch)-linux-$(CrossCompileAbi) $(CrossCompileArch)-alpine-linux-$(CrossCompileAbi) $(CrossCompileArch)-unknown-freebsd12 + $(CrossCompileArch)-unknown-haiku @rpath/$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt) @@ -222,17 +223,19 @@ The .NET Foundation licenses this file to you under the MIT license. - + - + + + @@ -250,7 +253,7 @@ The .NET Foundation licenses this file to you under the MIT license. - + @@ -260,8 +263,8 @@ The .NET Foundation licenses this file to you under the MIT license. - - + + diff --git a/src/coreclr/nativeaot/Runtime/CMakeLists.txt b/src/coreclr/nativeaot/Runtime/CMakeLists.txt index 9f3a80c702358e..1d21c535c67804 100644 --- a/src/coreclr/nativeaot/Runtime/CMakeLists.txt +++ b/src/coreclr/nativeaot/Runtime/CMakeLists.txt @@ -159,6 +159,7 @@ else() add_definitions(-D_LIBUNWIND_IS_NATIVE_ONLY) if(CLR_CMAKE_TARGET_HAIKU) + add_definitions(-D_LIBUNWIND_USE_HAIKU_BSD_LIB=1) add_definitions(-DPT_GNU_EH_FRAME=PT_EH_FRAME) endif() diff --git a/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp index dec55db82905fb..b04a0a562aad57 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp @@ -504,7 +504,7 @@ void InitializeCurrentProcessCpuCount() g_RhNumberOfProcessors = count; } -#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) static pthread_key_t key; #endif @@ -548,7 +548,7 @@ bool PalInit() } #endif -#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) if (pthread_key_create(&key, RuntimeThreadShutdown) != 0) { return false; @@ -558,7 +558,7 @@ bool PalInit() return true; } -#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) +#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_HAIKU) struct TlsDestructionMonitor { void* m_thread = nullptr; @@ -604,7 +604,7 @@ FCIMPLEND // thread - thread to attach void PalAttachThread(void* thread) { -#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) if (pthread_setspecific(key, thread) != 0) { _ASSERTE(!"pthread_setspecific failed"); diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index 5aedd6781601fe..685d2df3aee192 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -67,6 +67,8 @@ public static TargetOS GetTargetOS(string token) return TargetOS.OSX; else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) return TargetOS.FreeBSD; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("HAIKU"))) + return TargetOS.Haiku; throw new NotImplementedException(); } @@ -77,6 +79,7 @@ public static TargetOS GetTargetOS(string token) "win" or "windows" => TargetOS.Windows, "osx" => TargetOS.OSX, "freebsd" => TargetOS.FreeBSD, + "haiku" => TargetOS.Haiku, "maccatalyst" => TargetOS.MacCatalyst, "iossimulator" => TargetOS.iOSSimulator, "ios" => TargetOS.iOS, diff --git a/src/coreclr/tools/Common/Compiler/ObjectWriter/PETargetExtensions.cs b/src/coreclr/tools/Common/Compiler/ObjectWriter/PETargetExtensions.cs index 12f992c29677b8..42fd0220f5fe1f 100644 --- a/src/coreclr/tools/Common/Compiler/ObjectWriter/PETargetExtensions.cs +++ b/src/coreclr/tools/Common/Compiler/ObjectWriter/PETargetExtensions.cs @@ -20,6 +20,7 @@ internal enum MachineOSOverride : ushort FreeBSD = 0xADC4, NetBSD = 0x1993, SunOS = 0x1992, + Haiku = 0x0B05, } /// @@ -125,6 +126,9 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t case TargetOS.NetBSD: return MachineOSOverride.NetBSD; + case TargetOS.Haiku: + return MachineOSOverride.Haiku; + default: throw new NotImplementedException(target.OperatingSystem.ToString()); } diff --git a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs index fc69a28bdcb977..826456b23f70cb 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/TargetDetails.cs @@ -23,6 +23,7 @@ public enum TargetOS FreeBSD, NetBSD, SunOS, + Haiku, Browser, Wasi } diff --git a/src/coreclr/tools/aot/ILCompiler.Diagnostics/PerfMapWriter.cs b/src/coreclr/tools/aot/ILCompiler.Diagnostics/PerfMapWriter.cs index 16f82023ad0b57..88460dc254b515 100644 --- a/src/coreclr/tools/aot/ILCompiler.Diagnostics/PerfMapWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Diagnostics/PerfMapWriter.cs @@ -117,6 +117,7 @@ private static PerfmapTokensForTarget TranslateTargetDetailsToPerfmapConstants(T TargetOS.FreeBSD => PerfMapOSToken.FreeBSD, TargetOS.NetBSD => PerfMapOSToken.NetBSD, TargetOS.SunOS => PerfMapOSToken.SunOS, + TargetOS.Haiku => PerfMapOSToken.Haiku, _ => throw new NotImplementedException(details.OperatingSystem.ToString()) }; diff --git a/src/coreclr/tools/aot/ILCompiler.Diagnostics/ReadyToRunDiagnosticsConstants.cs b/src/coreclr/tools/aot/ILCompiler.Diagnostics/ReadyToRunDiagnosticsConstants.cs index 281349be80e52e..6d5d28eb932237 100644 --- a/src/coreclr/tools/aot/ILCompiler.Diagnostics/ReadyToRunDiagnosticsConstants.cs +++ b/src/coreclr/tools/aot/ILCompiler.Diagnostics/ReadyToRunDiagnosticsConstants.cs @@ -32,6 +32,7 @@ public enum PerfMapOSToken : uint FreeBSD = 4, NetBSD = 5, SunOS = 6, + Haiku = 7, } public enum PerfMapAbiToken : uint diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs index ef76a9abcce5bb..3588ec59956a96 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/TargetExtensions.cs @@ -20,6 +20,7 @@ public enum MachineOSOverride : ushort FreeBSD = 0xADC4, NetBSD = 0x1993, SunOS = 0x1992, + Haiku = 0x0B05, } /// @@ -125,6 +126,9 @@ public static MachineOSOverride MachineOSOverrideFromTarget(this TargetDetails t case TargetOS.NetBSD: return MachineOSOverride.NetBSD; + case TargetOS.Haiku: + return MachineOSOverride.Haiku; + default: throw new NotImplementedException(target.OperatingSystem.ToString()); } diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs index 13dd20c4e979be..e01fe62f236560 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs @@ -30,6 +30,7 @@ public enum OperatingSystem Linux = 0x7B79, NetBSD = 0x1993, SunOS = 0x1992, + Haiku = 0x0B05, Windows = 0, Unknown = -1 } diff --git a/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.cs b/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.cs index acf155339d2055..b56906d3dd0617 100644 --- a/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.cs +++ b/src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/TrimmingDriver.cs @@ -183,6 +183,8 @@ public static void ComputeDefaultOptions(out TargetOS os, out TargetArchitecture os = TargetOS.OSX; else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)) os = TargetOS.FreeBSD; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("HAIKU"))) + os = TargetOS.Haiku; else throw new NotImplementedException(); diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs index fa5340d80a13fc..25b06c9602f611 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs +++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs @@ -350,7 +350,7 @@ public static void PrintExtendedHelp(ParseResult _) "considered to be input files. If no input files begin with '--' then this option is not necessary.\n"); string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64", "riscv64", "loongarch64" }; - string[] ValidOS = new string[] { "windows", "linux", "freebsd", "osx", "maccatalyst", "ios", "iossimulator", "tvos", "tvossimulator" }; + string[] ValidOS = new string[] { "windows", "linux", "freebsd", "haiku", "osx", "maccatalyst", "ios", "iossimulator", "tvos", "tvossimulator" }; Console.WriteLine("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetos", string.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant()); diff --git a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs index 49127d3077831a..14dc419a87caa1 100644 --- a/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs +++ b/src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs @@ -309,7 +309,7 @@ public static void PrintExtendedHelp(ParseResult _) Console.WriteLine(); string[] ValidArchitectures = ["arm", "armel", "arm64", "x86", "x64", "riscv64", "loongarch64", "wasm"]; - string[] ValidOS = ["windows", "linux", "osx", "ios", "iossimulator", "maccatalyst", "browser"]; + string[] ValidOS = ["windows", "linux", "haiku", "osx", "ios", "iossimulator", "maccatalyst", "browser"]; Console.WriteLine(String.Format(SR.SwitchWithDefaultHelp, "--targetos", String.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant())); Console.WriteLine(); diff --git a/src/coreclr/tools/r2rdump/Program.cs b/src/coreclr/tools/r2rdump/Program.cs index 7dd5f49c5a8d85..e4e98b35a14ce6 100644 --- a/src/coreclr/tools/r2rdump/Program.cs +++ b/src/coreclr/tools/r2rdump/Program.cs @@ -221,6 +221,7 @@ public void Dump(ReadyToRunReader r2r) OperatingSystem.Apple => TargetOS.OSX, OperatingSystem.FreeBSD => TargetOS.FreeBSD, OperatingSystem.NetBSD => TargetOS.FreeBSD, + OperatingSystem.Haiku => TargetOS.Haiku, _ => throw new NotImplementedException(r2r.OperatingSystem.ToString()), }; TargetDetails details = new(architecture, os, TargetAbi.NativeAot); diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.CoreCLR.sfxproj b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.CoreCLR.sfxproj index f8e03ff1dc0b71..f7b908affc2bb9 100644 --- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.CoreCLR.sfxproj +++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Runtime.CoreCLR.sfxproj @@ -22,8 +22,8 @@ true - - false + + false false false From 9f000ec641af4c9888517a902a01356f5419cb5d Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Sun, 26 Apr 2026 16:13:42 +1000 Subject: [PATCH 2/4] Haiku: Simplify OS configuration logic Use `Enum` parsing instead of `switch` statements to avoid having to manually add new OSes in the future. This also fixes a typo where NetBSD is mapped to FreeBSD. --- src/coreclr/tools/Common/CommandLineHelpers.cs | 14 ++------------ src/coreclr/tools/r2rdump/Program.cs | 9 +++------ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/coreclr/tools/Common/CommandLineHelpers.cs b/src/coreclr/tools/Common/CommandLineHelpers.cs index 685d2df3aee192..47b7a9f66ff5b5 100644 --- a/src/coreclr/tools/Common/CommandLineHelpers.cs +++ b/src/coreclr/tools/Common/CommandLineHelpers.cs @@ -75,18 +75,8 @@ public static TargetOS GetTargetOS(string token) return token.ToLowerInvariant() switch { - "linux" => TargetOS.Linux, - "win" or "windows" => TargetOS.Windows, - "osx" => TargetOS.OSX, - "freebsd" => TargetOS.FreeBSD, - "haiku" => TargetOS.Haiku, - "maccatalyst" => TargetOS.MacCatalyst, - "iossimulator" => TargetOS.iOSSimulator, - "ios" => TargetOS.iOS, - "tvossimulator" => TargetOS.tvOSSimulator, - "tvos" => TargetOS.tvOS, - "browser" => TargetOS.Browser, - "wasi" => TargetOS.Wasi, + "win" => TargetOS.Windows, + _ when Enum.TryParse(token, ignoreCase: true, out TargetOS os) => os, _ => throw new CommandLineException($"Target OS '{token}' is not supported") }; } diff --git a/src/coreclr/tools/r2rdump/Program.cs b/src/coreclr/tools/r2rdump/Program.cs index e4e98b35a14ce6..62e3f0b5b252c3 100644 --- a/src/coreclr/tools/r2rdump/Program.cs +++ b/src/coreclr/tools/r2rdump/Program.cs @@ -214,15 +214,12 @@ public void Dump(ReadyToRunReader r2r) Machine.RiscV64 => TargetArchitecture.RiscV64, _ => throw new NotImplementedException(r2r.Machine.ToString()), }; + string osToken = r2r.OperatingSystem.ToString(); TargetOS os = r2r.OperatingSystem switch { - OperatingSystem.Windows => TargetOS.Windows, - OperatingSystem.Linux => TargetOS.Linux, OperatingSystem.Apple => TargetOS.OSX, - OperatingSystem.FreeBSD => TargetOS.FreeBSD, - OperatingSystem.NetBSD => TargetOS.FreeBSD, - OperatingSystem.Haiku => TargetOS.Haiku, - _ => throw new NotImplementedException(r2r.OperatingSystem.ToString()), + _ when Enum.TryParse(osToken, ignoreCase: true, out TargetOS parsedOs) => parsedOs, + _ => throw new NotImplementedException(osToken), }; TargetDetails details = new(architecture, os, TargetAbi.NativeAot); From ea0ecb360dfbaf7aaff3366efbcd525aa3386967 Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Sun, 26 Apr 2026 16:15:59 +1000 Subject: [PATCH 3/4] Haiku: Check for `pthread_key_create` Check for `pthread_key_create` and prioritize using that to detect the end of thread lifetimes. This removes a dependency on `libstdc++` for UNIX platforms. --- src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp | 8 ++++---- src/coreclr/nativeaot/Runtime/unix/config.h.in | 1 + src/coreclr/nativeaot/Runtime/unix/configure.cmake | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp index b04a0a562aad57..0fd3f622d039e7 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp @@ -504,7 +504,7 @@ void InitializeCurrentProcessCpuCount() g_RhNumberOfProcessors = count; } -#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) +#if HAVE_PTHREAD_KEY_CREATE static pthread_key_t key; #endif @@ -548,7 +548,7 @@ bool PalInit() } #endif -#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) +#if HAVE_PTHREAD_KEY_CREATE if (pthread_key_create(&key, RuntimeThreadShutdown) != 0) { return false; @@ -558,7 +558,7 @@ bool PalInit() return true; } -#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_HAIKU) +#if !HAVE_PTHREAD_KEY_CREATE struct TlsDestructionMonitor { void* m_thread = nullptr; @@ -604,7 +604,7 @@ FCIMPLEND // thread - thread to attach void PalAttachThread(void* thread) { -#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) +#if HAVE_PTHREAD_KEY_CREATE if (pthread_setspecific(key, thread) != 0) { _ASSERTE(!"pthread_setspecific failed"); diff --git a/src/coreclr/nativeaot/Runtime/unix/config.h.in b/src/coreclr/nativeaot/Runtime/unix/config.h.in index 3a5e1ef87b5dc3..1a13cff7cf1702 100644 --- a/src/coreclr/nativeaot/Runtime/unix/config.h.in +++ b/src/coreclr/nativeaot/Runtime/unix/config.h.in @@ -10,6 +10,7 @@ #cmakedefine01 HAVE_PTHREAD_GETATTR_NP #cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK #cmakedefine01 HAVE_PTHREAD_GETTHREADID_NP +#cmakedefine01 HAVE_PTHREAD_KEY_CREATE #cmakedefine01 HAVE_CLOCK_NANOSLEEP #cmakedefine01 HAVE_SYSCTLBYNAME diff --git a/src/coreclr/nativeaot/Runtime/unix/configure.cmake b/src/coreclr/nativeaot/Runtime/unix/configure.cmake index 7cd0bf8ef7542e..2d15fccaef49c0 100644 --- a/src/coreclr/nativeaot/Runtime/unix/configure.cmake +++ b/src/coreclr/nativeaot/Runtime/unix/configure.cmake @@ -32,6 +32,7 @@ check_library_exists(${PTHREAD_LIBRARY} pthread_attr_get_np "" HAVE_PTHREAD_ATTR check_library_exists(${PTHREAD_LIBRARY} pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP) check_library_exists(${PTHREAD_LIBRARY} pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK) check_library_exists(${PTHREAD_LIBRARY} pthread_getthreadid_np "" HAVE_PTHREAD_GETTHREADID_NP) +check_library_exists(${PTHREAD_LIBRARY} pthread_key_create "" HAVE_PTHREAD_KEY_CREATE) check_function_exists(clock_nanosleep HAVE_CLOCK_NANOSLEEP) From 2829aa3909436c14911d789ad785e7061968f99e Mon Sep 17 00:00:00 2001 From: Trung Nguyen <57174311+trungnt2910@users.noreply.github.com> Date: Mon, 27 Apr 2026 11:43:40 +1000 Subject: [PATCH 4/4] Revert "Haiku: Check for `pthread_key_create`" This reverts commit ea0ecb360dfbaf7aaff3366efbcd525aa3386967. --- src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp | 8 ++++---- src/coreclr/nativeaot/Runtime/unix/config.h.in | 1 - src/coreclr/nativeaot/Runtime/unix/configure.cmake | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp index 0fd3f622d039e7..b04a0a562aad57 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalUnix.cpp @@ -504,7 +504,7 @@ void InitializeCurrentProcessCpuCount() g_RhNumberOfProcessors = count; } -#if HAVE_PTHREAD_KEY_CREATE +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) static pthread_key_t key; #endif @@ -548,7 +548,7 @@ bool PalInit() } #endif -#if HAVE_PTHREAD_KEY_CREATE +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) if (pthread_key_create(&key, RuntimeThreadShutdown) != 0) { return false; @@ -558,7 +558,7 @@ bool PalInit() return true; } -#if !HAVE_PTHREAD_KEY_CREATE +#if !defined(TARGET_LINUX) && !defined(TARGET_ANDROID) && !defined(TARGET_HAIKU) struct TlsDestructionMonitor { void* m_thread = nullptr; @@ -604,7 +604,7 @@ FCIMPLEND // thread - thread to attach void PalAttachThread(void* thread) { -#if HAVE_PTHREAD_KEY_CREATE +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) || defined(TARGET_HAIKU) if (pthread_setspecific(key, thread) != 0) { _ASSERTE(!"pthread_setspecific failed"); diff --git a/src/coreclr/nativeaot/Runtime/unix/config.h.in b/src/coreclr/nativeaot/Runtime/unix/config.h.in index 1a13cff7cf1702..3a5e1ef87b5dc3 100644 --- a/src/coreclr/nativeaot/Runtime/unix/config.h.in +++ b/src/coreclr/nativeaot/Runtime/unix/config.h.in @@ -10,7 +10,6 @@ #cmakedefine01 HAVE_PTHREAD_GETATTR_NP #cmakedefine01 HAVE_PTHREAD_CONDATTR_SETCLOCK #cmakedefine01 HAVE_PTHREAD_GETTHREADID_NP -#cmakedefine01 HAVE_PTHREAD_KEY_CREATE #cmakedefine01 HAVE_CLOCK_NANOSLEEP #cmakedefine01 HAVE_SYSCTLBYNAME diff --git a/src/coreclr/nativeaot/Runtime/unix/configure.cmake b/src/coreclr/nativeaot/Runtime/unix/configure.cmake index 2d15fccaef49c0..7cd0bf8ef7542e 100644 --- a/src/coreclr/nativeaot/Runtime/unix/configure.cmake +++ b/src/coreclr/nativeaot/Runtime/unix/configure.cmake @@ -32,7 +32,6 @@ check_library_exists(${PTHREAD_LIBRARY} pthread_attr_get_np "" HAVE_PTHREAD_ATTR check_library_exists(${PTHREAD_LIBRARY} pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP) check_library_exists(${PTHREAD_LIBRARY} pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK) check_library_exists(${PTHREAD_LIBRARY} pthread_getthreadid_np "" HAVE_PTHREAD_GETTHREADID_NP) -check_library_exists(${PTHREAD_LIBRARY} pthread_key_create "" HAVE_PTHREAD_KEY_CREATE) check_function_exists(clock_nanosleep HAVE_CLOCK_NANOSLEEP)