From: Thomas Weißschuh Date: Sat, 18 Apr 2026 10:19:57 +0000 (+0200) Subject: tools/nolibc: add __nolibc_arg_to_reg() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32db83195f75bda670ca9282d9868ad02b1d6185;p=thirdparty%2Fkernel%2Flinux.git tools/nolibc: add __nolibc_arg_to_reg() In the architecture specific system call glue, all arguments are currently casted to 'long' to fit into registers. This works for pointers as 'long' has the same size as pointers. However the system call registers for X32 and MIPS N32 need to be 'long long' to work correctly for 64-bit values expected by the system call ABI. Casting a pointer to a 'long long' will produce a compiler warning while casting 64-bit integers to 'long' will truncate those. Add a helper which can be used to correctly cast both pointers and integers into 'long long' registers. Cast the pointers through 'unsigned' to avoid any sign extensions. Both builtins have been available since at least GCC 3 and clang 3. Signed-off-by: Thomas Weißschuh Acked-by: Willy Tarreau Link: https://patch.msgid.link/20260418-nolibc-largefile-v1-2-b91f0775bac3@weissschuh.net --- diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h index 78124b6598a72..714256228914e 100644 --- a/tools/include/nolibc/crt.h +++ b/tools/include/nolibc/crt.h @@ -7,6 +7,10 @@ #ifndef _NOLIBC_CRT_H #define _NOLIBC_CRT_H +#define __nolibc_arg_to_reg(_a) \ + __builtin_choose_expr(__builtin_classify_type(_a) == __builtin_classify_type(NULL), \ + (unsigned long)(_a), (_a)) + #ifndef NOLIBC_NO_RUNTIME #include "compiler.h"