[libc-commits] [libc] [libc] Fix pause build on riscv32 via ppoll wrapper (PR #231959)
Mikhail R. Gadelha via libc-commits
libc-commits at lists.llvm.org
Tue Nov 17 03:48:13 PST 2026
https://github.com/mikhailramalho updated https://github.com/llvm/llvm-project/pull/231959
>From 25e5163bf6365c6fb13992b4435c0031c462237f Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Wed, 14 Oct 2026 12:21:45 -0300
Subject: [PATCH 1/4] [libc] Fix pause build on riscv32 via ppoll wrapper
riscv32 has no SYS_ppoll, only SYS_ppoll_time64, so pause failed to
build. Call linux_syscalls::ppoll, which already picks the right syscall.
Assisted-by: Automated tooling, human reviewed.
---
.../__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt | 3 +--
libc/src/__support/OSUtil/linux/syscall_wrappers/pause.h | 7 ++-----
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 5247a6c71ffce9..313939059e6d12 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1600,11 +1600,10 @@ add_header_library(
HDRS
pause.h
DEPENDS
- libc.include.sys_syscall
+ libc.src.__support.OSUtil.linux.syscall_wrappers.ppoll
libc.src.__support.common
libc.src.__support.error_or
libc.src.__support.macros.config
- libc.src.__support.OSUtil.osutil
)
add_header_library(
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/pause.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/pause.h
index c5dcb01bb86ea8..6f7833ad78a381 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/pause.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/pause.h
@@ -14,18 +14,15 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PAUSE_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_SYSCALL_WRAPPERS_PAUSE_H
-#include "src/__support/OSUtil/linux/syscall.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/ppoll.h"
#include "src/__support/common.h"
#include "src/__support/error_or.h"
#include "src/__support/macros/config.h"
-#include <sys/syscall.h>
namespace LIBC_NAMESPACE_DECL {
namespace linux_syscalls {
-LIBC_INLINE ErrorOr<int> pause() {
- return syscall_checked<int>(SYS_ppoll, nullptr, 0, nullptr, nullptr, 0);
-}
+LIBC_INLINE ErrorOr<int> pause() { return ppoll(nullptr, 0, nullptr, nullptr); }
} // namespace linux_syscalls
} // namespace LIBC_NAMESPACE_DECL
>From 32d23236b98d31f47d42ff9f59fca823ce57c718 Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Wed, 14 Oct 2026 12:40:22 -0300
Subject: [PATCH 2/4] [libc] Prefer SYS_ppoll over SYS_ppoll_time64 in ppoll
wrapper
arm32 defines SYS_ppoll_time64 but has a 32-bit time_t, so the time_t
static_assert failed there. Try SYS_ppoll first and fall back to
SYS_ppoll_time64, which riscv32 needs because it has no SYS_ppoll.
---
.../OSUtil/linux/syscall_wrappers/ppoll.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
index 8ac3a1f070c7d7..48c3ddba0912b3 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
@@ -39,19 +39,19 @@ LIBC_INLINE ErrorOr<int> ppoll(struct pollfd *fds, nfds_t nfds,
// signals. NSIG is the signal count, so NSIG / 8 gives the byte size.
const size_t SIGSETSIZE = NSIG / 8;
-#if defined(SYS_ppoll_time64)
- static_assert(
- sizeof(time_t) == sizeof(int64_t),
- "SYS_ppoll_time64 requires struct timespec with 64-bit members.");
- return syscall_checked<int>(SYS_ppoll_time64, fds, nfds, tmo_p, sigmask,
- SIGSETSIZE);
-#elif defined(SYS_ppoll)
+#if defined(SYS_ppoll)
static_assert(
sizeof(timespec::tv_nsec) == sizeof(long),
"This legacy syscall fallback is only safe on platforms where tv_nsec "
"matches the register size (long). It is unsafe on 32-bit platforms "
"with 64-bit tv_nsec.");
return syscall_checked<int>(SYS_ppoll, fds, nfds, tmo_p, sigmask, SIGSETSIZE);
+#elif defined(SYS_ppoll_time64)
+ static_assert(
+ sizeof(time_t) == sizeof(int64_t),
+ "SYS_ppoll_time64 requires struct timespec with 64-bit members.");
+ return syscall_checked<int>(SYS_ppoll_time64, fds, nfds, tmo_p, sigmask,
+ SIGSETSIZE);
#else
#error "ppoll and ppoll_time64 syscalls not available."
#endif
>From 12d6330a10c734b519a6f6d7168abd7e0e02544c Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Fri, 16 Oct 2026 17:40:50 -0300
Subject: [PATCH 3/4] [libc] Pick ppoll syscall by time_t size
Choosing SYS_ppoll before SYS_ppoll_time64 is unsafe where time_t is 64-bit but
both syscalls exist. Use SYS_ppoll_time64 for a 64-bit time_t and SYS_ppoll
when time_t is as wide as long, and return ENOSYS if neither matches.
---
.../linux/syscall_wrappers/CMakeLists.txt | 1 +
.../OSUtil/linux/syscall_wrappers/ppoll.h | 28 +++++++++----------
2 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
index 313939059e6d12..e6d7961892f985 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/CMakeLists.txt
@@ -1325,6 +1325,7 @@ add_header_library(
HDRS
ppoll.h
DEPENDS
+ libc.hdr.errno_macros
libc.hdr.signal_macros
libc.hdr.types.nfds_t
libc.hdr.types.sigset_t
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
index 48c3ddba0912b3..2892eeb10c3d4d 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
@@ -14,6 +14,7 @@
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PPOLL_H
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_SYSCALL_WRAPPERS_PPOLL_H
+#include "hdr/errno_macros.h"
#include "hdr/signal_macros.h"
#include "hdr/types/nfds_t.h"
#include "hdr/types/sigset_t.h"
@@ -39,22 +40,21 @@ LIBC_INLINE ErrorOr<int> ppoll(struct pollfd *fds, nfds_t nfds,
// signals. NSIG is the signal count, so NSIG / 8 gives the byte size.
const size_t SIGSETSIZE = NSIG / 8;
+ // Pick the syscall whose timespec layout matches ours. SYS_ppoll_time64 takes
+ // 64-bit members. The legacy SYS_ppoll takes two longs, so it is only safe
+ // when time_t is as wide as long.
+#if defined(SYS_ppoll_time64)
+ if constexpr (sizeof(time_t) == sizeof(int64_t))
+ return syscall_checked<int>(SYS_ppoll_time64, fds, nfds, tmo_p, sigmask,
+ SIGSETSIZE);
+#endif
#if defined(SYS_ppoll)
- static_assert(
- sizeof(timespec::tv_nsec) == sizeof(long),
- "This legacy syscall fallback is only safe on platforms where tv_nsec "
- "matches the register size (long). It is unsafe on 32-bit platforms "
- "with 64-bit tv_nsec.");
- return syscall_checked<int>(SYS_ppoll, fds, nfds, tmo_p, sigmask, SIGSETSIZE);
-#elif defined(SYS_ppoll_time64)
- static_assert(
- sizeof(time_t) == sizeof(int64_t),
- "SYS_ppoll_time64 requires struct timespec with 64-bit members.");
- return syscall_checked<int>(SYS_ppoll_time64, fds, nfds, tmo_p, sigmask,
- SIGSETSIZE);
-#else
-#error "ppoll and ppoll_time64 syscalls not available."
+ if constexpr (sizeof(time_t) == sizeof(long))
+ return syscall_checked<int>(SYS_ppoll, fds, nfds, tmo_p, sigmask,
+ SIGSETSIZE);
#endif
+ // No syscall matches our timespec.
+ return Error(ENOSYS);
}
} // namespace linux_syscalls
>From 8369ebdb6779d44c718d6bcb152d91e1ad64964f Mon Sep 17 00:00:00 2001
From: "Mikhail R. Gadelha" <mikhail at igalia.com>
Date: Tue, 17 Nov 2026 08:45:40 -0300
Subject: [PATCH 4/4] [libc] Error if ppoll has no ppoll syscall
Fail to compile when neither SYS_ppoll nor SYS_ppoll_time64 is defined,
like the other syscall wrappers.
---
libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h b/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
index 2892eeb10c3d4d..0c7884f21c1a89 100644
--- a/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
+++ b/libc/src/__support/OSUtil/linux/syscall_wrappers/ppoll.h
@@ -40,6 +40,10 @@ LIBC_INLINE ErrorOr<int> ppoll(struct pollfd *fds, nfds_t nfds,
// signals. NSIG is the signal count, so NSIG / 8 gives the byte size.
const size_t SIGSETSIZE = NSIG / 8;
+#if !defined(SYS_ppoll) && !defined(SYS_ppoll_time64)
+#error "ppoll and ppoll_time64 syscalls not available."
+#endif
+
// Pick the syscall whose timespec layout matches ours. SYS_ppoll_time64 takes
// 64-bit members. The legacy SYS_ppoll takes two longs, so it is only safe
// when time_t is as wide as long.
More information about the libc-commits
mailing list