Cobalt build fixes for uClibc-ng
v2 cover Cobalt build fixes for uClibc-ng
Cobalt has not built with uClibc-ng since v3.1.1. These patches fix the build, plus the clock_gettime() vDSO selection, which picks the 32-bit call for uClibc-ng and musl with 64-bit time_t. They complement Jan's mmap() off_t fix for uClibc-ng >= 1.0.58, now in next.
Tested with Buildroot's test-pkg on next plus the series, building Cobalt with the testsuite, RTCAN, Analogy and the pSOS and VxWorks skins:
- armv5 uClibc-ng 1.0.59 (time64), GCC 15
- armv7 glibc 2.44, GCC 16
- aarch64 glibc 2.24, GCC 6
Without the series, the uClibc-ng build fails on __OPEN_NEEDS_MODE; the ADJ_SETOFFSET error only showed up once that was fixed.
musl (as asked by Jan): I built Cobalt with configure and "make -k" using the Bootlin armv7 and i686 musl 1.2.6 toolchains (GCC 15), without Buildroot:
- Patches 1 and 3 remove the __OPEN_NEEDS_MODE and ADJ_SETOFFSET errors with musl as well.
- musl also defines __USE_TIME_BITS64 (in bits/alltypes.h) but not __TIMESIZE, so patch 2 applies just like for uClibc-ng: the vcall changes from __vdso_clock_gettime to __vdso_clock_gettime64. The time syscalls already pick the *64 variants via __USE_TIME_BITS64. This corrects my v1 cover letter, which claimed musl defines neither.
Cobalt still doesn't build with musl after this series. The remaining errors are the same with and without it:
- <error.h> (GNU error()) is missing, used by lib/cobalt/parse_vdso.c, the utils and the testsuite
- off64_t and open64() are gone since musl 1.2.4 (include/cobalt/ sys/mman.h, lib/cobalt/mmap.c, umm.c, wrappers.c)
- PTHREAD_MUTEX_ROBUST_NP (lib/cobalt/mutex.c, lib/vxworks/semLib.c) and PTHREAD_{RECURSIVE,ERRORCHECK}_MUTEX_INITIALIZER_NP (smokey posix-mutex)
- basename() without <libgen.h> in lib/boilerplate/setup.c
- __STRING in include/copperplate/traceobj.h
- the static pthread_mutexattr_[gs]etprioceiling() fallbacks in include/boilerplate/libc.h clash with musl's declarations
Also, musl redirects clock_gettime() and friends to __clock_gettime64 etc., just like glibc with _TIME_BITS=64. But configure only enables cobalt-glibc-time64.wrappers for glibc >= 2.34, so with symbol wrapping these calls would bypass libcobalt on 32-bit musl.
I can look into these separately if musl support is wanted.
Changes v1 -> v2:
- Dropped the getauxval() fallback for uClibc-ng < 1.0.43 (Jan).
- Checked the series with musl and mentioned it in the commit messages and comments (Jan). No functional changes.
Yegor Yefremov (3):
lib/cobalt: Don't rely on glibc's __OPEN_NEEDS_MODE lib/cobalt: Select the time64 vDSO call without __TIMESIZE testsuite/smokey/y2038: Define ADJ_SETOFFSET if missing
lib/cobalt/arch/arm/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/arch/arm64/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/arch/x86/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/rtdm.c | 14 ++++++++++---- testsuite/smokey/y2038/syscall-tests.c | 5 +++++ 5 files changed, 36 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/3 lib/cobalt: Don't rely on glibc's __OPEN_NEEDS_MODE
__OPEN_NEEDS_MODE() is an internal helper of glibc's <fcntl.h>, so libcobalt fails to build with other C libraries such as uClibc-ng and musl:
rtdm.c:94:13: error: implicit declaration of function '__OPEN_NEEDS_MODE'
Factor out the check open() and open64() already do into a local helper and use it in __open_2() and __open64_2() as well.
--- lib/cobalt/rtdm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
lib/cobalt/rtdm.c +10 -4
@@ -36,6 +36,12 @@#define O_TMPFILE (020000000 | 0200000)#endif +/* like __OPEN_NEEDS_MODE(), which only glibc provides */ +static inline int open_needs_mode (int oflag) +{ +return (oflag &O_CREAT ) || (oflag &O_TMPFILE ) ==O_TMPFILE ; +} +static int do_open (const char *path,int oflag,mode_t mode) {int fd, oldtype;
@@ -62,7 +68,7 @@ COBALT_IMPL(int, open, (const char *path, int oflag, ...))mode_t mode =0 ;va_list ap; -if ((oflag &O_CREAT ) || (oflag &O_TMPFILE ) ==O_TMPFILE ) { +if (open_needs_mode (oflag)) {va_start (ap, oflag); mode =va_arg (ap, int);va_end (ap);
@@ -76,7 +82,7 @@ COBALT_IMPL(int, open64, (const char *path, int oflag, ...))mode_t mode =0 ;va_list ap; -if ((oflag &O_CREAT ) || (oflag &O_TMPFILE ) ==O_TMPFILE ) { +if (open_needs_mode (oflag)) {va_start (ap, oflag); mode =va_arg (ap, int);va_end (ap);
@@ -91,7 +97,7 @@ COBALT_IMPL(int, __open_2, (const char *path, int oflag))* parameter to the functionality of open(). It may be used when the macro * _FORTIFY_SOURCE is defined when compiling the application code. */ -if (__OPEN_NEEDS_MODE (oflag)) { +if (open_needs_mode (oflag)) {const char *msg ="invalid open call: O_CREAT or O_TMPFILE without mode\n" ;ssize_t n =__STD (write (STDERR_FILENO , msg,strlen (msg)));
@@ -105,7 +111,7 @@ COBALT_IMPL(int, __open_2, (const char *path, int oflag)) COBALT_IMPL(int, __open64_2, (const char *path, int oflag)) {/* just like __open_2() and open64() */ -if (__OPEN_NEEDS_MODE (oflag)) { +if (open_needs_mode (oflag)) {const char *msg ="invalid open64 call: O_CREAT or O_TMPFILE without mode\n" ;ssize_t n =__STD (write (STDERR_FILENO , msg,strlen (msg)));
Signature · 1 line
2.34.1
PATCH v2 2/3 lib/cobalt: Select the time64 vDSO call without __TIMESIZE
In reply to Yegor YefremovThe clock_gettime() vcall is chosen by checking for __TIMESIZE == 32, which only glibc defines. uClibc-ng built with time64 support (__UCLIBC_USE_TIME64__, as e.g. Buildroot builds it) and musl >= 1.2 define __USE_TIME_BITS64 and use a 64-bit time_t on 32-bit targets, but have no __TIMESIZE. libcobalt then picks __vdso_clock_gettime, which fills in a 32-bit struct timespec: the seconds and nanoseconds both end up in the 64-bit tv_sec of the caller, and tv_nsec is left untouched.
Fall back to the size of long if __TIMESIZE is not defined. Nothing changes for glibc, and on 64-bit targets.
--- lib/cobalt/arch/arm/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/arch/arm64/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/arch/x86/include/asm/xenomai/time.h | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-)
lib/cobalt/arch/arm/include/asm/xenomai/time.h +7 -1
@@ -12,7 +12,13 @@#define COBALT_VDSO_VERSION "LINUX_2.6" -#if __USE_TIME_BITS64 && __TIMESIZE ==32 +/* +* Use the time64 vcall whenever time_t is 64-bit on a 32-bit target. Not +* all C libraries define __TIMESIZE (e.g. uClibc-ng and musl), so fall back +* to the word size. +*/ +#if __USE_TIME_BITS64 && \ + (__TIMESIZE ==32 || (!defined(__TIMESIZE) && __SIZEOF_LONG__ ==4 ))#define COBALT_VDSO_GETTIME "__vdso_clock_gettime64"#else #define COBALT_VDSO_GETTIME "__vdso_clock_gettime"
lib/cobalt/arch/arm64/include/asm/xenomai/time.h +7 -1
@@ -12,7 +12,13 @@#define COBALT_VDSO_VERSION "LINUX_2.6.39" -#if __USE_TIME_BITS64 && __TIMESIZE ==32 +/* +* Use the time64 vcall whenever time_t is 64-bit on a 32-bit target. Not +* all C libraries define __TIMESIZE (e.g. uClibc-ng and musl), so fall back +* to the word size. +*/ +#if __USE_TIME_BITS64 && \ + (__TIMESIZE ==32 || (!defined(__TIMESIZE) && __SIZEOF_LONG__ ==4 ))#define COBALT_VDSO_GETTIME "__vdso_clock_gettime64"#else #define COBALT_VDSO_GETTIME "__kernel_clock_gettime"
lib/cobalt/arch/x86/include/asm/xenomai/time.h +7 -1
@@ -12,7 +12,13 @@#define COBALT_VDSO_VERSION "LINUX_2.6" -#if __USE_TIME_BITS64 && __TIMESIZE ==32 +/* +* Use the time64 vcall whenever time_t is 64-bit on a 32-bit target. Not +* all C libraries define __TIMESIZE (e.g. uClibc-ng and musl), so fall back +* to the word size. +*/ +#if __USE_TIME_BITS64 && \ + (__TIMESIZE ==32 || (!defined(__TIMESIZE) && __SIZEOF_LONG__ ==4 ))#define COBALT_VDSO_GETTIME "__vdso_clock_gettime64"#else #define COBALT_VDSO_GETTIME "__vdso_clock_gettime"
Signature · 1 line
2.34.1
Re: [PATCH v2 2/3] lib/cobalt: Select the time64 vDSO call without __TIMESIZE
Quoted 25 lines · Yegor Yefremov
The
clock_gettime()vcall is chosen by checking for__TIMESIZE== 32, which only glibc defines. uClibc-ng built with time64 support (__UCLIBC_USE_TIME64__, as e.g. Buildroot builds it) and musl >= 1.2 define__USE_TIME_BITS64and use a 64-bittime_ton 32-bit targets, but have no__TIMESIZE. libcobalt then picks__vdso_clock_gettime, which fills in a 32-bit struct timespec: the seconds and nanoseconds both end up in the 64-bittv_secof the caller, andtv_nsecis left untouched.Fall back to the size of long if
__TIMESIZEis not defined. Nothing changes for glibc, and on 64-bit targets.Fixes fb112c2fdc69 ("y2038: lib/cobalt: Switch vdso to gettime64")Assisted-by Claude:claude-opus-5-5Signed-off-by Yegor Yefremov <[email protected]>--- lib/cobalt/arch/arm/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/arch/arm64/include/asm/xenomai/time.h | 8 +++++++- lib/cobalt/arch/x86/include/asm/xenomai/time.h | 8 +++++++- 3 files changed, 21 insertions(+), 3 deletions(-)lib/cobalt/arch/arm/include/asm/xenomai/time.h +0
-0
lib/cobalt/arch/arm/include/asm/xenomai/time.h line 19
Quoted 9 lines
lib/cobalt/arch/arm/include/asm/xenomai/time.h +5
-1@@ -12,7 +12,13 @@#define COBALT_VDSO_VERSION "LINUX_2.6" -#if __USE_TIME_BITS64 && __TIMESIZE ==32 +/* +* Use the time64 vcall whenever time_t is 64-bit on a 32-bit target. Not +* all C libraries define __TIMESIZE (e.g. uClibc-ng and musl), so fall back +* to the word size. +*/
Grml... From a userspace perspective we could simply remove the __TIMESIZE check. That would change the routing for systems with native 64 bit time_t, which would be ok. But: The kernel does not export the "gettime64" variant on those systems.
Next idea: Remove COBALT_VDSO_GETTIME and do the detection based on sizeof(time_t). Sadly arm64 has a different name of the native vdso endpoint, so that we need some kind of arch specific "override", which is the reason why COBALT_VDSO_GETTIME exists... Obviously not an option.
Not sure if we should really rely on __SIZEOF_LONG__ here.
Anyhow, we have more usages of __TIMESIZE in the code base. I'm sure this patch is incomplete and further issues will come up while testing.
Quoted 45 lines
lib/cobalt/arch/arm/include/asm/xenomai/time.h +2
-0+#if __USE_TIME_BITS64 && \ + (__TIMESIZE ==32 || (!defined(__TIMESIZE) && __SIZEOF_LONG__ ==4 ))#define COBALT_VDSO_GETTIME "__vdso_clock_gettime64"#else #define COBALT_VDSO_GETTIME "__vdso_clock_gettime"lib/cobalt/arch/arm64/include/asm/xenomai/time.h +7
-1@@ -12,7 +12,13 @@#define COBALT_VDSO_VERSION "LINUX_2.6.39" -#if __USE_TIME_BITS64 && __TIMESIZE ==32 +/* +* Use the time64 vcall whenever time_t is 64-bit on a 32-bit target. Not +* all C libraries define __TIMESIZE (e.g. uClibc-ng and musl), so fall back +* to the word size. +*/ +#if __USE_TIME_BITS64 && \ + (__TIMESIZE ==32 || (!defined(__TIMESIZE) && __SIZEOF_LONG__ ==4 ))#define COBALT_VDSO_GETTIME "__vdso_clock_gettime64"#else #define COBALT_VDSO_GETTIME "__kernel_clock_gettime"lib/cobalt/arch/x86/include/asm/xenomai/time.h +7
-1@@ -12,7 +12,13 @@#define COBALT_VDSO_VERSION "LINUX_2.6" -#if __USE_TIME_BITS64 && __TIMESIZE ==32 +/* +* Use the time64 vcall whenever time_t is 64-bit on a 32-bit target. Not +* all C libraries define __TIMESIZE (e.g. uClibc-ng and musl), so fall back +* to the word size. +*/ +#if __USE_TIME_BITS64 && \ + (__TIMESIZE ==32 || (!defined(__TIMESIZE) && __SIZEOF_LONG__ ==4 ))#define COBALT_VDSO_GETTIME "__vdso_clock_gettime64"#else #define COBALT_VDSO_GETTIME "__vdso_clock_gettime"Signature · 1 line
2.34.1
Re: [PATCH v2 2/3] lib/cobalt: Select the time64 vDSO call without __TIMESIZE
Hi Florian,
Quoted 4 lines · Florian Bezdeka
Not sure if we should really rely on
__SIZEOF_LONG__here.Anyhow, we have more usages of
__TIMESIZEin the code base. I'm sure this patch is incomplete and further issues will come up while testing.
You're right, I went through the other users. They fall into two groups:
1. glibc symbol redirection: include/cobalt/wrappers.h, include/cobalt/pthread.h and wrappers_time64.c:686. These are about glibc providing both the 32-bit and the *64 symbols. uClibc-ng and musl only have the plain names, which are already 64-bit there, so not redirecting is correct for them and the glibc-only check is fine.
2. Kernel ABI: the vDSO selection, the select() wrapper (wrappers_time64.c:771) and clocktest.c:89. On 32-bit uClibc-ng or musl with 64-bit time_t these are all wrong: the clocktest calls SYS_clock_gettime with a 64-bit timespec, and select() passes a 64-bit timeval to sc_cobalt_select. The time64 branch of select() also falls back to __select64, which only glibc has.
So v3 would add one helper for group 2 and use it at all of these places, with the select() fallback picking __select64 only for glibc. The syscall selection in wrappers_time64.c (XN_USE_TIME64_SYSCALL) already works this way, as it checks __USE_TIME_BITS64 without __TIMESIZE.
As for __SIZEOF_LONG__: I found no libc-independent alternative, as musl only defines __WORDSIZE in <sys/reg.h> and <sys/user.h>. The case where it gives the wrong answer is x32, where long is 32-bit but the time syscalls are 64-bit. I would exclude that explicitly:
#if defined(__TIMESIZE) # if __USE_TIME_BITS64 && __TIMESIZE == 32 # define XN_TIME64_ON_32BIT # endif #elif __USE_TIME_BITS64 && __SIZEOF_LONG__ == 4 && !defined(__x86_64__) /* e.g. uClibc-ng, musl; __x86_64__ excludes x32 */ # define XN_TIME64_ON_32BIT #endif
Does that work for you? If you'd rather have something else, e.g. a configure check, I can do that instead.
Regarding musl: I confirm the build is broken there independently of this (error.h, off64_t/open64, the *_NP mutex initializers, ...; see the v2 cover letter), so I'd keep that separate.
Best regards,
Yegor
Re: [PATCH v2 2/3] lib/cobalt: Select the time64 vDSO call without __TIMESIZE
Quoted 31 lines · Yegor Yefremov
Hi Florian,
Quoted 4 lines · Florian Bezdeka
Not sure if we should really rely on
__SIZEOF_LONG__here.Anyhow, we have more usages of
__TIMESIZEin the code base. I'm sure this patch is incomplete and further issues will come up while testing.You're right, I went through the other users. They fall into two groups:
1. glibc symbol redirection:
include/cobalt/wrappers.h,include/cobalt/pthread.hand wrappers_time64.c:686. These are about glibc providing both the 32-bit and the *64 symbols. uClibc-ng and musl only have the plain names, which are already 64-bit there, so not redirecting is correct for them and the glibc-only check is fine.2. Kernel ABI: the vDSO selection, the
select()wrapper (wrappers_time64.c:771) and clocktest.c:89. On 32-bit uClibc-ng or musl with 64-bittime_tthese are all wrong: the clocktest callsSYS_clock_gettimewith a 64-bit timespec, andselect()passes a 64-bit timeval tosc_cobalt_select. The time64 branch ofselect()also falls back to__select64, which only glibc has.So v3 would add one helper for group 2 and use it at all of these places, with the
select()fallback picking__select64only for glibc. The syscall selection inwrappers_time64.c(XN_USE_TIME64_SYSCALL) already works this way, as it checks__USE_TIME_BITS64without__TIMESIZE.
Quoted 3 lines
As for
__SIZEOF_LONG__: I found no libc-independent alternative, as musl only defines__WORDSIZEin <sys/reg.h> and <sys/user.h>. The case where it gives the wrong answer is x32, where long is 32-bit but the
x32 is dead. And Xenomai dropped in 2021 (3.2 series). So it is not worth bothering about it explicitly, only if there are other, vivid reasons.
Quoted 11 lines
time syscalls are 64-bit. I would exclude that explicitly:
#if defined(__TIMESIZE) # if __USE_TIME_BITS64 && __TIMESIZE == 32 # define XN_TIME64_ON_32BIT # endif #elif __USE_TIME_BITS64 && __SIZEOF_LONG__ == 4 && !defined(__x86_64__) /* e.g. uClibc-ng, musl; __x86_64__ excludes x32 */ # define XN_TIME64_ON_32BIT #endif
Quoted 7 lines
Does that work for you? If you'd rather have something else, e.g. a configure check, I can do that instead.
Regarding musl: I confirm the build is broken there independently of this (
error.h, off64_t/open64, the*_NPmutex initializers, ...; see the v2 cover letter), so I'd keep that separate.
General remark: This reads a lot to me like coming as-is from an AI tool. Those are often beneficial to use for supporting patch development and specifically local review, but I'd like us to avoid pasting replies directly without marking what came from where.
Thanks,
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
PATCH v2 3/3 testsuite/smokey/y2038: Define ADJ_SETOFFSET if missing
In reply to Yegor YefremovThe <sys/timex.h> of uClibc-ng and musl lacks ADJ_SETOFFSET, so the y2038 test fails to build:
syscall-tests.c:412:22: error: 'ADJ_SETOFFSET' undeclared (first use in this function)
Fall back to the value from the kernel UAPI, as the test already does for the time64 data types.
--- testsuite/smokey/y2038/syscall-tests.c | 5 +++++ 1 file changed, 5 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +5 -0
@@ -17,6 +17,11 @@#include <sched.h> #include <rtdm/ipc.h> +/* not provided by all C libraries, e.g. uClibc-ng and musl */ +#ifndef ADJ_SETOFFSET +#define ADJ_SETOFFSET 0x0100 +#endif +smokey_test_plugin (y2038,SMOKEY_NOARGS ,"Validate correct y2038 support" );/*
Signature · 1 line
2.34.1