Ok I ve tried to test these changes under BSD systems, to make it
accepted by the system headers and all.

Kind regards.

On Thu, 26 Nov 2020 at 13:46, Christian Jullien <eli...@orange.fr> wrote:
>
> Yes, it would be fine.
> I have direct access to FreeBSD, NetBSD and OpenBSD x64 machines this way I 
> can check myself.
>
>
> -----Original Message-----
> From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] 
> On Behalf Of David CARLIER
> Sent: Thursday, November 26, 2020 14:43
> To: jull...@eligis.com; tinycc-devel@nongnu.org
> Subject: Re: [Tinycc-devel] [PATCH] DragonFlyBSD build fix proposal
>
> I just tried quickly FreeBSD, it fails for similar reasons than
> DragonFlyBSD minus the TLS one. I purposely focus only on DragonFlyBSD
> to make review easier do you prefer however an overall fix ?
>
> On Thu, 26 Nov 2020 at 13:38, Christian Jullien <eli...@orange.fr> wrote:
> >
> > It's really cool then, have you recently tried other BSD flavors: FreeBSD, 
> > OpenBSD and NetBSD?
> > I made few attempts in the past.
> >
> > -----Original Message-----
> > From: Tinycc-devel 
> > [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of 
> > David CARLIER
> > Sent: Thursday, November 26, 2020 14:18
> > To: jull...@eligis.com; tinycc-devel@nongnu.org
> > Subject: Re: [Tinycc-devel] [PATCH] DragonFlyBSD build fix proposal
> >
> > It works I was able to compile few programs with, tests fail in same
> > way as on Linux (current mob branch).
> >
> > On Thu, 26 Nov 2020 at 12:59, Christian Jullien <eli...@orange.fr> wrote:
> > >
> > > Thanks but are sure it really works passing all the tests?
> > > Few years ago I tried different BSD versions and, for one reason or 
> > > another, they all failed.
> > >
> > > -----Original Message-----
> > > From: Tinycc-devel 
> > > [mailto:tinycc-devel-bounces+eligis=orange...@nongnu.org] On Behalf Of 
> > > David CARLIER
> > > Sent: Thursday, November 26, 2020 13:53
> > > To: tinycc-devel@nongnu.org
> > > Subject: [Tinycc-devel] [PATCH] DragonFlyBSD build fix proposal
> > >
> > > Hi,
> > >
> > > here my first contribution, hope it is useful.
> > >
> > > Kind regards.
> > >
> > >
> > > _______________________________________________
> > > Tinycc-devel mailing list
> > > Tinycc-devel@nongnu.org
> > > https://lists.nongnu.org/mailman/listinfo/tinycc-devel
> >
> > _______________________________________________
> > Tinycc-devel mailing list
> > Tinycc-devel@nongnu.org
> > https://lists.nongnu.org/mailman/listinfo/tinycc-devel
> >
> >
> > _______________________________________________
> > Tinycc-devel mailing list
> > Tinycc-devel@nongnu.org
> > https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
> _______________________________________________
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
>
> _______________________________________________
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
From 8f08071e683fbdd915af88fcd7d583364450ea93 Mon Sep 17 00:00:00 2001
From: David Carlier <devne...@gmail.com>
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 <stdarg.h>
 #include <string.h>
 #include <setjmp.h>
+#include <pthread.h>
 
 #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 <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -40,11 +45,17 @@
 # include <unistd.h>
 # include <sys/time.h>
 # ifndef CONFIG_TCC_STATIC
+#  ifdef _TINYC_
+#   define __pure
+#  endif
 #  include <dlfcn.h>
 # 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

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to