Build fixes for Mercury, GCC 16 and glibc 2.43
cover Build fixes for Mercury, GCC 16 and glibc 2.43
While bumping Xenomai to 3.3.3 in Buildroot, I hit several build failures. Xenomai forces -Werror for userspace code, so new compiler and libc warnings turn into errors:
- The Mercury core no longer builds at all since the include cleanups in 41de7cc7196f and 7b7ddf4a3658: mmap()/MAP_* and __NR_tkill are undeclared. This affects every Mercury build of v3.3.x.
- GCC 16 warns about variables that are only ever incremented (-Wunused-but-set-variable), in autotune and in the smokey tests.
- glibc 2.43 makes strstr() return a const pointer for a const argument (C23), which breaks sched-tp.
- The alchemy tests miss a couple of includes.
All patches apply to stable/v3.3.x as well, and would be good to have there, especially the first one.
Tested by building v3.3.3 plus this series with Buildroot: Mercury for arm and aarch64 (glibc and uClibc), and Cobalt with the testsuite and the Alchemy, pSOS and VxWorks skins for aarch64, i686 (GCC 15) and x86_64 (GCC 16).
Some testsuite issues remain on Mercury that this series doesn't address, e.g. the alchemy pipe test calling the Cobalt-only rt_pipe_read() and task-11.c missing <stdbool.h>.
Yegor Yefremov (5):
lib: Restore includes needed by the Mercury core utils/autotune: Drop unused sample counter testsuite/smokey/sched-tp: Fix build with C23 strstr() testsuite/smokey/alchemytests: Add missing includes testsuite/smokey: Fix unused variable warnings with GCC 16
lib/boilerplate/setup.c | 1 + lib/copperplate/internal.c | 1 + testsuite/smokey/alchemytests/alchemytests.c | 1 + testsuite/smokey/alchemytests/task-2.c | 1 + testsuite/smokey/psostests/rn-1.c | 7 +++---- testsuite/smokey/psostests/task-2.c | 5 +++-- testsuite/smokey/sched-tp/sched-tp.c | 2 +- testsuite/smokey/vxworkstests/task-2.c | 5 +++-- utils/autotune/autotune.c | 4 +--- 9 files changed, 15 insertions(+), 12 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/5 lib: Restore includes needed by the Mercury core
Commits 41de7cc7196f ("lib/boilerplate: Cleanup includes") and 7b7ddf4a3658 ("lib/copperplate: Cleanup includes") dropped headers that are still needed. With the Cobalt core, they get pulled in indirectly, but building the Mercury core fails:
setup.c: In function '__xenomai_init':
setup.c:606:23: error: implicit declaration of function 'mlockall' [-Wimplicit-function-declaration] setup.c:606:32: error: 'MCL_CURRENT' undeclared (first use in this function) setup.c:606:46: error: 'MCL_FUTURE' undeclared (first use in this function)
internal.c:108:24: error: '__NR_tkill' undeclared (first use in this function)
Include <sys/mman.h> and <sys/syscall.h> again.
--- lib/boilerplate/setup.c | 1 + lib/copperplate/internal.c | 1 + 2 files changed, 2 insertions(+)
lib/boilerplate/setup.c +1 -0
@@ -17,6 +17,7 @@*/ #include <sys/types.h> +#include <sys/mman.h> #include <sched.h> #include <getopt.h> #include <string.h>
lib/copperplate/internal.c +1 -0
@@ -18,6 +18,7 @@#include <sys/types.h> #include <sys/prctl.h> +#include <sys/syscall.h> #include <stdio.h> #include <stdarg.h> #include <pthread.h>
Signature · 1 line
2.34.1
Re: [PATCH 1/5] lib: Restore includes needed by the Mercury core
Quoted 49 lines · Yegor Yefremov
Commits
41de7cc7196f("lib/boilerplate: Cleanup includes") and7b7ddf4a3658("lib/copperplate: Cleanup includes") dropped headers that are still needed. With the Cobalt core, they get pulled in indirectly, but building the Mercury core fails:
setup.c: In function '__xenomai_init':
setup.c:606:23: error: implicit declaration of function 'mlockall' [-Wimplicit-function-declaration] setup.c:606:32: error: 'MCL_CURRENT' undeclared (first use in this function) setup.c:606:46: error: 'MCL_FUTURE' undeclared (first use in this function)internal.c:108:24: error: '
__NR_tkill' undeclared (first use in this function)Include <
sys/mman.h> and <sys/syscall.h> again.Fixes 41de7cc7196f ("lib/boilerplate: Cleanup includes")Fixes 7b7ddf4a3658 ("lib/copperplate: Cleanup includes")Assisted-by Claude:claude-opus-5-5Signed-off-by Yegor Yefremov <[email protected]>--- lib/boilerplate/setup.c | 1 + lib/copperplate/internal.c | 1 + 2 files changed, 2 insertions(+)lib/boilerplate/setup.c +1
-0@@ -17,6 +17,7 @@*/ #include <sys/types.h> +#include <sys/mman.h> #include <sched.h> #include <getopt.h> #include <string.h> lib/copperplate/internal.c +1
-0@@ -18,6 +18,7 @@#include <sys/types.h> #include <sys/prctl.h> +#include <sys/syscall.h> #include <stdio.h> #include <stdarg.h> #include <pthread.h> Signature · 1 line
2.34.1
Could you please check if that mercury staff is covered by the wip/flo/refactor-includes branch (which is not complete yet and will most likely look completely different for the next revision)?
If those includes are needed for a special build configuration they should only be included for exactly that configuration.
Specific for this patch: If those includes are only needed for a specific build variant: Guard them with the correct #if/#ifdef as needed.
Florian
PATCH 2/5 utils/autotune: Drop unused sample counter
In reply to Yegor YefremovThe n counter in sampler_thread() is only ever written. GCC 16 now warns about variables that are only incremented, which breaks the build due to -Werror:
autotune.c: In function 'sampler_thread':
autotune.c:95:34: error: variable 'n' set but not used [-Werror=unused-but-set-variable=]
Remove it.
--- utils/autotune/autotune.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
utils/autotune/autotune.c +1 -3
@@ -92,7 +92,7 @@ static const struct option base_options[] = {static void *sampler_thread (void *arg) { -int fd = (long )arg, ret, n =0 ; +int fd = (long )arg, ret;__u64 timestamp =0 ;struct timespec now;
@@ -102,9 +102,7 @@ static void *sampler_thread(void *arg)if (errno !=EPIPE )error (1 , errno,"pulse failed" ); timestamp =0 ;/* Next tuning period. */ - n =0 ; }else { - n++;clock_gettime (CLOCK_MONOTONIC , &now); timestamp = (__u64 )now.tv_sec *1000000000 + now.tv_nsec; }
Signature · 1 line
2.34.1
Re: [PATCH 2/5] utils/autotune: Drop unused sample counter
Quoted 11 lines · Yegor Yefremov
The n counter in
sampler_thread()is only ever written. GCC 16 now warns about variables that are only incremented, which breaks the build due to -Werror:
autotune.c: In function 'sampler_thread':
autotune.c:95:34: error: variable 'n' set but not used [-Werror=unused-but-set-variable=]Remove it.
Assisted-by Claude:claude-opus-5-5Signed-off-by Yegor Yefremov <[email protected]>
Already done. See commit 2bc267a49541fea39eb230e9efd0820c87f8e990
This series is not targeting the next branch.
Florian
PATCH 3/5 testsuite/smokey/sched-tp: Fix build with C23 strstr()
In reply to Yegor YefremovSince glibc 2.43, strstr() returns a const pointer when passed a const string in C23 mode, which is the default since GCC 15. As ref_schedule is const, assigning the result to a non-const pointer fails due to -Werror:
sched-tp.c:233:11: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
The result is only compared, so make s a const pointer.
--- testsuite/smokey/sched-tp/sched-tp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
testsuite/smokey/sched-tp/sched-tp.c +1 -1
@@ -123,7 +123,7 @@ static int run_sched_tp(struct smokey_test *t, int argc, char *const argv[])union sched_config *p;int ret, n, policies;size_t len; -char *s; +const char *s; ret =cobalt_corectl (_CC_COBALT_GET_POLICIES, &policies,sizeof (policies));if (ret || (policies & _CC_COBALT_SCHED_TP) ==0 )
Signature · 1 line
2.34.1
Re: [PATCH 3/5] testsuite/smokey/sched-tp: Fix build with C23 strstr()
Quoted 7 lines · Yegor Yefremov
Since glibc 2.43,
strstr()returns a const pointer when passed a const string in C23 mode, which is the default since GCC 15. Asref_scheduleis const, assigning the result to a non-const pointer fails due to -Werror:sched-tp.c:233:11: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
Quoted 8 lines
The result is only compared, so make s a const pointer.
Assisted-by Claude:claude-opus-5-5Signed-off-by Yegor Yefremov <[email protected]>--- testsuite/smokey/sched-tp/sched-tp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Already done. See commit 8109051556b438cd4c280e75c2a45ae3b43d7f7e
PATCH 4/5 testsuite/smokey/alchemytests: Add missing includes
In reply to Yegor YefremovWith the Mercury core, the alchemy tests fail to build, as some declarations are only pulled in indirectly by the Cobalt headers:
alchemytests.c:43:17: error: implicit declaration of function 'fprintf' [-Wimplicit-function-declaration] alchemytests.c:43:25: error: 'stderr' undeclared (first use in this function) task-2.c:34:17: error: implicit declaration of function 'compiler_barrier' [-Wimplicit-function-declaration]
Include <stdio.h> and <boilerplate/atomic.h>.
--- testsuite/smokey/alchemytests/alchemytests.c | 1 + testsuite/smokey/alchemytests/task-2.c | 1 + 2 files changed, 2 insertions(+)
testsuite/smokey/alchemytests/alchemytests.c +1 -0
@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> #include <string.h> #include <stdlib.h> #include <smokey/smokey.h>
testsuite/smokey/alchemytests/task-2.c +1 -0
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <stdio.h> #include <stdlib.h> +#include <boilerplate/atomic.h> #include <copperplate/traceobj.h> #include <alchemy/task.h> #include <alchemy/sem.h>
Signature · 1 line
2.34.1
Re: [PATCH 4/5] testsuite/smokey/alchemytests: Add missing includes
Quoted 42 lines · Yegor Yefremov
With the Mercury core, the alchemy tests fail to build, as some declarations are only pulled in indirectly by the Cobalt headers:
alchemytests.c:43:17: error: implicit declaration of function 'fprintf' [-Wimplicit-function-declaration] alchemytests.c:43:25: error: 'stderr' undeclared (first use in this function) task-2.c:34:17: error: implicit declaration of function '
compiler_barrier' [-Wimplicit-function-declaration]Include <
stdio.h> and <boilerplate/atomic.h>.Fixes 61fc9ff4b721 ("alchemytests: Set cpu-affinity by env var")Fixes 10d898c40e26 ("alchemytests: Fix task-2")Assisted-by Claude:claude-opus-5-5Signed-off-by Yegor Yefremov <[email protected]>--- testsuite/smokey/alchemytests/alchemytests.c | 1 + testsuite/smokey/alchemytests/task-2.c | 1 + 2 files changed, 2 insertions(+)testsuite/smokey/alchemytests/alchemytests.c +1
-0@@ -1,4 +1,5 @@// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> #include <string.h> #include <stdlib.h> #include <smokey/smokey.h> testsuite/smokey/alchemytests/task-2.c +1
-0@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <stdio.h> #include <stdlib.h> +#include <boilerplate/atomic.h> #include <copperplate/traceobj.h> #include <alchemy/task.h> #include <alchemy/sem.h> Signature · 1 line
2.34.1
That one might be still relevant. But: I'm wondering that you did not run into another build issue:
There is a include-refactoring branch (not up to date right now, will try to refresh it within the next days...) located at
wip/flo/refactor-includes
That branch holds the following commit
https://gitlab.com/Xenomai/xenomai3/xenomai/-/commit/454ae865105807f2fcd49901c618f224f3dcab34
I'm quite sure that this is also required for !cobalt.
Re: [PATCH 4/5] testsuite/smokey/alchemytests: Add missing includes
Hi Florian,
Quoted 2 lines · Florian Bezdeka
That one might be still relevant. But: I'm wondering that you did not run into another build issue:
[...]
Quoted 3 lines
https://gitlab.com/Xenomai/xenomai3/xenomai/-/commit/454ae865105807f2fcd49901c618f224f3dcab34
I'm quite sure that this is also required for !cobalt.
I did run into it, it's the rt_pipe_read() link error I mentioned in the cover letter as not addressed. With 454ae865 applied on top of next, the Mercury testsuite builds fine here. As the include refactoring will take a while, could that commit go to next (and stable/v3.3.x) on its own?
Regarding your comment on patch 1: the wip branch includes both headers, so it covers Mercury. Until it lands, I've guarded them with CONFIG_XENO_MERCURY in v2.
Thanks,
Yegor
PATCH 5/5 testsuite/smokey: Fix unused variable warnings with GCC 16
In reply to Yegor YefremovGCC 16 now warns about variables that are only incremented, which breaks the build of the pSOS and VxWorks tests due to -Werror:
task-2.c:19:42: error: variable 'count' set but not used [-Werror=unused-but-set-variable=] rn-1.c:15:22: error: variable 'alloc_size' set but not used [-Werror=unused-but-set-variable=] rn-1.c:16:18: error: variable 'n' set but not used [-Werror=unused-but-set-variable=]
In task-2, count only makes the background task busy-wait. Making it volatile is not enough, as GCC 16 still warns about it, so drop it and use compiler_barrier() in the loop instead, as the Alchemy task-2 test does. In rn-1, alloc_size and n are not needed, so drop them.
--- testsuite/smokey/psostests/rn-1.c | 7 +++---- testsuite/smokey/psostests/task-2.c | 5 +++-- testsuite/smokey/vxworkstests/task-2.c | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-)
testsuite/smokey/psostests/rn-1.c +3 -4
@@ -12,15 +12,15 @@ static u_long tid, rnid;static void alloc_task (u_long a1,u_long a2,u_long a3,u_long a4) { -u_long size, alloc_size =0 ; -int ret, n; +u_long size; +int ret;void *buf;traceobj_enter (&trobj);srandom (0x11223344 ); -for (n =0 ;; n++) { +for (;;) { size = (random () % (sizeof (rn_mem) /8 )) +4 ; ret =rn_getseg (rnid, size,RN_NOWAIT ,0 , &buf);if (ret) {
@@ -28,7 +28,6 @@ static void alloc_task(u_long a1, u_long a2, u_long a3, u_long a4)break ; }memset (buf,0xaa , size); - alloc_size += size; }traceobj_exit (&trobj);
testsuite/smokey/psostests/task-2.c +3 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <stdio.h> #include <stdlib.h> +#include <boilerplate/atomic.h> #include <copperplate/traceobj.h> #include <psos/psos.h>
@@ -16,7 +17,7 @@ static u_long sem_id;static void backgroundTask (u_long a1,u_long a2,u_long a3,u_long a4) { -unsigned int safety =100000000 , count =0 ; +unsigned int safety =100000000 ;int ret;traceobj_enter (&trobj);
@@ -29,7 +30,7 @@ static void backgroundTask(u_long a1, u_long a2, u_long a3, u_long a4)traceobj_mark (&trobj,2 );while (--safety >0 ) - count++; +compiler_barrier ();traceobj_mark (&trobj,3 );
testsuite/smokey/vxworkstests/task-2.c +3 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0 #include <stdlib.h> #include <unistd.h> +#include <boilerplate/atomic.h> #include <copperplate/traceobj.h> #include <vxworks/errnoLib.h> #include <vxworks/semLib.h>
@@ -23,7 +24,7 @@ static SEM_ID sem_id, fdone_sem_id;static void backgroundTask (long arg, ...) { -unsigned int safety =100000000 , count =0 ; +unsigned int safety =100000000 ;int ret;traceobj_enter (&trobj);
@@ -36,7 +37,7 @@ static void backgroundTask(long arg, ...)traceobj_mark (&trobj,2 );while (--safety >0 ) - count++; +compiler_barrier ();/* * Enter infinite pause so that any pending cancellation is
Signature · 1 line
2.34.1
Re: [PATCH 5/5] testsuite/smokey: Fix unused variable warnings with GCC 16
Quoted 12 lines · Yegor Yefremov
GCC 16 now warns about variables that are only incremented, which breaks the build of the pSOS and VxWorks tests due to -Werror:
task-2.c:19:42: error: variable 'count' set but not used [-Werror=unused-but-set-variable=] rn-1.c:15:22: error: variable '
alloc_size' set but not used [-Werror=unused-but-set-variable=] rn-1.c:16:18: error: variable 'n' set but not used [-Werror=unused-but-set-variable=]In task-2, count only makes the background task busy-wait. Making it volatile is not enough, as GCC 16 still warns about it, so drop it and use
compiler_barrier()in the loop instead, as the Alchemy task-2 test does. In rn-1,alloc_sizeand n are not needed, so drop them.
Quoted 8 lines
Assisted-by Claude:claude-opus-5-5Signed-off-by Yegor Yefremov <[email protected]>--- testsuite/smokey/psostests/rn-1.c | 7 +++---- testsuite/smokey/psostests/task-2.c | 5 +++-- testsuite/smokey/vxworkstests/task-2.c | 5 +++-- 3 files changed, 9 insertions(+), 8 deletions(-)
Already done. See commit 8e4c4e836f45ddf46a090abbeb76e0152a5dec93
Quoted 13 lines · Yegor Yefremov
While bumping Xenomai to 3.3.3 in Buildroot, I hit several build failures. Xenomai forces -Werror for userspace code, so new compiler and libc warnings turn into errors:
- The Mercury core no longer builds at all since the include cleanups in
41de7cc7196fand7b7ddf4a3658: mmap()/MAP_* and__NR_tkillare undeclared. This affects every Mercury build of v3.3.x.
- GCC 16 warns about variables that are only ever incremented (-Wunused-but-set-variable), in autotune and in the smokey tests.
- glibc 2.43 makesstrstr()return a const pointer for a const argument (C23), which breaks sched-tp.
- The alchemy tests miss a couple of includes.
Quoted 2 lines
All patches apply to stable/v3.3.x as well, and would be good to have there, especially the first one.
Means you validated the next branch with your fixes?
Quoted 10 lines
Tested by building v3.3.3 plus this series with Buildroot: Mercury for arm and aarch64 (glibc and uClibc), and Cobalt with the testsuite and the Alchemy, pSOS and VxWorks skins for aarch64, i686 (GCC 15) and
x86_64(GCC 16).Some testsuite issues remain on Mercury that this series doesn't address, e.g. the alchemy pipe test calling the Cobalt-only
rt_pipe_read()andtask-11.cmissing <stdbool.h>.
Fixing all these is primarily driven by your desire to fix the build recipes, or do you also have a use case for Mercury?
Thanks a lot,
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Hi Jan,
Quoted 1 line · Jan Kiszka
Means you validated the next branch with your fixes?
Not for v1, sorry: I only tested on top of v3.3.3 and missed the next branch. Patches 2, 3 and 5 duplicate Florian's GCC 16 fixes already in next, so please drop them.
I have now built next with Buildroot. The Mercury core and its testsuite still need patches 1 and 4, plus two more missing includes, so I'll send a v2 based on next.
Quoted 2 lines
Fixing all these is primarily driven by your desire to fix the build recipes, or do you also have a use case for Mercury?
Mainly the build recipe: Mercury is the default core in Buildroot, so it's what the Buildroot autobuilders and most users without a Dovetail kernel build, and with v3.3.x it doesn't build at all.
Thanks,
Yegor