tools/nolibc: assorted fixes and small updates
Subsystems (2)
Willy Tarreau
maintainerv2 cover tools/nolibc: assorted fixes and small updates
Trying to port a program to nolibc triggered a few trivial errors that are worth being addressed:
- inttypes.h is missing, while being generally recommended over stdint.h for being more portable. Here we add it, which simply includes stdint.h.
- sys/select.h is supposed to be where struct fd_set and FD_CLR() etc are defined. Till now it was still in types.h. Let's create the file and move these definitions there.
- memchr() was still missing, thus a trivial one was added.
Finally the help message from "make help" reported an inaccurate installation path, omitting the dependency on $OUTPUT. This was fixed as well.
---
v2:
- rebase this old changeset onto latest updates from Thomas
- moved select() definition do sys/select.h as well and include nolibc.h to avoid having just a dummy file like in v1
Willy Tarreau (4):
tools/nolibc: fix misleading help message regarding installation path tools/nolibc: add the more portable inttypes.h tools/nolibc: add missing memchr() to string.h tools/nolibc: provide the portable sys/select.h
tools/include/nolibc/Makefile | 4 +- tools/include/nolibc/inttypes.h | 8 ++ tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/string.h | 15 +++ tools/include/nolibc/sys.h | 45 -------- tools/include/nolibc/sys/select.h | 103 +++++++++++++++++++ tools/include/nolibc/types.h | 47 --------- tools/testing/selftests/nolibc/nolibc-test.c | 2 + 8 files changed, 132 insertions(+), 93 deletions(-) create mode 100644 tools/include/nolibc/inttypes.h create mode 100644 tools/include/nolibc/sys/select.h
Signature · 1 line
2.17.5
Willy Tarreau
maintainerPATCH v2 1/4 tools/nolibc: fix misleading help message regarding installation path
The help message says the headers are going to be installed into tools/include/nolibc but this is only the default if $OUTPUT is not set, so better clarify this (the current value of $OUTPUT is already shown).
--- tools/include/nolibc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/nolibc/Makefile +1 -1
@@ -79,7 +79,7 @@ help: @echo "Supported targets under nolibc:" @echo " all call \"headers\"" @echo " clean clean the sysroot" - @echo " headers prepare a sysroot in tools/include/nolibc/sysroot" + @echo " headers prepare a sysroot in \$${OUTPUT}sysroot" @echo " headers_standalone like \"headers\", and also install kernel headers" @echo " help this help" @echo ""
Signature · 1 line
2.17.5
Re: [PATCH v2 1/4] tools/nolibc: fix misleading help message regarding installation path
Quoted 5 lines · Willy Tarreau
The help message says the headers are going to be installed into
tools/include/nolibcbut this is only the default if $OUTPUT is not set, so better clarify this (the current value of $OUTPUT is already shown).Signed-off-by Willy Tarreau <[email protected]>
Applied.
Willy Tarreau
maintainerPATCH v2 2/4 tools/nolibc: add the more portable inttypes.h
In reply to Willy TarreauIt's often recommended to only use inttypes.h instead of stdint.h for portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when including inttypes.h. Let's add one that simply includes stdint.h to better support these programs.
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/inttypes.h | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tools/include/nolibc/inttypes.h
tools/include/nolibc/Makefile +1 -0
@@ -33,6 +33,7 @@ all_files := \ errno.h \ fcntl.h \ getopt.h \ + inttypes.h \ limits.h \ math.h \ nolibc.h \
tools/include/nolibc/inttypes.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ + +#ifndef _NOLIBC_INTTYPES_H +#define _NOLIBC_INTTYPES_H + +#include "stdint.h" + +#endif /* _NOLIBC_INTTYPES_H */
Signature · 1 line
2.17.5
Thomas Weißschuh
maintainerRe: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h
Quoted 7 lines · Willy Tarreau
It's often recommended to only use
inttypes.hinstead ofstdint.hfor portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when includinginttypes.h. Let's add one that simply includesstdint.hto better support these programs.
Quoted 6 lines
Signed-off-by Willy Tarreau <[email protected]>--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/inttypes.h | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tools/include/nolibc/inttypes.h
I think this should also interact with the big nolibc.h. Both being included from it and including it itself, to follow the generally used pattern.
Thomas
Willy Tarreau
maintainerRe: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h
Quoted 15 lines · Thomas Weißschuh
Quoted 7 lines · Willy Tarreau
It's often recommended to only use
inttypes.hinstead ofstdint.hfor portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when includinginttypes.h. Let's add one that simply includesstdint.hto better support these programs.Quoted 6 lines
Signed-off-by Willy Tarreau <[email protected]>--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/inttypes.h | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 tools/include/nolibc/inttypes.h
Quoted 4 lines
I think this should also interact with the big
nolibc.h. Both being included from it and including it itself, to follow the generally used pattern.
You mean you'd prefer "include nolibc.h" from inttypes and "include inttypes" from nolibc, that's it ?
Willy
Thomas Weißschuh
maintainerRe: [PATCH v2 2/4] tools/nolibc: add the more portable inttypes.h
Nov 2, 2025 12:18:57 Willy Tarreau <[email protected]>:
Quoted 16 lines · Thomas Weißschuh
Quoted 15 lines · Willy Tarreau
Quoted 13 lines
It's often recommended to only use
inttypes.hinstead ofstdint.hfor portability reasons since the former is always present when the latter is present, but not conversely, and the former includes the latter. Due to this some simple programs fail to build when includinginttypes.h. Let's add one that simply includesstdint.hto better support these programs.Signed-off-by Willy Tarreau <[email protected]>---
tools/include/nolibc/Makefile | 1 +tools/include/nolibc/inttypes.h| 8 ++++++++2 files changed, 9 insertions(+)create mode 100644
tools/include/nolibc/inttypes.h
Quoted 7 lines
Quoted 4 lines
I think this should also interact with the big
nolibc.h. Both being included from it and including it itself, to follow the generally used pattern.You mean you'd prefer "include
nolibc.h" from inttypes and "include inttypes" from nolibc, that's it ?
Yep.
Thomas
Willy Tarreau
maintainerPATCH v2 3/4 tools/nolibc: add missing memchr() to string.h
In reply to Willy TarreauSurprisingly we forgot to add this common one. It was added with a per-arch guard allowing to later implement it in arch-specific asm code like was done for a few other ones.
The test verifies that we don't search past the indicated length.
--- tools/include/nolibc/string.h | 15 +++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 17 insertions(+)
tools/include/nolibc/string.h +15 -0
@@ -93,6 +93,21 @@ void *memset(void *dst, int b, size_t len) }#endif /* #ifndef NOLIBC_ARCH_HAS_MEMSET */ +#ifndef NOLIBC_ARCH_HAS_MEMCHR +static __attribute__((unused)) +void *memchr (const void *s,int c,size_t len) +{ +char *p = (char *)s; + +while (len--) { +if (*p == (char )c) +return p; + p++; + } +return NULL ; +} +#endif /* #ifndef NOLIBC_ARCH_HAS_MEMCHR */ +static __attribute__((unused))char *strchr (const char *s,int c) {
tools/testing/selftests/nolibc/nolibc-test.c +2 -0
@@ -1558,6 +1558,8 @@ int run_stdlib(int min, int max)CASE_TEST (abs_noop);EXPECT_EQ (1 ,abs (10 ),10 );break ;CASE_TEST (difftime);EXPECT_ZR (1 ,test_difftime ());break ;CASE_TEST (test_timespec);EXPECT_ZR (1 ,test_timespec ());break ; +CASE_TEST (memchr_foobar6_o);EXPECT_STREQ (1 ,memchr ("foobar" ,'o' ,6 ),"oobar" );break ; +CASE_TEST (memchr_foobar3_b);EXPECT_STRZR (1 ,memchr ("foobar" ,'b' ,3 ));break ;case __LINE__:return ret;/* must be last */
Signature · 1 line
2.17.5
Re: [PATCH v2 3/4] tools/nolibc: add missing memchr() to string.h
Quoted 11 lines · Willy Tarreau
Surprisingly we forgot to add this common one. It was added with a per-arch guard allowing to later implement it in arch-specific asm code like was done for a few other ones.
The test verifies that we don't search past the indicated length.
Signed-off-by Willy Tarreau <[email protected]>--- tools/include/nolibc/string.h | 15 +++++++++++++++ tools/testing/selftests/nolibc/nolibc-test.c | 2 ++ 2 files changed, 17 insertions(+)
Applied.
Willy Tarreau
maintainerPATCH v2 4/4 tools/nolibc: provide the portable sys/select.h
In reply to Willy TarreauModern programs tend to include sys/select.h to get FD_SET() and FD_CLR() definitions as well as struct fd_set, but in our case it didn't exist.
The definitions were moved from types.h to sys/select.h, which is now included from nolibc.h, and the sys_select() definition moved there as well from sys.h.
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys.h | 45 ------------- tools/include/nolibc/sys/select.h | 103 ++++++++++++++++++++++++++++++ tools/include/nolibc/types.h | 47 -------------- 5 files changed, 105 insertions(+), 92 deletions(-) create mode 100644 tools/include/nolibc/sys/select.h
tools/include/nolibc/Makefile +1 -0
@@ -57,6 +57,7 @@ all_files := \ sys/random.h \ sys/reboot.h \ sys/resource.h \ + sys/select.h \ sys/stat.h \ sys/syscall.h \ sys/sysmacros.h \
tools/include/nolibc/nolibc.h +1 -0
@@ -104,6 +104,7 @@#include "sys/random.h" #include "sys/reboot.h" #include "sys/resource.h" +#include "sys/select.h" #include "sys/stat.h" #include "sys/syscall.h" #include "sys/sysmacros.h"
tools/include/nolibc/sys.h +0 -45
51 lines not on this page · raw message
tools/include/nolibc/sys/select.h new file +103 -0
103 lines not on this page · raw message
tools/include/nolibc/types.h +0 -47
59 lines not on this page · raw message
Signature · 1 line
2.17.5
Re: [PATCH v2 4/4] tools/nolibc: provide the portable sys/select.h
Quoted 9 lines · Willy Tarreau
Modern programs tend to include
sys/select.hto getFD_SET()andFD_CLR()definitions as well as structfd_set, but in our case it didn't exist.The definitions were moved from
types.htosys/select.h, which is now included fromnolibc.h, and thesys_select()definition moved there as well fromsys.h.Signed-off-by Willy Tarreau <[email protected]>
Quoted 8 lines
--- tools/include/nolibc/Makefile | 1 + tools/include/nolibc/nolibc.h | 1 + tools/include/nolibc/sys.h | 45 ------------- tools/include/nolibc/sys/select.h | 103 ++++++++++++++++++++++++++++++ tools/include/nolibc/types.h | 47 -------------- 5 files changed, 105 insertions(+), 92 deletions(-) create mode 100644 tools/include/nolibc/sys/select.h
Applied.