[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] lib: define va_* for bootstrappable tcc in riscv
From: |
Ekaitz Zarraga |
Subject: |
[PATCH] lib: define va_* for bootstrappable tcc in riscv |
Date: |
Wed, 11 Oct 2023 18:01:44 +0000 |
>From 925db8452301e1cae0db3b265791de626b736b2d Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <ekaitz@elenq.tech>
Date: Wed, 11 Oct 2023 15:53:08 +0200
Subject: [PATCH] lib: define va_* for bootstrappable tcc in riscv
Bootstrappable TCC needs some extra definitions that upstream TCC
obtains from `tccdefs.h` in its codebase, which is also injected in the
binary using a weird trick (see `c2str` in tcc's codebase).
* include/stdarg.h: Add definitions for variable length arguments.
---
include/stdarg.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/stdarg.h b/include/stdarg.h
index 090aebe1..98b168a9 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
@@ -32,6 +32,21 @@
// GCC on RISC-V always passes arguments in registers. Implementing these
macros without
// the use of built-ins would be very involved.
// TINYCC tries to be GCC compatible in this case.
+
+#if __TINYC__ < 928
+// Bootstrappable TINYCC (version < 928) needs some definitions in RISC-V
+typedef char *__builtin_va_list;
+#define __va_reg_size (__riscv_xlen >> 3)
+#define _tcc_align(addr,type) (((unsigned long)addr + __alignof__(type) - 1) \
+ & -(__alignof__(type)))
+#define __builtin_va_arg(ap,type) (*(sizeof(type) > (2*__va_reg_size) ? *(type
**)((ap += __va_reg_size) - __va_reg_size) : (ap =
(va_list)(_tcc_align(ap,type) + (sizeof(type)+__va_reg_size - 1)&
-__va_reg_size), (type *)(ap - ((sizeof(type)+ __va_reg_size - 1)&
-__va_reg_size)))))
+
+#define __builtin_va_end(ap) (void)(ap)
+#ifndef __builtin_va_copy
+# define __builtin_va_copy(dest, src) (dest) = (src)
+#endif
+#endif
+
typedef __builtin_va_list va_list;
#define va_start(v,l) __builtin_va_start(v,l)
--
2.41.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] lib: define va_* for bootstrappable tcc in riscv,
Ekaitz Zarraga <=