boot4-musl-shim-riscv64.h (1779B)
1 /* boot4 va_list shim for compiling musl with tcc 0.9.26 on riscv64. 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's riscv64 stdarg.h spells va_list as `char *` and 10 * implements va_arg / va_copy / va_end as plain pointer-arithmetic 11 * macros. Mirror that here, since musl is compiled with -nostdinc 12 * (tcc's stdarg.h is unreachable on its own); this header is 13 * `-include`d on every musl translation unit. 14 * 15 * The va_arg expansion is the riscv64 lp64/lp64d branch from 16 * tcc/include/stdarg.h: 8-byte slots, args ≤ 16 bytes by-value, args 17 * > 16 bytes by-pointer. __builtin_va_start is recognized internally 18 * by tcc's frontend; we only need to bridge the typedef and the 19 * remaining macros. 20 * 21 * Untested-but-promising — may need adjustment once first failures 22 * appear in printf/scanf/syslog/openat-style varargs callers. */ 23 24 typedef char *__builtin_va_list; 25 26 #define __va_reg_size 8 /* __riscv_xlen / 8, fixed for rv64 */ 27 28 #define _tcc_align(addr,type) \ 29 (((unsigned long)(addr) + __alignof__(type) - 1) & -(__alignof__(type))) 30 31 #define __builtin_va_arg(ap, type) \ 32 (*(sizeof(type) > (2 * __va_reg_size) \ 33 ? *(type **)((ap += __va_reg_size) - __va_reg_size) \ 34 : (ap = (__builtin_va_list)(_tcc_align(ap, type) + \ 35 (sizeof(type) + __va_reg_size - 1) & -__va_reg_size), \ 36 (type *)(ap - ((sizeof(type) + __va_reg_size - 1) & \ 37 -__va_reg_size))))) 38 39 #define __builtin_va_copy(dest, src) ((dest) = (src)) 40 #define __builtin_va_end(ap) ((void)(ap))