diff --git a/include/stdarg.h b/include/stdarg.h index 080143da..81c6a308 100644 --- a/include/stdarg.h +++ b/include/stdarg.h @@ -4,7 +4,24 @@ #ifdef __x86_64__ #ifndef _WIN64 +#ifndef __APPLE__ +//This should be in sync with the declaration on our lib/libtcc1.c +/* GCC compatible definition of va_list. */ +typedef struct { + unsigned int gp_offset; + unsigned int fp_offset; + union { + unsigned int overflow_offset; + char *overflow_arg_area; + }; + char *reg_save_area; +} __va_list_struct; +typedef __va_list_struct va_list[1]; +#else +/* This is sometimes a void* on TCC, which makes it unlikely to + work with va_copy, but until we have something better ... */ typedef __builtin_va_list va_list; +#endif void __va_start(va_list ap, void *fp); void *__va_arg(va_list ap, int arg_type, int size, int align); diff --git a/lib/bt-log.c b/lib/bt-log.c index 94010b2f..d767f08a 100644 --- a/lib/bt-log.c +++ b/lib/bt-log.c @@ -1,9 +1,9 @@ /* ------------------------------------------------------------- */ /* function to get a stack backtrace on demand with a message */ +#include #include #include -#include int (*__rt_error)(void*, void*, const char *, va_list); diff --git a/lib/va_list.c b/lib/va_list.c index 6be9fa19..3d403177 100644 --- a/lib/va_list.c +++ b/lib/va_list.c @@ -2,16 +2,14 @@ #if defined __x86_64__ -#include "stdarg.h" - /* Avoid include files, they may not be available when cross compiling */ extern void *memset(void *s, int c, __SIZE_TYPE__ n); extern void abort(void); /* This should be in sync with our include/stdarg.h */ -#define __VA_GEN_REG 0 -#define __VA_FLOAT_REG 1 -#define __VA_STACK 2 +enum __va_arg_type { + __va_gen_reg, __va_float_reg, __va_stack +}; /* GCC compatible definition of va_list. */ typedef struct { @@ -24,45 +22,43 @@ typedef struct { char *reg_save_area; } __va_list_struct; -void __va_start(va_list ap, void *fp) +void __va_start(__va_list_struct *ap, void *fp) { - __va_list_struct * _ap = (__va_list_struct*) ap; - memset(_ap, 0, sizeof(__va_list_struct)); - *_ap = *(__va_list_struct *)((char *)fp - 16); - _ap->overflow_arg_area = (char *)fp + _ap->overflow_offset; - _ap->reg_save_area = (char *)fp - 176 - 16; + memset(ap, 0, sizeof(__va_list_struct)); + *ap = *(__va_list_struct *)((char *)fp - 16); + ap->overflow_arg_area = (char *)fp + ap->overflow_offset; + ap->reg_save_area = (char *)fp - 176 - 16; } -void *__va_arg(va_list ap, +void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align) { - __va_list_struct * _ap = (__va_list_struct*) ap; size = (size + 7) & ~7; align = (align + 7) & ~7; switch (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; + 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; + 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: + 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; + 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 h_appen */ + default: /* should never happen */ abort(); return 0; } diff --git a/libtcc.c b/libtcc.c index 61fafe46..5bbed072 100644 --- a/libtcc.c +++ b/libtcc.c @@ -928,15 +928,15 @@ LIBTCCAPI TCCState *tcc_new(void) tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x"); #endif /* ndef TCC_TARGET_PE */ #ifdef TCC_TARGET_MACHO - /* emulate APPLE-GCC to make libc's headerfiles compile: */ - tcc_define_symbol(s, "__APPLE__", "1"); + /* emulate APPLE-GCC to make libc's headerfiles compile: */ + tcc_define_symbol(s, "__APPLE__", "1"); tcc_define_symbol(s, "__GNUC__", "4"); /* darwin emits warning on GCC<4 */ - + /* avoids usage of GCC/clang specific builtins in libc-headerfiles: */ tcc_define_symbol(s, "__FINITE_MATH_ONLY__", "1"); tcc_define_symbol(s, "_FORTIFY_SOURCE", "0"); -#endif /* ndef TCC_TARGET_MACHO */ tcc_define_symbol(s, "__builtin_va_list", "void *"); +#endif /* ndef TCC_TARGET_MACHO */ return s; } diff --git a/tcc.h b/tcc.h index a4506f41..6ff661eb 100644 --- a/tcc.h +++ b/tcc.h @@ -24,9 +24,9 @@ #define _GNU_SOURCE #include "config.h" +#include #include #include -#include #include #include #include