tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] [PATCH v2] Adjust va_list to work with musl


From: Steffen Nurpmeso
Subject: [Tinycc-devel] [PATCH v2] Adjust va_list to work with musl
Date: Sat, 30 Sep 2017 16:34:14 +0200
Date: Sat, 30 Sep 2017 00:11:59 +0200
User-agent: mail v14.9.4

---
Changes:
  Well, just use the tcc_define_symbol() mechanism to prevent musl
  from doing its own stuff, and ensure va_list always gets
  defined, then.
  This requires the tcc stdarg.h to be found, though.
  The patch series works for the small test below regardless of
  what header is included first, and the MUA i maintain works when
  compiled with tcc, too.

    #include <stdio.h>
    #include <stdarg.h>
    void heu(int argc, ...);
    int main(void){heu(2, "one","two");return 0;}
    void heu(int argc, ...){
            va_list vl;
            va_start(vl, argc);
            while(argc-- != 0){
                    char const *cp = va_arg(vl, char const *);
                    fprintf(stderr, "%s\n", cp);
            }
            va_end(vl);
    }

 include/stdarg.h | 3 ++-
 libtcc.c         | 6 +++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/stdarg.h b/include/stdarg.h
index 9adfc61..a42acae 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
@@ -17,8 +17,9 @@ typedef struct {
 } __va_list_struct;
 
 /* Avoid conflicting definition for va_list on musl libc */
-#ifndef __DEFINED_va_list
+#if !defined __DEFINED_va_list || defined __TCC_NEEDS_va_list
 typedef __va_list_struct va_list[1];
+#undef __DEFINED_va_list
 #define __DEFINED_va_list
 #endif
 
diff --git a/libtcc.c b/libtcc.c
index 41c814d..dcc398f 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -854,7 +854,11 @@ LIBTCCAPI TCCState *tcc_new(void)
 #endif
 
 #if defined(TCC_MUSL)
-    tcc_define_symbol(s, "__builtin_va_list", "void *");
+    tcc_define_symbol(s, "__TCC_NEEDS_va_list", "");
+    tcc_define_symbol(s, "__builtin_va_list", "va_list");
+    tcc_define_symbol(s, "__DEFINED_va_list", "");
+    tcc_define_symbol(s, "__DEFINED___isoc_va_list", "");
+    tcc_define_symbol(s, "__isoc_va_list", "void *");
 #endif /* TCC_MUSL */
 
 #ifdef TCC_TARGET_PE
-- 
2.14.2


--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]