mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
Make tcclib1.a compile on macOS again
When compiling on macOS (at least in version 10.12) the TCC compiler failed to compile libtcc1.a. Three problems were solved: - The predefined macro "__APPLE__" is now available, as it is tested in the libc darwin header files - the libtcc1 Makefile defined _ANSI_SOURCE, although it used signals - stdargs.h defined va_list differently from the darwin libc. If the darwin standard library was included BEFORE stdargs this caused problems. - the darwin libc generated a warning if GCC < 4 was used - additional defines are predefined now to make darwin libc headers compile.
This commit is contained in:
parent
38ab621b55
commit
1803762e3f
@ -4,22 +4,10 @@
|
|||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
#ifndef _WIN64
|
#ifndef _WIN64
|
||||||
|
|
||||||
//This should be in sync with the declaration on our lib/libtcc1.c
|
typedef __builtin_va_list va_list;
|
||||||
/* 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];
|
void __va_start(va_list ap, void *fp);
|
||||||
|
void *__va_arg(va_list ap, int arg_type, int size, int align);
|
||||||
void __va_start(__va_list_struct *ap, void *fp);
|
|
||||||
void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
|
|
||||||
|
|
||||||
#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
|
#define va_start(ap, last) __va_start(ap, __builtin_frame_address(0))
|
||||||
#define va_arg(ap, type) \
|
#define va_arg(ap, type) \
|
||||||
@ -27,9 +15,6 @@ void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
|
|||||||
#define va_copy(dest, src) (*(dest) = *(src))
|
#define va_copy(dest, src) (*(dest) = *(src))
|
||||||
#define va_end(ap) ((void)0)
|
#define va_end(ap) ((void)0)
|
||||||
|
|
||||||
/* avoid conflicting definition for va_list on Macs. */
|
|
||||||
#define _VA_LIST_T
|
|
||||||
|
|
||||||
#else /* _WIN64 */
|
#else /* _WIN64 */
|
||||||
typedef char *va_list;
|
typedef char *va_list;
|
||||||
#define va_start(ap,last) __builtin_va_start(ap,last)
|
#define va_start(ap,last) __builtin_va_start(ap,last)
|
||||||
|
@ -36,10 +36,6 @@ else
|
|||||||
DSO_O = dsohandle.o
|
DSO_O = dsohandle.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef CONFIG_OSX
|
|
||||||
XFLAGS += -D_ANSI_SOURCE
|
|
||||||
endif
|
|
||||||
|
|
||||||
I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BT_O)
|
I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BT_O)
|
||||||
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BT_O)
|
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BT_O)
|
||||||
ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o $(BT_O)
|
ARM_O = libtcc1.o armeabi.o alloca-arm.o armflush.o $(BT_O)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#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,14 +2,16 @@
|
|||||||
|
|
||||||
#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 */
|
||||||
enum __va_arg_type {
|
#define __VA_GEN_REG 0
|
||||||
__va_gen_reg, __va_float_reg, __va_stack
|
#define __VA_FLOAT_REG 1
|
||||||
};
|
#define __VA_STACK 2
|
||||||
|
|
||||||
/* GCC compatible definition of va_list. */
|
/* GCC compatible definition of va_list. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -22,43 +24,45 @@ typedef struct {
|
|||||||
char *reg_save_area;
|
char *reg_save_area;
|
||||||
} __va_list_struct;
|
} __va_list_struct;
|
||||||
|
|
||||||
void __va_start(__va_list_struct *ap, void *fp)
|
void __va_start(va_list ap, void *fp)
|
||||||
{
|
{
|
||||||
memset(ap, 0, sizeof(__va_list_struct));
|
__va_list_struct * _ap = (__va_list_struct*) ap;
|
||||||
*ap = *(__va_list_struct *)((char *)fp - 16);
|
memset(_ap, 0, sizeof(__va_list_struct));
|
||||||
ap->overflow_arg_area = (char *)fp + ap->overflow_offset;
|
*_ap = *(__va_list_struct *)((char *)fp - 16);
|
||||||
ap->reg_save_area = (char *)fp - 176 - 16;
|
_ap->overflow_arg_area = (char *)fp + _ap->overflow_offset;
|
||||||
|
_ap->reg_save_area = (char *)fp - 176 - 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *__va_arg(__va_list_struct *ap,
|
void *__va_arg(va_list ap,
|
||||||
enum __va_arg_type 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 happen */
|
default: /* should never h_appen */
|
||||||
abort();
|
abort();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
10
libtcc.c
10
libtcc.c
@ -927,6 +927,16 @@ LIBTCCAPI TCCState *tcc_new(void)
|
|||||||
/* Some GCC builtins that are simple to express as macros. */
|
/* Some GCC builtins that are simple to express as macros. */
|
||||||
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
|
||||||
|
/* 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 *");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user