DRAFT lib: define va_* for bootstrappable tcc in riscv.

Bootstrappable TCC needs some extra definitions that upstream TCC
obtains from `tccdefs.h` in its codebase, which is also injected in the
binary using a weird trick (see `c2str` in tcc's codebase).

* include/stdarg.h: Add definitions for variable length arguments.
This commit is contained in:
Ekaitz Zarraga 2023-10-11 15:53:08 +02:00 committed by Janneke Nieuwenhuizen
parent 3539ee92a7
commit 596df500b6

View file

@ -32,6 +32,29 @@
// GCC on RISC-V always passes arguments in registers. Implementing
// these macros without the use of built-ins would be very involved.
// TINYCC tries to be GCC compatible in this case.
#if __TINYC__ < 928
// Bootstrappable TINYCC (version < 928) needs some definitions in RISC-V
typedef char *__builtin_va_list;
#define __va_reg_size (__riscv_xlen >> 3)
#define _tcc_align(addr, type) \
(((unsigned long)addr + __alignof__(type) - 1) \
& -(__alignof__(type)))
#define __builtin_va_arg(ap, type) \
(*(sizeof (type) > (2*__va_reg_size) \
? *(type **)((ap += __va_reg_size) - __va_reg_size) \
: (ap = (va_list)(_tcc_align (ap, type) \
+ (sizeof (type) + __va_reg_size - 1) \
& -__va_reg_size), \
(type *)(ap - ((sizeof (type)+ __va_reg_size - 1) \
& -__va_reg_size)))))
#define __builtin_va_end(ap) (void)(ap)
#if !defined (__builtin_va_copy)
#define __builtin_va_copy(dest, src) (dest) = (src)
#endif
#endif // __TINYC__ < 928
typedef __builtin_va_list va_list;
#define va_start(v, l) __builtin_va_start (v, l)