From 5d2f4cb4038696f93e1f2819da010d29f741fbac Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Fri, 22 May 2020 05:12:23 +0200 Subject: [PATCH] macos: various fixes * alloca needs to be _alloca * int64_t and uint64_t are also defined in but as long long, not as long, so adjust out to agree on Darwin * define __APPLE_CC__ so that correctly defines various macros like TARGET_OS_MAC and TARGET_CPU_X86_64 --- include/stddef.h | 5 +++-- lib/alloca86_64.S | 3 +++ libtcc.c | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/stddef.h b/include/stddef.h index f8561196..773006f9 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -17,7 +17,7 @@ typedef union { long long __ll; long double __ld; } max_align_t; typedef signed char int8_t; typedef signed short int int16_t; typedef signed int int32_t; -#ifdef __LP64__ +#if defined(__LP64__) && !defined(__APPLE__) typedef signed long int int64_t; #else typedef signed long long int int64_t; @@ -25,7 +25,7 @@ typedef signed long long int int64_t; typedef unsigned char uint8_t; typedef unsigned short int uint16_t; typedef unsigned int uint32_t; -#ifdef __LP64__ +#if defined(__LP64__) && !defined(__APPLE__) typedef unsigned long int uint64_t; #else typedef unsigned long long int uint64_t; @@ -36,6 +36,7 @@ typedef unsigned long long int uint64_t; #define NULL ((void*)0) #endif +#undef offsetof #define offsetof(type, field) ((size_t)&((type *)0)->field) void *alloca(size_t size); diff --git a/lib/alloca86_64.S b/lib/alloca86_64.S index a4aa173c..bb03233c 100644 --- a/lib/alloca86_64.S +++ b/lib/alloca86_64.S @@ -1,6 +1,9 @@ /* ---------------------------------------------- */ /* alloca86_64.S */ +#ifdef __APPLE__ +#define alloca _alloca +#endif .globl alloca alloca: diff --git a/libtcc.c b/libtcc.c index 256dfb68..8f95ace1 100644 --- a/libtcc.c +++ b/libtcc.c @@ -943,6 +943,7 @@ LIBTCCAPI TCCState *tcc_new(void) /* 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 */ + tcc_define_symbol(s, "__APPLE_CC__", "1"); /* for */ /* avoids usage of GCC/clang specific builtins in libc-headerfiles: */ tcc_define_symbol(s, "__FINITE_MATH_ONLY__", "1");