From 052bcaf7046b16431e49d1175c5cf42073ff86f3 Mon Sep 17 00:00:00 2001 From: Dev <9416650+aoinoikaz@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:40:26 -0500 Subject: [PATCH 1/2] include: sys/types.h: Define wchar_t as the compiler's __WCHAR_TYPE__. The type of a wide character literal is the compiler's to decide for its target, and it names that type __WCHAR_TYPE__; a TinyCC that writes PE names unsigned short, Windows' width. Mes defined wchar_t as int whatever the compiler, so such a TinyCC compiling Mes libc against its own stddef.h, whose wchar_t is __WCHAR_TYPE__, stopped at the second definition with "incompatible redefinition of 'wchar_t'". MesCC names no __WCHAR_TYPE__ and keeps int. * include/sys/types.h (wchar_t): Define as __WCHAR_TYPE__ where the compiler names one. --- include/sys/types.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/sys/types.h b/include/sys/types.h index b9e0d553..29c505fa 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -165,9 +165,15 @@ typedef unsigned uid_t; #ifndef __MES_WCHAR_T #define __MES_WCHAR_T #undef wchar_t +// The compiler names the type of a wide character literal for its +// target; MesCC names none. +#ifdef __WCHAR_TYPE__ +typedef __WCHAR_TYPE__ wchar_t; +#else typedef int wchar_t; #endif #endif +#endif #endif // ! SYSTEM_LIBC From e25dc84c7798236d0bee990150e9247578161447 Mon Sep 17 00:00:00 2001 From: Dev <9416650+aoinoikaz@users.noreply.github.com> Date: Thu, 5 Nov 2026 19:40:26 -0500 Subject: [PATCH 2/2] lib: vfprintf, vsnprintf: Fall back to va_arg without va_arg8. include/stdarg.h defines va_arg8, which these read the argument of %e, %f and %g with, and, but for RISC-V and a system C library, a va_arg that reads every argument as a long. A compiler's own stdarg.h, which a C library may be compiled against in its place, defines va_arg alone, and its va_arg reads a double as one: TinyCC's for i386 steps over the double's eight bytes. So a TinyCC compiling Mes libc with its own include directory first, as nixpkgs' tinycc-boot-mes does, stopped at va_arg8. Where va_arg8 is undefined these now read a double with va_arg; with include/stdarg.h nothing changes. nixpkgs replaces va_arg8 with va_arg instead, which with include/stdarg.h reads a double as a long. * lib/stdio/vfprintf.c (va_arg8): Define as va_arg where stdarg.h does not define it. * lib/stdio/vsnprintf.c (va_arg8): Likewise. --- lib/stdio/vfprintf.c | 6 ++++++ lib/stdio/vsnprintf.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/stdio/vfprintf.c b/lib/stdio/vfprintf.c index 839ad897..e1c1c971 100644 --- a/lib/stdio/vfprintf.c +++ b/lib/stdio/vfprintf.c @@ -23,6 +23,12 @@ #include #include +/* A compiler's own stdarg.h defines va_arg alone, and its va_arg reads a + double as one. */ +#ifndef va_arg8 +#define va_arg8(ap, type) va_arg (ap, type) +#endif + int vfprintf (FILE * f, char const *format, va_list ap) { diff --git a/lib/stdio/vsnprintf.c b/lib/stdio/vsnprintf.c index ff1b3c2b..d8b3b5c8 100644 --- a/lib/stdio/vsnprintf.c +++ b/lib/stdio/vsnprintf.c @@ -23,6 +23,12 @@ #include #include +/* A compiler's own stdarg.h defines va_arg alone, and its va_arg reads a + double as one. */ +#ifndef va_arg8 +#define va_arg8(ap, type) va_arg (ap, type) +#endif + int vsnprintf (char *str, size_t size, char const *format, va_list ap) {