Skip to content

Haiku: Fix native component build#126701

Open
trungnt2910 wants to merge 3 commits intodotnet:mainfrom
trungnt2910:dev/trungnt2910/haiku-native-libs-build
Open

Haiku: Fix native component build#126701
trungnt2910 wants to merge 3 commits intodotnet:mainfrom
trungnt2910:dev/trungnt2910/haiku-native-libs-build

Conversation

@trungnt2910
Copy link
Copy Markdown
Contributor

This contains the missing configuration updates required to build the native component for Haiku with the latest .NET source.

Part of #55803.

This contains the missing configuration updates required to build the
native component for Haiku with the latest .NET source.
Copilot AI review requested due to automatic review settings April 9, 2026 11:50
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 9, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates native build configuration to improve compatibility with Haiku when building dotnet/runtime native components, primarily by feature-detecting pthread robust-mutex APIs and adjusting Haiku linker behavior in CMake.

Changes:

  • Add CMake feature checks for pthread_mutex_consistent and pthread_mutexattr_setrobust, and expose them via pal_config.h.
  • Conditionally compile robust-mutex initialization and recovery paths in pal_crossprocessmutex.c based on those feature macros.
  • Adjust Haiku CMake linker-group settings as a workaround for missing upstream CMake support.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/native/libs/System.Native/pal_crossprocessmutex.c Guard robust mutex attr usage and EOWNERDEAD recovery logic behind feature macros.
src/native/libs/configure.cmake Add configure-time detection for robust-mutex related pthread APIs.
src/native/libs/Common/pal_config.h.in Export new HAVE_PTHREAD_MUTEX_* feature macros to native builds.
eng/native/configurecompiler.cmake Set Haiku linker-group rescan settings and adjust Haiku linker flags.

@trungnt2910 trungnt2910 requested a review from jkotas April 13, 2026 11:22
@trungnt2910 trungnt2910 force-pushed the dev/trungnt2910/haiku-native-libs-build branch from 30de881 to c66034d Compare April 13, 2026 11:24
Instead of guarding for robust mutexes in `pal_crossprocessmutex.c`,
guard them in the `CMakeLists.txt` so that platforms without these can
fall back to the stubbed implementation on unsupported platforms.
- Remove the hard-coded OS support list for `pthread` robust mutexes in
favor of the new configure-time detection flags
`HAVE_PTHREAD_MUTEXATTR_SETROBUST` and `HAVE_PTHREAD_MUTEX_CONSISTENT`.
- Simplify the condition by flipping the order.
Copilot AI review requested due to automatic review settings April 14, 2026 08:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

set(CMAKE_LINK_GROUP_USING_RESCAN_SUPPORTED TRUE)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-Wa,--noexecstack>)
add_linker_flag("-Wl,--no-undefined")
add_linker_flag("-Wl,--build-id=sha1")
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Haiku-specific linker flags no longer include a “no undefined symbols” check (previously -Wl,--no-undefined). Dropping this makes it easier for undefined references to slip through link and fail later at runtime. If Haiku’s linker doesn’t support --no-undefined, consider using check_linker_flag() and conditionally adding it (or an equivalent like -Wl,-z,defs), so we keep the safety check when it’s supported.

Suggested change
add_linker_flag("-Wl,--build-id=sha1")
add_linker_flag("-Wl,--build-id=sha1")
check_linker_flag(C "-Wl,--no-undefined" LINKER_SUPPORTS_NO_UNDEFINED_FLAG)
if(LINKER_SUPPORTS_NO_UNDEFINED_FLAG)
add_linker_flag("-Wl,--no-undefined")
else()
check_linker_flag(C "-Wl,-z,defs" LINKER_SUPPORTS_Z_DEFS_FLAG)
if(LINKER_SUPPORTS_Z_DEFS_FLAG)
add_linker_flag("-Wl,-z,defs")
endif()
endif()

Copilot uses AI. Check for mistakes.
Comment on lines +59 to 65
if (HAVE_PTHREAD_MUTEXATTR_SETROBUST AND HAVE_PTHREAD_MUTEX_CONSISTENT)
list (APPEND NATIVE_SOURCES
pal_crossprocessmutex_unsupported.c)
pal_crossprocessmutex.c)
else()
list (APPEND NATIVE_SOURCES
pal_crossprocessmutex.c
)
pal_crossprocessmutex_unsupported.c)
endif()
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes cross-process mutex source selection from an OS allow/deny list to pure symbol detection. That means targets that were previously forced to use pal_crossprocessmutex_unsupported.c (notably Android/OpenBSD/Apple/etc.) may now build the pthread-based implementation if those symbols happen to be present, which is a behavior change and could reintroduce known platform issues. Consider keeping the explicit target exclusions (at least for the previously-denied targets) and combining them with the new HAVE_PTHREAD_MUTEX* feature checks, or add a comment explaining why the old exclusions are no longer needed.

Copilot uses AI. Check for mistakes.
@jkotas jkotas requested a review from jkoritzinsky April 14, 2026 13:33
Copy link
Copy Markdown
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkoritzinsky Could you please sign off as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Infrastructure community-contribution Indicates that the PR has been added by a community member os-haiku

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants