mirror of
https://github.com/frida/tinycc
synced 2024-12-24 22:16:49 +03:00
245f6a0d13
This makes available the __builtin_va_list type and __builtin variants of va_start, va_arg, va_copy and va_end. We do this via a header file that's prepended to all compilations always (except if merely preprocessing): tcc_predefs.h. That header could also be used for predefining other builtins in the future. We don't need the define hacks for musl anymore with this. Also fix x86_64 gfunc_prologue to reserve enoug space for the full va_list structure, not just 16 bytes.
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
/* va_list.c - tinycc support for va_list on X86_64 */
|
|
|
|
#if defined __x86_64__
|
|
|
|
/* Avoid include files, they may not be available when cross compiling */
|
|
extern void abort(void);
|
|
|
|
/* This should be in sync with our include/stdarg.h */
|
|
enum __va_arg_type {
|
|
__va_gen_reg, __va_float_reg, __va_stack
|
|
};
|
|
|
|
/* GCC compatible definition of va_list. */
|
|
/*predefined by TCC (tcc_predefs.h):
|
|
typedef struct {
|
|
unsigned int gp_offset;
|
|
unsigned int fp_offset;
|
|
union {
|
|
unsigned int overflow_offset;
|
|
char *overflow_arg_area;
|
|
};
|
|
char *reg_save_area;
|
|
} __builtin_va_list[1];
|
|
*/
|
|
|
|
void *__va_arg(__builtin_va_list ap,
|
|
int arg_type,
|
|
int size, int align)
|
|
{
|
|
size = (size + 7) & ~7;
|
|
align = (align + 7) & ~7;
|
|
switch ((enum __va_arg_type)arg_type) {
|
|
case __va_gen_reg:
|
|
if (ap->gp_offset + size <= 48) {
|
|
ap->gp_offset += size;
|
|
return ap->reg_save_area + ap->gp_offset - size;
|
|
}
|
|
goto use_overflow_area;
|
|
|
|
case __va_float_reg:
|
|
if (ap->fp_offset < 128 + 48) {
|
|
ap->fp_offset += 16;
|
|
return ap->reg_save_area + ap->fp_offset - 16;
|
|
}
|
|
size = 8;
|
|
goto use_overflow_area;
|
|
|
|
case __va_stack:
|
|
use_overflow_area:
|
|
ap->overflow_arg_area += size;
|
|
ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
|
|
return ap->overflow_arg_area - size;
|
|
|
|
default: /* should never happen */
|
|
abort();
|
|
return 0;
|
|
}
|
|
}
|
|
#endif
|