From 2b2c9e7f125706f9ab27a52699dcbfdb42179548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Jos=C3=A9=20Garc=C3=ADa=20Garc=C3=ADa?= Date: Sat, 15 Aug 2026 13:41:42 +0200 Subject: [PATCH] Use the compiler's va_list instead of the char* stack-walk _PDCLIB_va_list is char*, and va_arg/va_start walk it as a flat sequence of pointer-sized slots starting right after the last named parameter. That conflicts with the compiler's own va_list the moment a translation unit pulls in both (see vitasdk/vdpm#66), and even without that clash, the walk itself breaks on long long/double/anything 8-byte once you're past the register-passed args, since AAPCS aligns those to an even register pair and _PDCLIB_va_round doesn't account for it. Swap _PDCLIB_va_list and the four va_* macros for the compiler's own __builtin_va_list/__builtin_va_arg/etc. Same public va_arg/va_start/ va_end/va_copy names, nothing calling them needs to change. --- include/_PDCLIB_config.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/_PDCLIB_config.h b/include/_PDCLIB_config.h index f1d1475..f521260 100644 --- a/include/_PDCLIB_config.h +++ b/include/_PDCLIB_config.h @@ -216,11 +216,15 @@ struct _PDCLIB_imaxdiv_t /* Internal helper macro. va_round is not part of . */ #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) -typedef char * _PDCLIB_va_list; -#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) -#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) -#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) -#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) +/* arm-vita-eabi passes the first four words of a variadic call in + registers (AAPCS), so the stack-walking hack above -- which this file's + own comment already disclaims for non-stack-based architectures -- does + not locate them. Defer to the compiler's real va_list instead. */ +typedef __builtin_va_list _PDCLIB_va_list; +#define _PDCLIB_va_arg( ap, type ) __builtin_va_arg( ap, type ) +#define _PDCLIB_va_copy( dest, src ) __builtin_va_copy( dest, src ) +#define _PDCLIB_va_end( ap ) __builtin_va_end( ap ) +#define _PDCLIB_va_start( ap, parmN ) __builtin_va_start( ap, parmN ) /* -------------------------------------------------------------------------- */ /* OS "glue", part 1 */