[PATCH 2/7] tools/nolibc: add __nolibc_arg_to_reg()
From: Thomas Weißschuh
Date: Sat Apr 18 2026 - 06:27:15 EST
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 <linux@xxxxxxxxxxxxxx>
---
tools/include/nolibc/crt.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/include/nolibc/crt.h b/tools/include/nolibc/crt.h
index f38590a05adf..2414114b7752 100644
--- a/tools/include/nolibc/crt.h
+++ b/tools/include/nolibc/crt.h
@@ -11,6 +11,10 @@
#include "compiler.h"
+#define __nolibc_arg_to_reg(_a) \
+ __builtin_choose_expr(__builtin_classify_type(_a) == __builtin_classify_type(NULL), \
+ (unsigned long)(_a), (_a))
+
char **environ __attribute__((weak));
const unsigned long *_auxv __attribute__((weak));
--
2.53.0