Hi everyone,
This is my first time using the mailing list/patching an open-source
program, so let me know if I am doing something wrong.

I was trying to build the riscv version of tcc while using the newlib
standard library for riscv provided by GCC and I ran into a couple of
issues. First, I wanted to make the cross compiler use the newlib library
by default and I believe using the `--sysincludepaths`, `--libpaths`, and
`--crtprefix` However, I found when I tried adding these options to the
`./configure` script, they had no effect on the tcc cross compiler.
(Command and output shown below)

```
../configure \
--prefix=$HOME/.local \
--sysincludepaths=/usr/riscv64-elf/include \
--libpaths=/usr/riscv64-elf/lib \
--crtprefix=/usr/riscv64-elf/lib
make cross-riscv64
```

TCC output
```
./riscv64-tcc -print-search-dirs
install: /home/nebk/.local/lib/tcc
include:
  /home/nebk/.local/lib/tcc/include
  /usr/local/include
  /usr/include
libraries:
  /usr/lib
  /lib
  /usr/local/lib
libtcc1:
  /home/nebk/.local/lib/tcc/riscv64-libtcc1.a
crt:
  /usr/lib
elfinterp:
  /lib/ld-linux-riscv64-lp64d.so.1
```

I put together a small patch that seems to fix the issue
(0001-Update-build-scripts.patch). It changes the `print_mak` function in
the configure script to output these options to the `EXTRA_DEFINES`
variable (a random name I chose) instead of the `NATIVE_DEFINES` variable.
Then the `EXTRA_DEFINES` variable is always appended to the total build
defines, so that is used for cross-compilers as well as the main tcc
compiler. With this change a few other lines could probably be removed from
the Makefile as well, but I wasn't brave enough to do it.

The next issue I ran into was errors when using `stdint.h`, (specifically a
file included by it `_intsup.h`). Many base definitions that are provided
by the gcc riscv compiler were missing (like __INT32_TYPE__) along with
some pointer size definitions. I added in the pointer size definitions
generally, and the other riscv definitions were copied from definitions by
the riscv gcc compiler. This is in
(0002-stdint-base-types-for-riscv-in-tccdef.h.patch).
The file contents for _intsup.h can be found here:
https://www.sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/sys/_intsup.h;h=993121ba890b2208eb83432daf741aa0ba598d30;hb=HEAD

Thanks,
-Sam Ellicott
Soli Deo Gloria
From 0d0a2083fa51693cc1a92f44b78aeee4f6e63aa4 Mon Sep 17 00:00:00 2001
From: Sam Ellicott <sellic...@cedarville.edu>
Date: Sun, 18 Jul 2021 18:56:37 -0400
Subject: [PATCH 2/2] stdint base types for riscv in tccdef.h

---
 include/tccdefs.h | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/tccdefs.h b/include/tccdefs.h
index ae0364e..a3d7219 100644
--- a/include/tccdefs.h
+++ b/include/tccdefs.h
@@ -24,6 +24,8 @@
 #else
     #define __SIZE_TYPE__ unsigned int
     #define __PTRDIFF_TYPE__ int
+    #define __UINTPTR_TYPE__ unsigned int 
+    #define __INTPTR_TYPE__ int 
 #endif
     #define __ILP32__ 1
     #define __INT64_TYPE__ long long
@@ -37,6 +39,8 @@
     /* Other 64bit systems. */
     #define __SIZE_TYPE__ unsigned long
     #define __PTRDIFF_TYPE__ long
+    #define __UINTPTR_TYPE__ long unsigned int
+    #define __INTPTR_TYPE__ long int
     #define __LP64__ 1
 # if defined __linux__
     #define __INT64_TYPE__ long
@@ -198,7 +202,37 @@
     #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 __INT32_TYPE__ int
+    #define __UINT_LEAST8_TYPE__ unsigned char
+    #define __SIG_ATOMIC_TYPE__ int
+    #define __UINTMAX_TYPE__ long unsigned int
+    #define __INT_FAST16_TYPE__ int
+    #define __INT_FAST64_TYPE__ long int
+    #define __UINT8_TYPE__ unsigned char
+    #define __INT_FAST32_TYPE__ int
+    #define __UINT_LEAST16_TYPE__ short unsigned int
+    #define __INT8_TYPE__ signed char
+    #define __INT_LEAST16_TYPE__ short int
+    #define __UINT_LEAST64_TYPE__ long unsigned int
+    #define __UINT_FAST16_TYPE__ unsigned int
+    #define __CHAR16_TYPE__ short unsigned int
+    #define __INT_LEAST64_TYPE__ long int
+    #define __INT16_TYPE__ short int
+    #define __INT_LEAST8_TYPE__ signed char
+    #define __UINT16_TYPE__ short unsigned int
+    #define __WCHAR_TYPE__ int
+    #define __UINT_FAST64_TYPE__ long unsigned int
+    #define __WINT_TYPE__ unsigned int
+    #define __UINT_LEAST32_TYPE__ unsigned int
+    #define __INT_LEAST32_TYPE__ int
+    #define __UINT64_TYPE__ long unsigned int
+    #define __INT_FAST8_TYPE__ int
+    #define __UINT_FAST32_TYPE__ unsigned int
+    #define __CHAR32_TYPE__ unsigned int
+    #define __INT32_TYPE__ int
+    #define __INTMAX_TYPE__ long int
+    #define __UINT32_TYPE__ unsigned int
+    #define __UINT_FAST8_TYPE__ unsigned int
 #else /* __i386__ */
     typedef char *__builtin_va_list;
     #define __builtin_va_start(ap,last) (ap = ((char *)&(last)) + ((sizeof(last)+3)&~3))
-- 
2.32.0

From 2a2ff66ccc229565f112fb13a97763e63fff23bd Mon Sep 17 00:00:00 2001
From: Sam Ellicott <sellic...@cedarville.edu>
Date: Sun, 18 Jul 2021 01:14:10 -0400
Subject: [PATCH 1/2] Update build scripts - print_mak uses EXTRA_DEFINES
 variable instead of NATIVE_DEFINES - Add EXTRA_DEFINES to compile options

---
 Makefile  | 2 +-
 configure | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 2a83a12..48d01d1 100644
--- a/Makefile
+++ b/Makefile
@@ -163,7 +163,7 @@ endif
 T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
 X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
 
-DEFINES += $(DEF-$T) $(DEF-all)
+DEFINES += $(DEF-$T) $(DEF-all) $(EXTRA_DEFINES)
 DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
 DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
 DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
diff --git a/configure b/configure
index 4c9e51e..d983815 100755
--- a/configure
+++ b/configure
@@ -475,7 +475,7 @@ print_mak() {
   local v="$2"
   if test -n "$v"; then
     test "$3" = "num" || v="\"\\\"$v\\\"\""
-    echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
+    echo "EXTRA_DEFINES+=-D$1=$v" >> config.mak
   fi
 }
 
-- 
2.32.0

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

Reply via email to