From 39dd9dd8f7a3aa7a7e1e1fe69f58437529a173c2 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:45:23 +0300 Subject: [PATCH 01/12] Add ability to use clang with GNU toolchain on Haiku --- eng/common/cross/toolchain.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/eng/common/cross/toolchain.cmake b/eng/common/cross/toolchain.cmake index ff2dfdb4a5bf60..16acdf9cd24f99 100644 --- a/eng/common/cross/toolchain.cmake +++ b/eng/common/cross/toolchain.cmake @@ -225,13 +225,16 @@ elseif(ILLUMOS) locate_toolchain_exec(g++ CMAKE_CXX_COMPILER) elseif(HAIKU) set(CMAKE_SYSROOT "${CROSS_ROOTFS}") - set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};${CROSS_ROOTFS}/cross-tools-x86_64/bin") set(CMAKE_SYSTEM_PREFIX_PATH "${CROSS_ROOTFS}") set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp") set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp") - locate_toolchain_exec(gcc CMAKE_C_COMPILER) - locate_toolchain_exec(g++ CMAKE_CXX_COMPILER) + # Tell clang (if used instead of gcc) where the Haiku GCC cross-toolchain lives + # so it can find crtbegin/crtend objects and libgcc under + # cross-tools-x86_64/lib/gcc/x86_64-unknown-haiku// + set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") + set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") + set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") # let CMake set up the correct search paths include(Platform/Haiku) From a17a93ddba0c48576a80e14ea0d7b5d0dc9c5a45 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 15:48:41 +0300 Subject: [PATCH 02/12] Cleanups --- eng/common/cross/toolchain.cmake | 3 --- 1 file changed, 3 deletions(-) diff --git a/eng/common/cross/toolchain.cmake b/eng/common/cross/toolchain.cmake index 16acdf9cd24f99..030a472cde35f7 100644 --- a/eng/common/cross/toolchain.cmake +++ b/eng/common/cross/toolchain.cmake @@ -229,9 +229,6 @@ elseif(HAIKU) set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp") set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp") - # Tell clang (if used instead of gcc) where the Haiku GCC cross-toolchain lives - # so it can find crtbegin/crtend objects and libgcc under - # cross-tools-x86_64/lib/gcc/x86_64-unknown-haiku// set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") From ae1767381347bdab4efb1417b74be1b2effeee72 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:30:11 +0300 Subject: [PATCH 03/12] Update configureplatform.cmake --- eng/native/configureplatform.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index 18952687829684..db3a2a2f065ee5 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -494,7 +494,11 @@ if(NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) # The default linker on Solaris also does not support PIE. if(NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_SUNOS AND NOT CLR_CMAKE_TARGET_APPLE AND NOT MSVC) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") - add_compile_options($<$,EXECUTABLE>:-fPIE>) + if(CLR_CMAKE_TARGET_HAIKU) + add_compile_options($<$,EXECUTABLE>:-fPIC>) + else() + add_compile_options($<$,EXECUTABLE>:-fPIE>) + endif() add_compile_options($<$,SHARED_LIBRARY>:-fPIC>) endif() From c8fe8e3072df92d09cce849c588fd61a7bbf1047 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:36:02 +0300 Subject: [PATCH 04/12] Update pal_environment.c --- src/native/libs/System.Native/pal_environment.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/libs/System.Native/pal_environment.c b/src/native/libs/System.Native/pal_environment.c index 76ad3a807eec1e..b61c8fab6c8751 100644 --- a/src/native/libs/System.Native/pal_environment.c +++ b/src/native/libs/System.Native/pal_environment.c @@ -25,8 +25,8 @@ char** SystemNative_GetEnviron(void) #endif } -void SystemNative_FreeEnviron(char** environ) +void SystemNative_FreeEnviron(char** environment) { // no op - (void)environ; + (void)environment; } From cddb40587813ab3465e496ad665721fee17a712c Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:36:38 +0300 Subject: [PATCH 05/12] Update pal_mount.c --- src/native/libs/System.Native/pal_mount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Native/pal_mount.c b/src/native/libs/System.Native/pal_mount.c index 69ae5ca7a29f85..b7fe6fa55bccb2 100644 --- a/src/native/libs/System.Native/pal_mount.c +++ b/src/native/libs/System.Native/pal_mount.c @@ -34,7 +34,7 @@ #endif // __HAIKU__ // Android does not define MNTOPT_RO -#ifndef MNTOPT_RO +#if !defined(MNTOPT_RO) && (HAVE_SYS_MNTENT_H || HAVE_MNTENT_H) #define MNTOPT_RO "r" #endif #endif From a1b45273dedb87385189bada2457cce8f8fb6276 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:37:10 +0300 Subject: [PATCH 06/12] Update pal_networking.c --- src/native/libs/System.Native/pal_networking.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 7f13890ca61fe3..ac1650519e96e7 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -3681,6 +3681,7 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i // Emulate sendfile using a simple read/send loop. *sent = 0; char* buffer = NULL; + size_t bufferLength = Min((size_t)count, 80 * 1024 * sizeof(char)); // Save the original input file position and seek to the offset position off_t inputFileOrigOffset = lseek(infd, 0, SEEK_CUR); @@ -3690,7 +3691,6 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i } // Allocate a buffer - size_t bufferLength = Min((size_t)count, 80 * 1024 * sizeof(char)); buffer = (char*)malloc(bufferLength); if (buffer == NULL) { From 8ec028b01c14579fc1a61eaff9efbbc1e7b29ee8 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:37:58 +0300 Subject: [PATCH 07/12] Update pal_process.c --- src/native/libs/System.Native/pal_process.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/native/libs/System.Native/pal_process.c b/src/native/libs/System.Native/pal_process.c index bc2a713849c1b7..6249f8821bce8d 100644 --- a/src/native/libs/System.Native/pal_process.c +++ b/src/native/libs/System.Native/pal_process.c @@ -784,6 +784,9 @@ static int32_t ConvertRLimitResourcesPalToPlatform(RLimitResources value) #elif defined(RLIMIT_VMEM) case PAL_RLIMIT_RSS: return RLIMIT_VMEM; +#else + case PAL_RLIMIT_RSS: + break; #endif #ifdef RLIMIT_MEMLOCK case PAL_RLIMIT_MEMLOCK: @@ -791,17 +794,19 @@ static int32_t ConvertRLimitResourcesPalToPlatform(RLimitResources value) #elif defined(RLIMIT_VMEM) case PAL_RLIMIT_MEMLOCK: return RLIMIT_VMEM; +#else + case PAL_RLIMIT_MEMLOCK: + break; #endif #ifdef RLIMIT_NPROC case PAL_RLIMIT_NPROC: return RLIMIT_NPROC; +#else + case PAL_RLIMIT_NPROC: + break; #endif case PAL_RLIMIT_NOFILE: return RLIMIT_NOFILE; -#if !defined(RLIMIT_RSS) || !(defined(RLIMIT_MEMLOCK) || defined(RLIMIT_VMEM)) || !defined(RLIMIT_NPROC) - default: - break; -#endif } assert_msg(false, "Unknown RLIMIT value", (int)value); From 865bfb5bab425e04edca2f95a09cc7a7bae91b5d Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 19:38:31 +0300 Subject: [PATCH 08/12] Update pal_evp_pkey.c --- .../libs/System.Security.Cryptography.Native/pal_evp_pkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c index c3dc67713f12d0..8da8bc93ee829c 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c @@ -1005,7 +1005,7 @@ EVP_PKEY* CryptoNative_LoadKeyFromProvider(const char* providerName, const char* EvpPKeyExtraHandle* extra = (EvpPKeyExtraHandle*)malloc(sizeof(EvpPKeyExtraHandle)); extra->prov = prov; extra->libCtx = libCtx; - atomic_init(&extra->refCount, 1); + __c11_atomic_init(&extra->refCount, 1); *extraHandle = extra; } From c1312bfc3eb7517026e49e089789afb45bcc6695 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 24 Apr 2026 20:42:26 +0300 Subject: [PATCH 09/12] Update pal_evp_pkey.c --- .../libs/System.Security.Cryptography.Native/pal_evp_pkey.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c index 8da8bc93ee829c..330794381be2ff 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c @@ -1005,7 +1005,11 @@ EVP_PKEY* CryptoNative_LoadKeyFromProvider(const char* providerName, const char* EvpPKeyExtraHandle* extra = (EvpPKeyExtraHandle*)malloc(sizeof(EvpPKeyExtraHandle)); extra->prov = prov; extra->libCtx = libCtx; +#ifdef TARGET_HAIKU __c11_atomic_init(&extra->refCount, 1); +#else + atomic_init(&extra->refCount, 1); +#endif *extraHandle = extra; } From 0d3664b2e065df88910dff36f5739fde0d48bdf4 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sat, 25 Apr 2026 11:34:32 +0300 Subject: [PATCH 10/12] Keep gcc working --- eng/common/cross/toolchain.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/eng/common/cross/toolchain.cmake b/eng/common/cross/toolchain.cmake index 030a472cde35f7..99d6dfe82dde38 100644 --- a/eng/common/cross/toolchain.cmake +++ b/eng/common/cross/toolchain.cmake @@ -229,9 +229,15 @@ elseif(HAIKU) set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp") set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp") - set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") - set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") - set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") + if ($ENV{CCC_CC} MATCHES ".*gcc.*") + set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH};${CROSS_ROOTFS}/cross-tools-x86_64/bin") + locate_toolchain_exec(gcc CMAKE_C_COMPILER) + locate_toolchain_exec(g++ CMAKE_CXX_COMPILER) + else() + set(CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") + set(CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") + set(CMAKE_ASM_COMPILER_EXTERNAL_TOOLCHAIN "${CROSS_ROOTFS}/cross-tools-x86_64") + endif() # let CMake set up the correct search paths include(Platform/Haiku) From 96107022ef7a2cd299d23c2d17a1dea9b61a6900 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sat, 25 Apr 2026 11:40:19 +0300 Subject: [PATCH 11/12] Update pal_evp_pkey.c --- .../libs/System.Security.Cryptography.Native/pal_evp_pkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c index 330794381be2ff..941e8363a8a97c 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c @@ -1005,7 +1005,7 @@ EVP_PKEY* CryptoNative_LoadKeyFromProvider(const char* providerName, const char* EvpPKeyExtraHandle* extra = (EvpPKeyExtraHandle*)malloc(sizeof(EvpPKeyExtraHandle)); extra->prov = prov; extra->libCtx = libCtx; -#ifdef TARGET_HAIKU +#if defined(TARGET_HAIKU) && defined(__clang__) __c11_atomic_init(&extra->refCount, 1); #else atomic_init(&extra->refCount, 1); From d71b4e62c6dbc8cabfb2f1e5d1409e80fba43034 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Sat, 25 Apr 2026 11:40:54 +0300 Subject: [PATCH 12/12] Update gcenv.unix.cpp --- src/coreclr/gc/unix/gcenv.unix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/gc/unix/gcenv.unix.cpp b/src/coreclr/gc/unix/gcenv.unix.cpp index f4b5cb7dfb7f7b..42b73e0611241a 100644 --- a/src/coreclr/gc/unix/gcenv.unix.cpp +++ b/src/coreclr/gc/unix/gcenv.unix.cpp @@ -208,7 +208,7 @@ bool GCToOSInterface::Initialize() #else // HAVE_SCHED_GETAFFINITY - for (size_t i = 0; i < configuredCpuCount; i++) + for (int i = 0; i < configuredCpuCount; i++) { g_processAffinitySet.Add(i); }