[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/92601 Backport af7467c Requested by: @Ericson2314 >From 472f75ba1cd626b92bf2b10099626717fcd58e29 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 17 May 2024 16:49:04 -0400 Subject: [PATCH] [libcxx][libcxxabi] Fix build for OpenBSD (#92186) - No indirect syscalls on OpenBSD. Instead there is a `futex` function which issues a direct syscall. - Monotonic clock is available despite the full POSIX suite of timers not being available in its entirety. See https://lists.boost.org/boost-bugs/2015/07/41690.php and https://github.com/boostorg/log/commit/c98b1f459add14d5ce3e9e63e2469064601d7f71 for a description of an analogous problem and fix for Boost. (cherry picked from commit af7467ce9f447d6fe977b73db1f03a18d6bbd511) --- libcxx/src/atomic.cpp | 16 ++-- libcxx/src/chrono.cpp | 4 +++- libcxxabi/src/cxa_guard_impl.h | 16 +++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp index 2f0389ae6974a..6b1f03c21bbcc 100644 --- a/libcxx/src/atomic.cpp +++ b/libcxx/src/atomic.cpp @@ -25,16 +25,28 @@ # if !defined(SYS_futex) && defined(SYS_futex_time64) #define SYS_futex SYS_futex_time64 # endif +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) #elif defined(__FreeBSD__) # include # include +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) + +#elif defined(__OpenBSD__) + +# include + +// OpenBSD has no indirect syscalls +# define _LIBCPP_FUTEX(...) futex(__VA_ARGS__) + #else // <- Add other operating systems here // Baseline needs no new headers +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) + #endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -44,11 +56,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) { static constexpr timespec __timeout = {2, 0}; - syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0); + _LIBCPP_FUTEX(__ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0); } static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) { - syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0); + _LIBCPP_FUTEX(__ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0); } #elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK) diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp index c5e827c0cb59f..e7d6dfbc22924 100644 --- a/libcxx/src/chrono.cpp +++ b/libcxx/src/chrono.cpp @@ -31,7 +31,9 @@ # include // for gettimeofday and timeval #endif -#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) +// OpenBSD does not have a fully conformant suite of POSIX timers, but +// it does have clock_gettime and CLOCK_MONOTONIC which is all we need. +#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) # define _LIBCPP_HAS_CLOCK_GETTIME #endif diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h index e00d54b3a7318..90d589be4d773 100644 --- a/libcxxabi/src/cxa_guard_impl.h +++ b/libcxxabi/src/cxa_guard_impl.h @@ -47,6 +47,9 @@ #include "__cxxabi_config.h" #include "include/atomic_support.h" // from libc++ #if defined(__has_include) +# if __has_include() +#include +# endif # if __has_include() #include # endif @@ -411,7 +414,18 @@ struct InitByteGlobalMutex { // Futex Implementation //===--===// -#if defined(SYS_futex) +#if defined(__OpenBSD__) +void PlatformFutexWait(int* addr, int expect) { + constexpr int WAIT = 0; + futex(reinterpret_cast(addr), WAIT, expect, NULL, NULL); + __tsan_acquire(addr); +} +void PlatformFutexWake(int* addr) { + constexpr int WAKE = 1; + __tsan_release(addr); + futex(reinterpret_cast(addr), WAKE, INT_MAX, NULL, NULL); +} +#elif defined(SYS_futex) void PlatformFutexWait(int* addr, int expect) { constexpr int WAIT = 0; syscall(SYS_futex, addr, WAIT, expect, 0); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
llvmbot wrote: @brad0 What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
llvmbot wrote: @llvm/pr-subscribers-libcxxabi @llvm/pr-subscribers-libcxx Author: None (llvmbot) Changes Backport af7467c Requested by: @Ericson2314 --- Full diff: https://github.com/llvm/llvm-project/pull/92601.diff 3 Files Affected: - (modified) libcxx/src/atomic.cpp (+14-2) - (modified) libcxx/src/chrono.cpp (+3-1) - (modified) libcxxabi/src/cxa_guard_impl.h (+15-1) ``diff diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp index 2f0389ae6974a..6b1f03c21bbcc 100644 --- a/libcxx/src/atomic.cpp +++ b/libcxx/src/atomic.cpp @@ -25,16 +25,28 @@ # if !defined(SYS_futex) && defined(SYS_futex_time64) #define SYS_futex SYS_futex_time64 # endif +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) #elif defined(__FreeBSD__) # include # include +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) + +#elif defined(__OpenBSD__) + +# include + +// OpenBSD has no indirect syscalls +# define _LIBCPP_FUTEX(...) futex(__VA_ARGS__) + #else // <- Add other operating systems here // Baseline needs no new headers +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) + #endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -44,11 +56,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) { static constexpr timespec __timeout = {2, 0}; - syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0); + _LIBCPP_FUTEX(__ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0); } static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) { - syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0); + _LIBCPP_FUTEX(__ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0); } #elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK) diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp index c5e827c0cb59f..e7d6dfbc22924 100644 --- a/libcxx/src/chrono.cpp +++ b/libcxx/src/chrono.cpp @@ -31,7 +31,9 @@ # include // for gettimeofday and timeval #endif -#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) +// OpenBSD does not have a fully conformant suite of POSIX timers, but +// it does have clock_gettime and CLOCK_MONOTONIC which is all we need. +#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) # define _LIBCPP_HAS_CLOCK_GETTIME #endif diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h index e00d54b3a7318..90d589be4d773 100644 --- a/libcxxabi/src/cxa_guard_impl.h +++ b/libcxxabi/src/cxa_guard_impl.h @@ -47,6 +47,9 @@ #include "__cxxabi_config.h" #include "include/atomic_support.h" // from libc++ #if defined(__has_include) +# if __has_include() +#include +# endif # if __has_include() #include # endif @@ -411,7 +414,18 @@ struct InitByteGlobalMutex { // Futex Implementation //===--===// -#if defined(SYS_futex) +#if defined(__OpenBSD__) +void PlatformFutexWait(int* addr, int expect) { + constexpr int WAIT = 0; + futex(reinterpret_cast(addr), WAIT, expect, NULL, NULL); + __tsan_acquire(addr); +} +void PlatformFutexWake(int* addr) { + constexpr int WAKE = 1; + __tsan_release(addr); + futex(reinterpret_cast(addr), WAKE, INT_MAX, NULL, NULL); +} +#elif defined(SYS_futex) void PlatformFutexWait(int* addr, int expect) { constexpr int WAIT = 0; syscall(SYS_futex, addr, WAIT, expect, 0); `` https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
https://github.com/brad0 approved this pull request. https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
tstellar wrote: @brad0 Can you look at #92293 too? https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
Ericson2314 wrote: Thanks, both of you. I can't merge these, so I am guessing someone else will come along that can? https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
brad0 wrote: > Thanks, both of you. I can't merge these, so I am guessing someone else will > come along that can? The RE manager does. This release cycle being tsteller. https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
https://github.com/tstellar updated https://github.com/llvm/llvm-project/pull/92601 >From 1118c2e05e67a36ed8ca250524525cdb66a55256 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Fri, 17 May 2024 16:49:04 -0400 Subject: [PATCH] [libcxx][libcxxabi] Fix build for OpenBSD (#92186) - No indirect syscalls on OpenBSD. Instead there is a `futex` function which issues a direct syscall. - Monotonic clock is available despite the full POSIX suite of timers not being available in its entirety. See https://lists.boost.org/boost-bugs/2015/07/41690.php and https://github.com/boostorg/log/commit/c98b1f459add14d5ce3e9e63e2469064601d7f71 for a description of an analogous problem and fix for Boost. (cherry picked from commit af7467ce9f447d6fe977b73db1f03a18d6bbd511) --- libcxx/src/atomic.cpp | 16 ++-- libcxx/src/chrono.cpp | 4 +++- libcxxabi/src/cxa_guard_impl.h | 16 +++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/libcxx/src/atomic.cpp b/libcxx/src/atomic.cpp index 2f0389ae6974a..6b1f03c21bbcc 100644 --- a/libcxx/src/atomic.cpp +++ b/libcxx/src/atomic.cpp @@ -25,16 +25,28 @@ # if !defined(SYS_futex) && defined(SYS_futex_time64) #define SYS_futex SYS_futex_time64 # endif +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) #elif defined(__FreeBSD__) # include # include +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) + +#elif defined(__OpenBSD__) + +# include + +// OpenBSD has no indirect syscalls +# define _LIBCPP_FUTEX(...) futex(__VA_ARGS__) + #else // <- Add other operating systems here // Baseline needs no new headers +# define _LIBCPP_FUTEX(...) syscall(SYS_futex, __VA_ARGS__) + #endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -44,11 +56,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD static void __libcpp_platform_wait_on_address(__cxx_atomic_contention_t const volatile* __ptr, __cxx_contention_t __val) { static constexpr timespec __timeout = {2, 0}; - syscall(SYS_futex, __ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0); + _LIBCPP_FUTEX(__ptr, FUTEX_WAIT_PRIVATE, __val, &__timeout, 0, 0); } static void __libcpp_platform_wake_by_address(__cxx_atomic_contention_t const volatile* __ptr, bool __notify_one) { - syscall(SYS_futex, __ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0); + _LIBCPP_FUTEX(__ptr, FUTEX_WAKE_PRIVATE, __notify_one ? 1 : INT_MAX, 0, 0, 0); } #elif defined(__APPLE__) && defined(_LIBCPP_USE_ULOCK) diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp index c5e827c0cb59f..e7d6dfbc22924 100644 --- a/libcxx/src/chrono.cpp +++ b/libcxx/src/chrono.cpp @@ -31,7 +31,9 @@ # include // for gettimeofday and timeval #endif -#if defined(__APPLE__) || defined(__gnu_hurd__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) +// OpenBSD does not have a fully conformant suite of POSIX timers, but +// it does have clock_gettime and CLOCK_MONOTONIC which is all we need. +#if defined(__APPLE__) || defined(__gnu_hurd__) || defined(__OpenBSD__) || (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0) # define _LIBCPP_HAS_CLOCK_GETTIME #endif diff --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h index e00d54b3a7318..90d589be4d773 100644 --- a/libcxxabi/src/cxa_guard_impl.h +++ b/libcxxabi/src/cxa_guard_impl.h @@ -47,6 +47,9 @@ #include "__cxxabi_config.h" #include "include/atomic_support.h" // from libc++ #if defined(__has_include) +# if __has_include() +#include +# endif # if __has_include() #include # endif @@ -411,7 +414,18 @@ struct InitByteGlobalMutex { // Futex Implementation //===--===// -#if defined(SYS_futex) +#if defined(__OpenBSD__) +void PlatformFutexWait(int* addr, int expect) { + constexpr int WAIT = 0; + futex(reinterpret_cast(addr), WAIT, expect, NULL, NULL); + __tsan_acquire(addr); +} +void PlatformFutexWake(int* addr) { + constexpr int WAKE = 1; + __tsan_release(addr); + futex(reinterpret_cast(addr), WAKE, INT_MAX, NULL, NULL); +} +#elif defined(SYS_futex) void PlatformFutexWait(int* addr, int expect) { constexpr int WAIT = 0; syscall(SYS_futex, addr, WAIT, expect, 0); ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [libcxx] [libcxxabi] release/18.x: [libcxx][libcxxabi] Fix build for OpenBSD (#92186) (PR #92601)
https://github.com/tstellar closed https://github.com/llvm/llvm-project/pull/92601 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits