summaryrefslogtreecommitdiffstats
path: root/tools/include/nolibc
AgeCommit message (Collapse)AuthorLines
2026-04-09tools/nolibc: support UBSAN on gccThomas Weißschuh-1/+5
The UBSAN implementation in gcc requires a slightly different function attribute to skip instrumentation. Extend __nolibc_no_sanitize_undefined to also handle gcc. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260408-nolibc-gcc-15-v1-2-330d0c40f894@weissschuh.net
2026-04-09tools/nolibc: create __nolibc_no_sanitize_ubsanThomas Weißschuh-4/+7
The logic to disable UBSAN will become a bit more complicated. Move it out into compiler.h, so crt.h stays readable. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260408-nolibc-gcc-15-v1-1-330d0c40f894@weissschuh.net
2026-04-07tools/nolibc: add byteorder conversionsThomas Weißschuh-0/+57
Add some standard functions to convert between different byte orders. Conveniently the UAPI headers provide all the necessary functionality. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260405-nolibc-bswap-v1-1-f7699ca9cee0@weissschuh.net
2026-04-07tools/nolibc: add the _syscall() macroThomas Weißschuh-1/+2
The standard syscall() function or macro uses the libc return value convention. Errors returned from the kernel as negative values are stored in errno and -1 is returned. Users who want to avoid using errno don't have a way to call raw syscalls and check the returned error. Add a new macro _syscall() which works like the standard syscall() but passes through the return value from the kernel unchanged. The naming scheme and return values match the named _sys_foo() system call wrappers already part of nolibc. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260405-nolibc-syscall-v1-3-e5b12bc63211@weissschuh.net
2026-04-07tools/nolibc: move the call to __sysret() into syscall()Thomas Weißschuh-2/+2
__sysret() transforms the return value from the kernel into the libc return value convention. There is no reason for it to be called in the middle of the internals of the syscall() implementation macros. Move the call up, directly into syscall(), to make the code simpler. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260405-nolibc-syscall-v1-2-e5b12bc63211@weissschuh.net
2026-04-07tools/nolibc: rename the internal macros used in syscall()Thomas Weißschuh-5/+5
These macros are the internal implementation of syscall(). They can not be used by users. Align them with the standard naming scheme for internal symbols. The current name also prevents the addition of an application-usable _syscall() symbol. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260405-nolibc-syscall-v1-1-e5b12bc63211@weissschuh.net
2026-04-06tools/nolibc: check for overflow in calloc() without divisionsThomas Weißschuh-2/+2
On some architectures without native division instructions the division can generate calls into libgcc/compiler-rt. This library might not be available, so its use should be avoided. Use the compiler builtin to check for overflows without needing a division. The builtin has been available since GCC 3 and clang 3.8. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260404-nolibc-asprintf-v2-1-17d2d0df9763@weissschuh.net
2026-04-06tools/nolibc: add support for asprintf()Thomas Weißschuh-0/+50
Add support for dynamically allocating formatted strings through asprintf() and vasprintf(). Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260401-nolibc-asprintf-v1-3-46292313439f@weissschuh.net
2026-04-04tools/nolibc: use __builtin_offsetof()Thomas Weißschuh-1/+1
The current custom implementation of offsetof() fails UBSAN: runtime error: member access within null pointer of type 'struct ...' This means that all its users, including container_of(), free() and realloc(), fail. Use __builtin_offsetof() instead which does not have this issue and has been available since GCC 4 and clang 3. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260401-nolibc-asprintf-v1-1-46292313439f@weissschuh.net
2026-04-04tools/nolibc: use makedev() in fstatat()Thomas Weißschuh-6/+3
fstatat() contains two open-coded copies of makedev() to handle minor numbers >= 256. Now that the regular makedev() handles both large minor and major numbers correctly use the common function. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260404-nolibc-makedev-v2-6-456a429bf60c@weissschuh.net
2026-04-04tools/nolibc: handle all major and minor numbers in makedev() and friendsThomas Weißschuh-4/+4
Remove the limitation of only handling small major and minor numbers. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260404-nolibc-makedev-v2-5-456a429bf60c@weissschuh.net
2026-04-04tools/nolibc: make dev_t 64 bits wideThomas Weißschuh-1/+1
statx() returns both 32-bit minor and major numbers. For both of them to fit into the 'dev_t' in 'struct stat', that needs to be 64 bits wide. The other uses of 'dev_t' in nolibc are makedev() and friends and mknod(). makedev() and friends are going to be adapted in an upcoming commit and mknod() will silently truncate 'dev_t' to 'unsigned int' in the kernel, similar to other libcs. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260404-nolibc-makedev-v2-4-456a429bf60c@weissschuh.net
2026-04-04tools/nolibc: move the logic of makedev() and friends into functionsThomas Weißschuh-3/+20
Functions make it easier to keep the input and output types straight and avoid duplicate evaluations of their arguments. Also these functions will become a bit more complex to handle full 64-bit 'dev_t' which is easier to read in a function. Still stay compatible with code which expects these to be macros. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260404-nolibc-makedev-v2-3-456a429bf60c@weissschuh.net
2026-04-02tools/nolibc: explicitly list architecture headersThomas Weißschuh-1/+2
Relying on $(wildcard) is brittle and non-deterministic. similar to all the other headers. Switch the list of architecture headers to an explicit list, Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-4-bcf4c9f5c1be@weissschuh.net Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-04-02tools/nolibc: drop superfluous definition of QThomas Weißschuh-6/+0
Q is already defined by tools/scripts/Makefile.include which is included at the top of tools/include/nolibc/Makefile. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-3-bcf4c9f5c1be@weissschuh.net
2026-04-02tools/nolibc: drop superfluous invocation of mkdirThomas Weißschuh-1/+0
The call to 'mkdir -p $(OUTPUT)sysroot/include' will also create the sysroot directory. Drop the unnecessary explicit invocation of mkdir. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-2-bcf4c9f5c1be@weissschuh.net
2026-04-02tools/nolibc: drop superfluous invocation of 'make headers'Thomas Weißschuh-1/+0
The headers_install target of the toplevel Makefile will already make sure that the headers are up-to-date. Drop the superfluous explicit invocation. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20260401-nolibc-cleanup-v1-1-bcf4c9f5c1be@weissschuh.net
2026-04-01tools/nolibc/printf: Support negative variable width and precisionDavid Laight-30/+38
For (eg) "%*.*s" treat a negative field width as a request to left align the output (the same as the '-' flag), and a negative precision to request the default precision. Set the default precision to -1 (not INT_MAX) and add explicit checks to the string handling for negative values (makes the tet unsigned). For numeric output check for 'precision >= 0' instead of testing _NOLIBC_PF_FLAGS_CONTAIN(flags, '.'). This needs an inverted test, some extra goto and removes an indentation. The changed conditionals fix printf("%0-#o", 0) - but '0' and '-' shouldn't both be specified. Signed-off-by: David Laight <david.laight.linux@gmail.com> Link: https://patch.msgid.link/20260323112247.3196-1-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-22tools/nolibc: rename sys_foo() functions to _sys_foo()Thomas Weißschuh-192/+192
The sys_foo() naming scheme used by the syscall wrappers may collide with application symbols. Especially as 'sys_' is an obvious naming scheme an application may choose for its own custom systemcall wrappers. Avoid these conflicts by using an leading underscore which moves the names into the implementation's namespace. This naming scheme was chosen over a '__nolibc_' prefix, as these functions are not an implementation detail but a documented interface meant to be used by applications. While this may break some existing users, adapting them should be straightforward. Given that nolibc is most-likely vendored, no unexpected breakage should happen. No in-tree users are affected. These conflicts happen when compiling some of the kernel selftests with nolibc. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260319-nolibc-namespacing-v1-1-33c22eaddb5e@weissschuh.net
2026-03-22tools/nolibc: avoid -Wundef warning for __STDC_VERSION__Thomas Weißschuh-1/+7
With -std=c89 the macro __STDC_VERSION__ is not defined. While undefined identifiers in '#if' directives are assumed to be '0', with -Wundef a warning is emitted. Avoid the warning by explicitly falling back to '0' if __STDC_VERSION__ is not provided by the preprocessor. Fixes: 37219aa5b123 ("tools/nolibc: add __nolibc_static_assert()") Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260318-nolibc-wundef-v1-1-fcb7f9ac7298@weissschuh.net
2026-03-22tools/nolibc: add err.hThomas Weißschuh-0/+89
Add a few convenient helpers to print error and warning messages. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260318-nolibc-err-h-v4-2-08247a694bd9@weissschuh.net
2026-03-22tools/nolibc: add support for program_invocation_{,short_}nameThomas Weißschuh-0/+30
Add support for the GNU extensions 'program_invocation_name' and 'program_invocation_short_name'. These are useful to print error messages, which by convention include the program name. As these are global variables which take up memory even if not used, similar to 'errno', gate them behind NOLIBC_IGNORE_ERRNO. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260318-nolibc-err-h-v4-1-08247a694bd9@weissschuh.net
2026-03-20tools/nolibc: MIPS: fix clobbers of 'lo' and 'hi' registers on different ISAsThomas Weißschuh-3/+12
All MIPS ISAs before r6 use the 'lo' and 'hi' special registers. These are clobbered by system calls and need to be marked as such to avoid miscompilations. Currently nolibc ties the clobbers to the ABI. But this is wrong and leads to ISA<->ABI combinations which are not handled correctly, leading to compiler errors or miscompilations. Handle all different combinations of ABI and ISA. Fixes: a6a2a8a42972 ("tools/nolibc: MIPS: add support for N64 and N32 ABIs") Fixes: 66b6f755ad45 ("rcutorture: Import a copy of nolibc") Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk> Link: https://lore.kernel.org/lkml/alpine.DEB.2.21.2603141744240.55200@angie.orcam.me.uk/ Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://patch.msgid.link/20260317-nolibc-mips-clobber-v2-1-5b9a97761a9e@linutronix.de Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Add support for octal outputDavid Laight-15/+35
Octal output isn't often used, but adding it costs very little. Supporting "%#o" is mildly annoying, it has to add a leading '0' if there isn't one present. In simple cases this is the same as adding a sign of '0' - but that adds an extra '0' in a few places. So you need 3 tests, %o, # and no leading '0' (which can only be checked after the zero pad for precision). If all the test are deferred until after zero padding then too many values are 'live' across the call to _nolibc_u64toa_base() and get spilled to stack. Hence the check that ignores the 'sign' if it is the same as the first character of the output string. Add tests for octal output. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-17-david.laight.linux@gmail.com [Thomas: avoid a -Wsign-compare] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Add support for zero padding and field precisionDavid Laight-16/+64
Includes support for variable field widths (eg "%*.*d"). Zero padding is limited to 31 zero characters. This is wider than the largest numeric field so shouldn't be a problem. All the standard printf formats are now supported except octal and floating point. Add tests for new features Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-16-david.laight.linux@gmail.com [Thomas: fixup testcases for musl libc] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Add support for left aligning fieldsDavid Laight-1/+5
Output the characters before or after the pad - writing the pad takes more code. Include additional/changed tests Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-15-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Special case 0 and add support for %#xDavid Laight-11/+27
The output for %#x is almost the same as that for %p, both output in hexadecimal with a leading "0x". However for zero %#x should just output "0" (the same as decimal and ocal). For %p match glibc and output "(nil)" rather than "0x0" or "0". Add tests for "%#x", "% d", "%+d" and passing NULL to "%p". Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-14-david.laight.linux@gmail.com [Thomas: fix up testcases for musl libc] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Add support for conversion flags space and plusDavid Laight-1/+5
Flags ' ' and '+' are sign characters for positive numbers. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-13-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Prepend sign to converted numberDavid Laight-9/+27
Instead of appending the converted number to the sign, convert first and then prepend the sign (or "0x"). Use the length returned by u64toh_r() instead of calling strlen(). Needed so that zero padding can be inserted between the sign and digits in an upcoming patch. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-12-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Handle "%s" with the numeric formatsDavid Laight-10/+11
Avoids the extra va_arg() call with is non-trivial on a lot of modern ABI. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-11-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Add support for length modifiers tzqL and formats iXDavid Laight-11/+16
Length modifiers t (ptrdiff_t) and z (size_t) are aliases for l (long), q and L are 64bit the same as j (intmax). Format i is an alias for d and X similar to x but upper case. Supporting them is mostly just adding the relevant bit to the bit pattern used for matching characters. Although %X is detected the output will be lower case. Change/add tests to use conversions i and X, and length modifiers L and ll. Use the correct minimum value for "%Li". Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-10-david.laight.linux@gmail.com [Thomas: Fix up testcases for musl libc] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Use bit-masks to hold requested flag, length and ↵David Laight-48/+106
conversion chars Use flags bits (1u << (ch & 31)) for the flags, length modifiers, and conversion specifiers. This makes it easy to test for multiple values at once. Detect the conversion flags " #+-0" although they are currently all ignored. Unconditionally generate the signed values (for %d) to remove a second set of checks for the size. Separate out the formatting of single characters from numbers. Output the sign for negative values then negate and treat as unsigned. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-9-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Use goto and reduce indentationDavid Laight-78/+93
Upcoming changes will need to use goto to jump to the code that outputs characters. Use 'goto do_output' to output a known number of characters. Use 'goto do_strlen_output' to output a '\0' terminated string. Removes a level of indentation from the format processing code. The change is best reviewed using 'git diff -b' after applying it. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-8-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Simplify __nolibc_printf()David Laight-51/+53
Move the check for the length modifiers into the format processing between the field width and conversion specifier. This lets the loop be simplified and a 'fast scan' for a format start used. If an error is detected (eg an invalid conversion specifier) then copy the invalid format to the output buffer. Reduces code size by about 10% on x86-64. Some versions of gcc bloat this version by generating a jump table. All goes away in the later patches. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-7-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Output pad characters in 16 byte chunksDavid Laight-5/+9
Simple to do and saves calls to the callback function. Change variables written, width and len to 'signed int' to get better code. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-6-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc: Rename the 'errnum' parameter to strerror()David Laight-2/+2
Change the parameter variable name from 'errno' to 'errnum'. Matches any documentation and avoids any issues that might happen if errno is actually a #define (which is not uncommon). Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-5-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc: Implement strerror() in terms of strerror_r()David Laight-3/+19
strerror() can be the only part of a program that has a .data section. This requires 4k in the program file. Add a simple implementation of strerror_r() and use that in strerror() so that the "errno=" string is copied at run-time. Use __builtin_memcpy() because that optimises away the input string and just writes the required constants to the target buffer. Code size change largely depends on whether the inlining decision for strerror() changes. Change the tests to use the normal EXPECT_VFPRINTF() when testing %m. Skip the tests when !is_nolibc. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-4-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc: Add _NOLIBC_OPTIMIZER_HIDE_VAR() to compiler.hDavid Laight-0/+3
Needed to stop compiler 'optimisations' bloating code. Equivalent to the definition in include/linux/compiler.h Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-2-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Move snprintf length check to callbackDavid Laight-27/+67
Move output truncation to the snprintf() callback. This simplifies the main code and fixes truncation of padded fields. Add a zero length callback to 'finalise' the buffer rather than doing it in snprintf() itself. Fixes: e90ce42e81381 ("tools/nolibc: implement width padding in printf()") Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260302101815.3043-3-david.laight.linux@gmail.com [Thomas: clean up Fixes trailer] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc/printf: Change variables 'c' to 'ch' and 'tmpbuf[]' to 'outbuf[]'David Laight-19/+19
Changing 'c' makes the code slightly easier to read because the variable stands out from the single character literals (especially 'c'). Change tmpbuf[] to outbuf[] because 'out' points into it. The following patches pretty much rewrite the function so the churn is limited. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260223101735.2922-7-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-03-20tools/nolibc: Optimise and common up the number to ascii functionsDavid Laight-87/+82
Implement u[64]to[ah]_r() using a common function that uses multiply by reciprocal to generate the least significant digit first and then reverses the string. On 32bit this is five multiplies (with 64bit product) for each output digit. I think the old utoa_r() always did 36 multiplies and a lot of subtracts - so this is likely faster even for 32bit values. Definitely better for 64bit values (especially small ones). Clearly shifts are faster for base 16, but reversing the output buffer makes a big difference. Sharing the code reduces the footprint (unless gcc decides to constant fold the functions). Definitely helps vfprintf() where the constants get loaded and a single call is done. Also makes it cheap to add octal support to vfprintf for completeness. Signed-off-by: David Laight <david.laight.linux@gmail.com> Link: https://patch.msgid.link/20260223101735.2922-3-david.laight.linux@gmail.com Acked-by: Willy Tarreau <w@1wt.eu> [Thomas: skip int128 multiplication on SPARC and clang] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-02-25tools/nolibc: rename my_syscallX() to __nolibc_syscallX()Thomas Weißschuh-218/+220
The naming convention of the my_syscallX() macros is a bit unfortunate. They may conflict with application code and the name is very generic. Switch to __nolibc_syscallX(). The leading underscores place the symbols in the implementation-defined namespace, avoiding conflicting names. It is also clearer that these are non-standard extensions from nolibc. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260223-nolibc-namespacing-v1-1-52574ffebb2c@weissschuh.net
2026-01-11tools/nolibc: Add fseek() to stdio.hDaniel Palmer-0/+19
A very basic wrapper around lseek() that implements fseek(). Signed-off-by: Daniel Palmer <daniel@thingy.jp> Link: https://patch.msgid.link/20260105023629.1502801-3-daniel@thingy.jp Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-01-11tools/nolibc: Add fread() to stdio.hDaniel Palmer-1/+33
Add a very basic version of fread() like we already have for fwrite(). Signed-off-by: Daniel Palmer <daniel@thingy.jp> Link: https://patch.msgid.link/20260105023629.1502801-2-daniel@thingy.jp Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
2026-01-06tools/nolibc: align sys_vfork() with sys_fork()Thomas Weißschuh-13/+13
Currently the generic variants of sys_fork() and sys_vfork() differ in both they precedence of used system calls and the usage of sys_clone() vs sys_clone3(). While the interface of clone3() in sys_vfork() is more consistent over different architectures, qemu-user does not support it, making testing harder. We already handle the different clone() interfaces for sys_fork() in the architecture-specific headers, and can do so also for sys_vfork(). In fact SPARC already has such handling and only s390 is currently missing. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260104-nolibc-vfork-v1-1-a63464b9e4e6@weissschuh.net
2026-01-06selftests/nolibc: add static assertions around time types handlingThomas Weißschuh-0/+22
The nolibc system call wrappers expect the libc types to be compatible to the kernel types. Make sure these expectations hold at compile-time. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20251220-nolibc-uapi-types-v3-14-c662992f75d7@weissschuh.net
2026-01-06tools/nolibc: add __nolibc_static_assert()Thomas Weißschuh-0/+8
Add a wrapper for _Static_assert() to use within nolibc. While _Static_assert() itself was only standardized in C11, in GCC and clang dialects it is also available in older standards. Link: https://lore.kernel.org/lkml/20251203192330.GA12995@1wt.eu/ Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20251220-nolibc-uapi-types-v3-13-c662992f75d7@weissschuh.net
2026-01-06tools/nolibc: add compiler version detection macrosThomas Weißschuh-0/+16
Some upcoming logic needs to depend on the version of GCC or clang. Add some helper macros to keep the conditionals readable. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20251220-nolibc-uapi-types-v3-12-c662992f75d7@weissschuh.net
2026-01-06tools/nolibc: remove time conversionsThomas Weißschuh-76/+8
Now that 'struct timespec' and 'struct __kernel_timespec' are compatible, the conversions are not necessary anymore. The same holds true for 'struct itimerspec' and 'struct __kernel_itimerspec'. Remove the conversions. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20251220-nolibc-uapi-types-v3-11-c662992f75d7@weissschuh.net
2026-01-04tools/nolibc: always use 64-bit time typesThomas Weißschuh-5/+6
32-bit time types will stop working in 2038. Switch to 64-bit time types everywhere. Suggested-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/lkml/cec27d94-c99d-4c57-9a12-275ea663dda8@app.fastmail.com/ Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Link: https://patch.msgid.link/20251220-nolibc-uapi-types-v3-9-c662992f75d7@weissschuh.net