Hi,

here my first contribution, hope it is useful.

Kind regards.
From d4ad25cefb7c18975c853dc43390108228f95e68 Mon Sep 17 00:00:00 2001
From: David Carlier <devne...@gmail.com>
Date: Thu, 26 Nov 2020 11:26:41 +0000
Subject: [PATCH] DragonFlyBSD build fix.

generates proper system constant.
errno uses TLS thus tccrun build breaks.
SYS_gettid is Linux specific, using pthread_self for simplicity.
---
 lib/bcheck.c | 6 ++++++
 libtcc.c     | 3 +++
 tcc.h        | 8 ++++++++
 3 files changed, 17 insertions(+)

diff --git a/lib/bcheck.c b/lib/bcheck.c
index 06c5b60..5bbab47 100644
--- a/lib/bcheck.c
+++ b/lib/bcheck.c
@@ -220,9 +220,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..454b566 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 */
diff --git a/tcc.h b/tcc.h
index 3c130ec..3c6ef2e 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>
@@ -45,6 +50,9 @@
 /* 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);
+# ifdef __DragonFly__
+extern char **environ;
+# endif
 #endif
 
 #ifdef _WIN32
-- 
2.28.0

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

Reply via email to