boot2

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

boot4-musl-shim-amd64.h (1768B)


      1 /* boot4 va_list shim for compiling musl with tcc 0.9.26.
      2  *
      3  * musl's stdarg.h and bits/alltypes.h spell varargs the GCC way:
      4  *
      5  *     typedef __builtin_va_list va_list;
      6  *     #define va_start(v,l) __builtin_va_start(v,l)
      7  *     ...
      8  *
      9  * tcc 0.9.26 has no `__builtin_va_list` typename; its own stdarg.h
     10  * names the same shape `__va_list_struct[1]` and routes va_start/va_arg
     11  * through tcc intrinsics __va_start, __va_arg, __builtin_frame_address,
     12  * and __builtin_va_arg_types. musl is compiled with -nostdinc so tcc's
     13  * stdarg.h is unreachable on its own; this header is `-include`d on
     14  * every musl translation unit to bridge the two notations.
     15  *
     16  * Layout matches tcc/lib/va_list.c — those four fields are the SysV
     17  * x86_64 ABI register-save struct that __va_start initializes and
     18  * __va_arg walks. boot3's libtcc1.a provides __va_start and __va_arg
     19  * at link time. */
     20 
     21 typedef struct {
     22     unsigned int gp_offset;
     23     unsigned int fp_offset;
     24     union {
     25         unsigned int overflow_offset;
     26         char *overflow_arg_area;
     27     };
     28     char *reg_save_area;
     29 } __va_list_struct;
     30 
     31 typedef __va_list_struct __builtin_va_list[1];
     32 
     33 void __va_start(__va_list_struct *ap, void *fp);
     34 void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
     35 
     36 #define __builtin_va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
     37 #define __builtin_va_arg(ap, type)                                     \
     38     (*(type *)(__va_arg(ap,                                            \
     39                         __builtin_va_arg_types(type),                  \
     40                         sizeof(type),                                  \
     41                         __alignof__(type))))
     42 #define __builtin_va_copy(dest, src) (*(dest) = *(src))
     43 #define __builtin_va_end(ap)