shithub: scc

Download patch

ref: 65014a8ce3a1b7d2b18c97bca389d17d83faff57
parent: 48a6d7f71087fc26fe03b357a22db8b93c6b7de6
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Sep 1 04:44:25 EDT 2018

[libc] Fix linking problems of printf

Printf was using symbols that are not defined. The support for wchar_t
is not finished.

--- /dev/null
+++ b/lib/c/errno.c
@@ -1,0 +1,1 @@
+int errno;
--- /dev/null
+++ b/lib/c/strnlen.c
@@ -1,0 +1,9 @@
+#include <string.h>
+
+#undef strnlen
+
+size_t
+strnlen(const char *s, size_t maxlen)
+{
+	return 0;
+}
--- a/lib/c/target/amd64-sysv-openbsd/syscall.mk
+++ b/lib/c/target/amd64-sysv-openbsd/syscall.mk
@@ -1,1 +1,1 @@
-SYSCALL = _Exit.o _read.o _write.o _open.o _close.o _brk.o _getpid.o _kill.o _sigaction.o _lseek.o 
+SYSCALL = _Exit.o _read.o _write.o _open.o _close.o _brk.o _getpid.o _sigaction.o _kill.o _lseek.o 
--- a/lib/c/target/script/objlst.mk
+++ b/lib/c/target/script/objlst.mk
@@ -19,7 +19,8 @@
          isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
          isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
          isxdigit.o toupper.o tolower.o ctype.o setlocale.o \
-         localeconv.o atoi.o atol.o atoll.o atexit.o abort.o exit.o
+         localeconv.o atoi.o atol.o atoll.o atexit.o abort.o exit.o \
+         errno.o strnlen.o wcsnlen.o
 
 #rules
 __abs.o: ../../__abs.c
@@ -76,6 +77,9 @@
 ctype.o: ../../ctype.c
 	$(CC) $(SCC_CFLAGS) ../../ctype.c -c
 
+errno.o: ../../errno.c
+	$(CC) $(SCC_CFLAGS) ../../errno.c -c
+
 exit.o: ../../exit.c
 	$(CC) $(SCC_CFLAGS) ../../exit.c -c
 
@@ -271,6 +275,9 @@
 strncpy.o: ../../strncpy.c
 	$(CC) $(SCC_CFLAGS) ../../strncpy.c -c
 
+strnlen.o: ../../strnlen.c
+	$(CC) $(SCC_CFLAGS) ../../strnlen.c -c
+
 strpbrk.o: ../../strpbrk.c
 	$(CC) $(SCC_CFLAGS) ../../strpbrk.c -c
 
@@ -306,4 +313,7 @@
 
 vsprintf.o: ../../vsprintf.c
 	$(CC) $(SCC_CFLAGS) ../../vsprintf.c -c
+
+wcsnlen.o: ../../wcsnlen.c
+	$(CC) $(SCC_CFLAGS) ../../wcsnlen.c -c
 
--- a/lib/c/vfprintf.c
+++ b/lib/c/vfprintf.c
@@ -128,6 +128,7 @@
 	int left = 0, adjust;
 	size_t cnt = 0;
 	wchar_t wc;
+#if 0
 
 	if (width < 0) {
 		left = 1;
@@ -148,7 +149,7 @@
 
 	for ( ; adjust < 0; adjust--)
 		putc(' ', fp);
-
+#endif
 	return cnt;
 }
 
--- /dev/null
+++ b/lib/c/wcsnlen.c
@@ -1,0 +1,10 @@
+#include <stdio.h>
+#include <wchar.h>
+
+#undef wcsnlen
+
+size_t
+wcsnlen(const wchar_t *s, size_t maxlen)
+{
+	return 0;
+}
--- a/tests/libc/execute/0001-abort.c
+++ b/tests/libc/execute/0001-abort.c
@@ -1,11 +1,14 @@
 
+#include <stdio.h>
 #include <signal.h>
 #include <stdlib.h>
 
+sig_atomic_t v;
+
 void
 handler(int dummy)
 {
-	exit(EXIT_SUCCESS);
+	v = 1;
 }
 
 int
@@ -13,6 +16,9 @@
 {
 	signal(SIGABRT, handler);
 	abort();
+
+	if (v == 1)
+		printf("ok\n");
 
 	return 1;
 }
--- /dev/null
+++ b/tests/libc/execute/0001-abort.txt
@@ -1,0 +1,1 @@
+ok
--- a/tests/libc/execute/cc.sh
+++ b/tests/libc/execute/cc.sh
@@ -17,6 +17,10 @@
 		sys=$2
 		shift 2
 		;;
+	-o)
+		out=$2
+		shift 2
+		;;
 	-*)
 		echo usage: cc.sh [-t target] file
 		exit 1
@@ -26,6 +30,7 @@
 
 sys=${sys:-`uname | tr 'A-Z' 'a-z'`}
 abi=${abi:-amd64-sysv}
+out=${out:-a.out}
 root=${root:-$SCCPREFIX}
 inc=$root/include/scc
 arch_inc=$root/include/scc/bits/$abi
@@ -32,5 +37,5 @@
 lib=$root/lib/scc/${abi}-${sys}
 obj=${1%.c}.o
 
-gcc -fno-stack-protector -std=c99 -static -nostdinc -I$inc -I$arch_inc -c $1
-ld -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc
+gcc -fno-stack-protector --freestanding -std=c99 -static -nostdinc -I$inc -I$arch_inc -c $1
+ld -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc -o $out
--- a/tests/libc/execute/chktest.sh
+++ b/tests/libc/execute/chktest.sh
@@ -1,16 +1,21 @@
 #!/bin/sh
 
 file=${1?' empty input file'}
-trap "rm -f a.out" 0 1 2 3 15
+tmp=`mktemp`
+#trap "rm -f a.out $tmp" 0 1 2 3 15
 ulimit -c 0
 rm -f test.log
 
 while read i state
 do
-	echo $i >>test.log
 	rm -f a.out
 
-	(./cc.sh $CFLAGS $i && ./a.out) 2>test.log &&
+	(echo
+	 echo $i
+	 ./cc.sh $CFLAGS $i.c &&
+	 ./a.out > $tmp &&
+	 cat $tmp
+	 diff -u $tmp $i.txt) > test.log 2>&1 &&
 	printf '[PASS]' || printf '[FAIL]'
 	printf '%s: %s\n' "$state" "$i"
 done < $file
--- a/tests/libc/execute/libc-tests.lst
+++ b/tests/libc/execute/libc-tests.lst
@@ -1,1 +1,1 @@
-0001-abort.c
+0001-abort