mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
Fix stdarg on x86-64
this partly reverts 1803762e3
to fix stdarg on x86-64 again. I've tried
to retain the apple specific changes from that commit.
Also include stdarg.h first in tcc.h, maybe that helps as well.
This commit is contained in:
parent
1803762e3f
commit
8c6143d86f
@ -4,7 +4,24 @@
|
|||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
#ifndef _WIN64
|
#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;
|
typedef __builtin_va_list va_list;
|
||||||
|
#endif
|
||||||
|
|
||||||
void __va_start(va_list ap, void *fp);
|
void __va_start(va_list ap, void *fp);
|
||||||
void *__va_arg(va_list ap, int arg_type, int size, int align);
|
void *__va_arg(va_list ap, int arg_type, int size, int align);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
/* function to get a stack backtrace on demand with a message */
|
/* function to get a stack backtrace on demand with a message */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
int (*__rt_error)(void*, void*, const char *, va_list);
|
int (*__rt_error)(void*, void*, const char *, va_list);
|
||||||
|
|
||||||
|
@ -2,16 +2,14 @@
|
|||||||
|
|
||||||
#if defined __x86_64__
|
#if defined __x86_64__
|
||||||
|
|
||||||
#include "stdarg.h"
|
|
||||||
|
|
||||||
/* Avoid include files, they may not be available when cross compiling */
|
/* Avoid include files, they may not be available when cross compiling */
|
||||||
extern void *memset(void *s, int c, __SIZE_TYPE__ n);
|
extern void *memset(void *s, int c, __SIZE_TYPE__ n);
|
||||||
extern void abort(void);
|
extern void abort(void);
|
||||||
|
|
||||||
/* This should be in sync with our include/stdarg.h */
|
/* This should be in sync with our include/stdarg.h */
|
||||||
#define __VA_GEN_REG 0
|
enum __va_arg_type {
|
||||||
#define __VA_FLOAT_REG 1
|
__va_gen_reg, __va_float_reg, __va_stack
|
||||||
#define __VA_STACK 2
|
};
|
||||||
|
|
||||||
/* GCC compatible definition of va_list. */
|
/* GCC compatible definition of va_list. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -24,45 +22,43 @@ typedef struct {
|
|||||||
char *reg_save_area;
|
char *reg_save_area;
|
||||||
} __va_list_struct;
|
} __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));
|
||||||
memset(_ap, 0, sizeof(__va_list_struct));
|
*ap = *(__va_list_struct *)((char *)fp - 16);
|
||||||
*_ap = *(__va_list_struct *)((char *)fp - 16);
|
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
|
||||||
_ap->overflow_arg_area = (char *)fp + _ap->overflow_offset;
|
ap->reg_save_area = (char *)fp - 176 - 16;
|
||||||
_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 arg_type,
|
||||||
int size, int align)
|
int size, int align)
|
||||||
{
|
{
|
||||||
__va_list_struct * _ap = (__va_list_struct*) ap;
|
|
||||||
size = (size + 7) & ~7;
|
size = (size + 7) & ~7;
|
||||||
align = (align + 7) & ~7;
|
align = (align + 7) & ~7;
|
||||||
switch (arg_type) {
|
switch (arg_type) {
|
||||||
case __VA_GEN_REG:
|
case __va_gen_reg:
|
||||||
if (_ap->gp_offset + size <= 48) {
|
if (ap->gp_offset + size <= 48) {
|
||||||
_ap->gp_offset += size;
|
ap->gp_offset += size;
|
||||||
return _ap->reg_save_area + _ap->gp_offset - size;
|
return ap->reg_save_area + ap->gp_offset - size;
|
||||||
}
|
}
|
||||||
goto use_overflow_area;
|
goto use_overflow_area;
|
||||||
|
|
||||||
case __VA_FLOAT_REG:
|
case __va_float_reg:
|
||||||
if (_ap->fp_offset < 128 + 48) {
|
if (ap->fp_offset < 128 + 48) {
|
||||||
_ap->fp_offset += 16;
|
ap->fp_offset += 16;
|
||||||
return _ap->reg_save_area + _ap->fp_offset - 16;
|
return ap->reg_save_area + ap->fp_offset - 16;
|
||||||
}
|
}
|
||||||
size = 8;
|
size = 8;
|
||||||
goto use_overflow_area;
|
goto use_overflow_area;
|
||||||
|
|
||||||
case __VA_STACK:
|
case __va_stack:
|
||||||
use_overflow_area:
|
use_overflow_area:
|
||||||
_ap->overflow_arg_area += size;
|
ap->overflow_arg_area += size;
|
||||||
_ap->overflow_arg_area = (char*)((long long)(_ap->overflow_arg_area + align - 1) & -align);
|
ap->overflow_arg_area = (char*)((long long)(ap->overflow_arg_area + align - 1) & -align);
|
||||||
return _ap->overflow_arg_area - size;
|
return ap->overflow_arg_area - size;
|
||||||
|
|
||||||
default: /* should never h_appen */
|
default: /* should never happen */
|
||||||
abort();
|
abort();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
8
libtcc.c
8
libtcc.c
@ -928,15 +928,15 @@ LIBTCCAPI TCCState *tcc_new(void)
|
|||||||
tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x");
|
tcc_define_symbol(s, "__builtin_extract_return_addr(x)", "x");
|
||||||
#endif /* ndef TCC_TARGET_PE */
|
#endif /* ndef TCC_TARGET_PE */
|
||||||
#ifdef TCC_TARGET_MACHO
|
#ifdef TCC_TARGET_MACHO
|
||||||
/* emulate APPLE-GCC to make libc's headerfiles compile: */
|
/* emulate APPLE-GCC to make libc's headerfiles compile: */
|
||||||
tcc_define_symbol(s, "__APPLE__", "1");
|
tcc_define_symbol(s, "__APPLE__", "1");
|
||||||
tcc_define_symbol(s, "__GNUC__", "4"); /* darwin emits warning on GCC<4 */
|
tcc_define_symbol(s, "__GNUC__", "4"); /* darwin emits warning on GCC<4 */
|
||||||
|
|
||||||
/* avoids usage of GCC/clang specific builtins in libc-headerfiles: */
|
/* avoids usage of GCC/clang specific builtins in libc-headerfiles: */
|
||||||
tcc_define_symbol(s, "__FINITE_MATH_ONLY__", "1");
|
tcc_define_symbol(s, "__FINITE_MATH_ONLY__", "1");
|
||||||
tcc_define_symbol(s, "_FORTIFY_SOURCE", "0");
|
tcc_define_symbol(s, "_FORTIFY_SOURCE", "0");
|
||||||
#endif /* ndef TCC_TARGET_MACHO */
|
|
||||||
tcc_define_symbol(s, "__builtin_va_list", "void *");
|
tcc_define_symbol(s, "__builtin_va_list", "void *");
|
||||||
|
#endif /* ndef TCC_TARGET_MACHO */
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
tcc.h
2
tcc.h
@ -24,9 +24,9 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user