From 8f08071e683fbdd915af88fcd7d583364450ea93 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 26 Nov 2020 11:26:41 +0000 Subject: [PATCH] BSD systems build fix. generates proper DragonFlyBSD system constant. errno uses TLS for DragonFlyBSD thus tccrun build breaks. SYS_gettid is Linux specific, using pthread_self for simplicity. --- lib/bcheck.c | 7 +++++++ libtcc.c | 6 +++++- tcc.h | 11 +++++++++++ tccrun.c | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/bcheck.c b/lib/bcheck.c index 06c5b60..df5d0c1 100644 --- a/lib/bcheck.c +++ b/lib/bcheck.c @@ -22,6 +22,7 @@ #include #include #include +#include #if !defined(__FreeBSD__) \ && !defined(__FreeBSD_kernel__) \ @@ -220,9 +221,15 @@ typedef struct alloca_list_struct { #define BOUND_TID_TYPE DWORD #define BOUND_GET_TID GetCurrentThreadId() #elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || defined(__riscv) +#if defined(__linux__) #define BOUND_TID_TYPE pid_t #define BOUND_GET_TID syscall (SYS_gettid) #else +// Note: each platform has its own thread id api, pthread_self might suffice for starter +#define BOUND_TID_TYPE int64_t +#define BOUND_GET_TID (int64_t)(pthread_self()) +#endif +#else #define BOUND_TID_TYPE int #define BOUND_GET_TID 0 #endif diff --git a/libtcc.c b/libtcc.c index 3698632..f7e364f 100644 --- a/libtcc.c +++ b/libtcc.c @@ -894,6 +894,9 @@ LIBTCCAPI TCCState *tcc_new(void) # if defined(__OpenBSD__) tcc_define_symbol(s, "__OpenBSD__", "__OpenBSD__"); # endif +# if defined(__DragonFly__) + tcc_define_symbol(s, "__DragonFly__", "__DragonFly__"); +# endif #endif /* TinyCC & gcc defines */ @@ -926,11 +929,12 @@ LIBTCCAPI TCCState *tcc_new(void) # if defined(__FreeBSD__) || defined (__FreeBSD_kernel__) \ || defined(__NetBSD__) || defined(__OpenBSD__) tcc_define_symbol(s, "__WINT_TYPE__", "int"); -# ifdef __FreeBSD__ +# if defined(__FreeBSD__) || defined(__NetBSD__) /* define __GNUC__ to have some useful stuff from sys/cdefs.h that are unconditionally used in FreeBSDs other system headers :/ */ tcc_define_symbol(s, "__GNUC__", "2"); tcc_define_symbol(s, "__GNUC_MINOR__", "7"); + tcc_define_symbol(s, "__GNUCLIKE_BUILTIN_VARARGS__", "1"); tcc_define_symbol(s, "__builtin_alloca", "alloca"); # endif # else diff --git a/tcc.h b/tcc.h index 3c130ec..2de8bc9 100644 --- a/tcc.h +++ b/tcc.h @@ -25,6 +25,11 @@ #define _DARWIN_C_SOURCE #include "config.h" +#ifdef __TINYC__ +// errno uses TLS unlike FreeBSD +#define __thread +#endif + #include #include #include @@ -40,11 +45,17 @@ # include # include # ifndef CONFIG_TCC_STATIC +# ifdef _TINYC_ +# define __pure +# endif # include # endif /* XXX: need to define this to use them in non ISOC99 context */ extern float strtof (const char *__nptr, char **__endptr); extern long double strtold (const char *__nptr, char **__endptr); +# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +extern char **environ; +# endif #endif #ifdef _WIN32 diff --git a/tccrun.c b/tccrun.c index 17f1eeb..0e8793c 100644 --- a/tccrun.c +++ b/tccrun.c @@ -648,6 +648,9 @@ static void rt_getcontext(ucontext_t *uc, rt_context *rc) # elif defined(__NetBSD__) rc->ip = uc->uc_mcontext.__gregs[_REG_RIP]; rc->fp = uc->uc_mcontext.__gregs[_REG_RBP]; +# elif defined(__OpenBSD__) + rc->ip = uc->sc_rip; + rc->fp = uc->uc_rbp; # else rc->ip = uc->uc_mcontext.gregs[REG_RIP]; rc->fp = uc->uc_mcontext.gregs[REG_RBP]; -- 2.28.0