boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

va_list_shim.h (1548B)


      1 /* tcc-libc va_list shim — pre-included when tcc-boot2 compiles
      2  * libc.flat.c (or any other host-preprocessed TU under our boot2
      3  * stdarg.h shim). The flatten step routes `va_list` through
      4  * `__builtin_va_list`, but on aarch64 / amd64 stock tcc's frontend
      5  * does not recognize that token as a type — tcc's <stdarg.h> defines
      6  * `va_list` as `__va_list_struct[1]`. Make `__builtin_va_list` an
      7  * alias for the same array type so libc.flat.c's
      8  *
      9  *     typedef __builtin_va_list va_list;
     10  *
     11  * collapses to a (legal) duplicate typedef of the existing
     12  * tcc-stdlib `va_list`. The `__builtin_va_*` macros in the flatten
     13  * are direct tcc intrinsics; the aliases just reach them by the
     14  * gcc-conformant builtin spelling.
     15  *
     16  * On riscv64 tcc's <stdarg.h> already names everything by the
     17  * gcc spelling — `va_list` is a typedef to `__builtin_va_list`,
     18  * `__builtin_va_arg` / `__builtin_va_end` / `__builtin_va_copy` are
     19  * macros, and `__builtin_va_start` is a frontend intrinsic — so the
     20  * shim has nothing to add. The aliases below would in fact redefine
     21  * the macros stdarg.h already declared, triggering an infinite-loop
     22  * expansion of `__builtin_va_arg(ap, type)` through `va_arg(ap,
     23  * type)` and back. Gate the aliases on !__riscv. */
     24 #include <stdarg.h>
     25 
     26 #ifndef __riscv
     27 typedef va_list __builtin_va_list;
     28 #define __builtin_va_start(ap, last) va_start(ap, last)
     29 #define __builtin_va_end(ap)         va_end(ap)
     30 #define __builtin_va_arg(ap, type)   va_arg(ap, type)
     31 #define __builtin_va_copy(dst, src)  va_copy(dst, src)
     32 #endif