From dd0a0d779aacbc4d50f6b7dc73c98f3aa82cc68c Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 25 Jun 2019 19:05:58 +0200 Subject: [PATCH] build: Improve --with-system-libc support. * build-aux/build-lib.sh: Avoid building libc for --with-system-libc. Make libmes richer. build-aux/check-mescc.sh: Enable 50-malloc test. * include/dirstream.h: Use HAVE_DIRSTREAM_H to cater for non-existing dirstream.h. * include/grp.h[SYSTEM_LIBC]: Typo. * include/mes/lib.h (__brk, __call_at_exit)[SYSTEM_LIBC]: Declare. * include/stdlib.h (comparison_fn_t)[SYSTEM_LIBC]: Declare. * include/time.h (mktime): Return time_t. * lib/posix/isatty.c [SYSTEM_LIBC]: Do not (re)declare termios. * lib/stub/mktime.c (mktime): Return time_t. * lib/tests/scaffold/41-ternary.c (main): Remove assumption that locals are initialized. * lib/tests/scaffold/70-stdarg.c: Cater for SYSTEM_LIBC. * lib/tests/setjmp/80-setjmp.c: Declare jmp buf. * lib/*/*.c: Add missing mes/lib.h, errno.h includes. --- build-aux/build-lib.sh | 67 ++++++--------------------------- build-aux/check-mescc.sh | 1 + build-aux/test-c.sh | 2 +- include/dirstream.h | 2 +- include/grp.h | 2 +- include/mes/lib.h | 5 ++- include/stdlib.h | 10 ++--- include/time.h | 1 + lib/dirent/__getdirentries.c | 1 + lib/dirent/opendir.c | 1 + lib/posix/isatty.c | 2 + lib/stdio/clearerr.c | 2 + lib/stdio/fprintf.c | 1 + lib/stdio/perror.c | 1 + lib/stdio/printf.c | 3 +- lib/stdio/snprintf.c | 3 +- lib/stdio/sprintf.c | 3 +- lib/stdio/sscanf.c | 1 + lib/stdio/vprintf.c | 1 + lib/stub/chown.c | 1 + lib/stub/ctime.c | 1 + lib/stub/fpurge.c | 1 + lib/stub/freadahead.c | 1 + lib/stub/fscanf.c | 1 + lib/stub/getlogin.c | 1 + lib/stub/getpwnam.c | 1 + lib/stub/getpwuid.c | 3 +- lib/stub/gmtime.c | 1 + lib/stub/localtime.c | 1 + lib/stub/pclose.c | 1 + lib/stub/popen.c | 1 + lib/stub/rand.c | 2 +- lib/stub/rewind.c | 1 + lib/stub/setbuf.c | 1 + lib/stub/sigsetmask.c | 1 + lib/stub/sys_siglist.c | 1 + lib/stub/system.c | 1 + lib/stub/ttyname.c | 1 + lib/stub/umask.c | 1 + lib/stub/utime.c | 1 + lib/tests/io/90-stat.c | 1 + lib/tests/scaffold/41-ternary.c | 4 +- lib/tests/scaffold/70-stdarg.c | 6 +-- lib/tests/setjmp/80-setjmp.c | 1 + 44 files changed, 70 insertions(+), 75 deletions(-) diff --git a/build-aux/build-lib.sh b/build-aux/build-lib.sh index 073842ed..bf498547 100755 --- a/build-aux/build-lib.sh +++ b/build-aux/build-lib.sh @@ -52,6 +52,8 @@ fi libmes_SOURCES=" $libc_mini_SOURCES +lib/ctype/isnumber.c +lib/mes/abtol.c lib/mes/itoa.c lib/mes/ltoa.c lib/mes/ltoab.c @@ -70,12 +72,13 @@ lib/mes/oputc.c if test $mes_libc = mes; then libmes_SOURCES="$libmes_SOURCES lib/stdlib/atoi.c -lib/mes/abtol.c lib/ctype/isdigit.c -lib/ctype/isnumber.c lib/ctype/isspace.c lib/ctype/isxdigit.c " +else + libmes_SOURCES="$libmes_SOURCES +" fi libc_SOURCES=" @@ -184,55 +187,7 @@ lib/stub/ldexp.c lib/stub/mprotect.c lib/stub/localtime.c lib/stub/sigemptyset.c -lib/ctype/islower.c -lib/ctype/isupper.c -lib/ctype/tolower.c -lib/ctype/toupper.c -lib/mes/search-path.c -lib/posix/execvp.c -lib/stdio/fclose.c -lib/stdio/fdopen.c -lib/stdio/ferror.c -lib/stdio/fflush.c -lib/stdio/fopen.c -lib/stdio/fprintf.c -lib/stdio/fread.c -lib/stdio/fseek.c -lib/stdio/ftell.c -lib/stdio/fwrite.c -lib/stdio/printf.c -lib/stdio/remove.c -lib/stdio/snprintf.c -lib/stdio/sprintf.c -lib/stdio/sscanf.c -lib/stdio/vfprintf.c -lib/stdio/vprintf.c -lib/stdio/vsnprintf.c -lib/stdio/vsprintf.c -lib/stdio/vsscanf.c -lib/stdlib/calloc.c -lib/stdlib/qsort.c -lib/stdlib/strtof.c -lib/stdlib/strtol.c -lib/stdlib/strtold.c -lib/stdlib/strtoll.c -lib/stdlib/strtoul.c -lib/stdlib/strtoull.c -lib/string/memmem.c -lib/string/memmove.c -lib/string/strcat.c -lib/string/strchr.c -lib/string/strlwr.c -lib/string/strncpy.c -lib/string/strrchr.c -lib/string/strstr.c -lib/string/strupr.c -lib/stub/sigaction.c -lib/stub/ldexp.c -lib/stub/mprotect.c -lib/stub/localtime.c -lib/stub/sigemptyset.c -xslib/stub/strtod.c +lib/stub/strtod.c lib/$mes_cpu-mes-$compiler/setjmp.c " @@ -367,10 +322,12 @@ if test -e libmes.s; then cp libmes.s $mes_cpu-mes fi -archive libc.a $libc_SOURCES -cp libc.a $mes_cpu-mes -if test -e libc.s; then - cp libc.S $mes_cpu-mes +if test $mes_libc = mes; then + archive libc.a $libc_SOURCES + cp libc.a $mes_cpu-mes + if test -e libc.s; then + cp libc.s $mes_cpu-mes + fi fi archive libc+tcc.a $libc_tcc_SOURCES diff --git a/build-aux/check-mescc.sh b/build-aux/check-mescc.sh index f13d4047..0e328832 100755 --- a/build-aux/check-mescc.sh +++ b/build-aux/check-mescc.sh @@ -101,6 +101,7 @@ lib/tests/scaffold/48-global-static.c lib/tests/assert/50-assert.c lib/tests/mes/50-itoa.c lib/tests/posix/50-getenv.c +lib/tests/stdlib/50-malloc.c lib/tests/string/50-strcmp.c lib/tests/string/50-strcpy.c lib/tests/string/50-strncmp.c diff --git a/build-aux/test-c.sh b/build-aux/test-c.sh index 1ca2d1de..5f7e1dff 100755 --- a/build-aux/test-c.sh +++ b/build-aux/test-c.sh @@ -50,7 +50,7 @@ fi if test $mes_libc = system; then crt1= - LIBS=-lmes + LIBS='-l mes' else crt1=crt1.o fi diff --git a/include/dirstream.h b/include/dirstream.h index e67df35d..f648b96c 100644 --- a/include/dirstream.h +++ b/include/dirstream.h @@ -22,7 +22,7 @@ #ifndef __MES_DIRSTREAM_H #define __MES_DIRSTREAM_H 1 -#if SYSTEM_LIBC +#if SYSTEM_LIBC && HAVE_DIRSTREAM_H #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/include/grp.h b/include/grp.h index f77a5e45..a67e5227 100644 --- a/include/grp.h +++ b/include/grp.h @@ -22,7 +22,7 @@ #if SYSTEM_LIBC #undef __MES_GRP_H -#include_next +#include_next #else // ! SYSTEM_LIBC #include diff --git a/include/mes/lib.h b/include/mes/lib.h index dc4c0d2d..4af3da00 100644 --- a/include/mes/lib.h +++ b/include/mes/lib.h @@ -41,6 +41,7 @@ char * fdgets (char *s, int count, int fd); int fdputc (int c, int fd); int fdputs (char const *s, int fd); int fdungetc (int c, int fd); +int isnumber (int c, int base); int mes_open (char const *file_name, int flags, int mask); int _open2 (char const *file_name, int flags); int _open3 (char const *file_name, int flags, int mask); @@ -48,10 +49,10 @@ int oputc (int c); int oputs (char const *s); char *search_path (char const *file_name); -#if !SYSTEM_LIBC - extern char *__brk; extern void (*__call_at_exit) (void); + +#if !SYSTEM_LIBC void __assert_fail (char *s); void _exit (int code); long brk (void *addr); diff --git a/include/stdlib.h b/include/stdlib.h index fbc06660..391d0446 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -20,6 +20,11 @@ #ifndef __MES_STDLIB_H #define __MES_STDLIB_H 1 +#ifndef __MES_COMPARISON_FN_T +#define __MES_COMPARISON_FN_T +typedef int (*comparison_fn_t) (void const *, void const *); +#endif + #if SYSTEM_LIBC #ifndef _GNU_SOURCE #define _GNU_SOURCE @@ -56,11 +61,6 @@ unsigned long long strtoull (char const *string, char **tailptr, int base); #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 -#ifndef __MES_COMPARISON_FN_T -#define __MES_COMPARISON_FN_T -typedef int (*comparison_fn_t) (void const *, void const *); -#endif - void *bsearch (void const *key, void const *array, size_t count, size_t size, comparison_fn_t compare); #endif // ! SYSTEM_LIBC diff --git a/include/time.h b/include/time.h index ca3d9ff8..dc05b69f 100644 --- a/include/time.h +++ b/include/time.h @@ -59,6 +59,7 @@ struct timespec int clock_gettime (clockid_t clk_id, struct timespec *tp); struct tm *localtime (time_t const *timep); struct tm *gmtime (time_t const *time); +int nanosleep (struct timespec const *requested_time, struct timespec const *remaining); time_t time (time_t * tloc); #endif // ! SYSTEM_LIBC diff --git a/lib/dirent/__getdirentries.c b/lib/dirent/__getdirentries.c index 0c5d9250..16be95d4 100644 --- a/lib/dirent/__getdirentries.c +++ b/lib/dirent/__getdirentries.c @@ -21,6 +21,7 @@ // Taken from GNU C Library 1.06.4 +#include #include #include #include diff --git a/lib/dirent/opendir.c b/lib/dirent/opendir.c index 25b77e3d..f0916056 100644 --- a/lib/dirent/opendir.c +++ b/lib/dirent/opendir.c @@ -21,6 +21,7 @@ // Taken from GNU C Library 2.2.5 +#include #include #include #include diff --git a/lib/posix/isatty.c b/lib/posix/isatty.c index 85c84097..db2319ec 100644 --- a/lib/posix/isatty.c +++ b/lib/posix/isatty.c @@ -24,6 +24,7 @@ #include #include +#if !SYSTEM_LIBC typedef unsigned char cc_t; typedef unsigned int speed_t; typedef unsigned int tcflag_t; @@ -39,6 +40,7 @@ struct termios cc_t c_line; cc_t c_cc[NCCS]; }; +#endif struct ktermios { diff --git a/lib/stdio/clearerr.c b/lib/stdio/clearerr.c index 4c0729e9..f43ec712 100644 --- a/lib/stdio/clearerr.c +++ b/lib/stdio/clearerr.c @@ -18,6 +18,8 @@ * along with GNU Mes. If not, see . */ +#include +#include #include void diff --git a/lib/stdio/fprintf.c b/lib/stdio/fprintf.c index c1ec5ceb..7e4a904a 100644 --- a/lib/stdio/fprintf.c +++ b/lib/stdio/fprintf.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include diff --git a/lib/stdio/perror.c b/lib/stdio/perror.c index 21f0f1e4..3db9bb2b 100644 --- a/lib/stdio/perror.c +++ b/lib/stdio/perror.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include #include diff --git a/lib/stdio/printf.c b/lib/stdio/printf.c index 879c9a64..dd903479 100644 --- a/lib/stdio/printf.c +++ b/lib/stdio/printf.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include @@ -26,7 +27,7 @@ printf (char const *format, ...) { va_list ap; int r; -#if __GNUC__ && __x86_64__ +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC #define __FUNCTION_ARGS 1 ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; #undef __FUNCTION_ARGS diff --git a/lib/stdio/snprintf.c b/lib/stdio/snprintf.c index f62da341..b0c2bd5e 100644 --- a/lib/stdio/snprintf.c +++ b/lib/stdio/snprintf.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include @@ -26,7 +27,7 @@ snprintf (char *str, size_t size, char const *format, ...) { va_list ap; int r; -#if __GNUC__ && __x86_64__ +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC #define __FUNCTION_ARGS 3 ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; #undef __FUNCTION_ARGS diff --git a/lib/stdio/sprintf.c b/lib/stdio/sprintf.c index 6c130b15..38147d8b 100644 --- a/lib/stdio/sprintf.c +++ b/lib/stdio/sprintf.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include @@ -26,7 +27,7 @@ sprintf (char *str, char const *format, ...) { va_list ap; int r; -#if __GNUC__ && __x86_64__ +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC #define __FUNCTION_ARGS 2 ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; #undef __FUNCTION_ARGS diff --git a/lib/stdio/sscanf.c b/lib/stdio/sscanf.c index cf3714ce..0d1ed682 100644 --- a/lib/stdio/sscanf.c +++ b/lib/stdio/sscanf.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include diff --git a/lib/stdio/vprintf.c b/lib/stdio/vprintf.c index ff945943..7b0160d6 100644 --- a/lib/stdio/vprintf.c +++ b/lib/stdio/vprintf.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include diff --git a/lib/stub/chown.c b/lib/stub/chown.c index 3fc5e4c4..d04001fa 100644 --- a/lib/stub/chown.c +++ b/lib/stub/chown.c @@ -19,6 +19,7 @@ */ #include +#include #include int diff --git a/lib/stub/ctime.c b/lib/stub/ctime.c index 859fc36c..6b762edf 100644 --- a/lib/stub/ctime.c +++ b/lib/stub/ctime.c @@ -19,6 +19,7 @@ */ #include +#include #include int diff --git a/lib/stub/fpurge.c b/lib/stub/fpurge.c index 0b883a25..fb4782d7 100644 --- a/lib/stub/fpurge.c +++ b/lib/stub/fpurge.c @@ -19,6 +19,7 @@ */ #include +#include #include int diff --git a/lib/stub/freadahead.c b/lib/stub/freadahead.c index 0364f2e1..a79acb11 100644 --- a/lib/stub/freadahead.c +++ b/lib/stub/freadahead.c @@ -19,6 +19,7 @@ */ #include +#include #include size_t diff --git a/lib/stub/fscanf.c b/lib/stub/fscanf.c index c6497483..0973adc4 100644 --- a/lib/stub/fscanf.c +++ b/lib/stub/fscanf.c @@ -19,6 +19,7 @@ */ #include +#include #include int diff --git a/lib/stub/getlogin.c b/lib/stub/getlogin.c index 5420f320..602fcb03 100644 --- a/lib/stub/getlogin.c +++ b/lib/stub/getlogin.c @@ -19,6 +19,7 @@ */ #include +#include #include char * diff --git a/lib/stub/getpwnam.c b/lib/stub/getpwnam.c index c37d895f..2820251d 100644 --- a/lib/stub/getpwnam.c +++ b/lib/stub/getpwnam.c @@ -19,6 +19,7 @@ */ #include +#include #include struct passwd * diff --git a/lib/stub/getpwuid.c b/lib/stub/getpwuid.c index 4081ffa3..aa1b8617 100644 --- a/lib/stub/getpwuid.c +++ b/lib/stub/getpwuid.c @@ -19,10 +19,11 @@ */ #include +#include #include struct passwd * -getpwuid () +getpwuid (uid_t uid) { static int stub = 0; if (__mes_debug () && !stub) diff --git a/lib/stub/gmtime.c b/lib/stub/gmtime.c index c1b262b9..17c49f26 100644 --- a/lib/stub/gmtime.c +++ b/lib/stub/gmtime.c @@ -19,6 +19,7 @@ */ #include +#include #include #include diff --git a/lib/stub/localtime.c b/lib/stub/localtime.c index 308ef400..3b060cc2 100644 --- a/lib/stub/localtime.c +++ b/lib/stub/localtime.c @@ -19,6 +19,7 @@ */ #include +#include #include #include diff --git a/lib/stub/pclose.c b/lib/stub/pclose.c index 88806f6b..14f15bdd 100644 --- a/lib/stub/pclose.c +++ b/lib/stub/pclose.c @@ -19,6 +19,7 @@ */ #include +#include int pclose (int x) diff --git a/lib/stub/popen.c b/lib/stub/popen.c index ee4cf63d..77fd5f95 100644 --- a/lib/stub/popen.c +++ b/lib/stub/popen.c @@ -19,6 +19,7 @@ */ #include +#include int popen (int x) diff --git a/lib/stub/rand.c b/lib/stub/rand.c index 21365edb..cee6b599 100644 --- a/lib/stub/rand.c +++ b/lib/stub/rand.c @@ -19,7 +19,7 @@ */ #include -#include +#include int rand (void) diff --git a/lib/stub/rewind.c b/lib/stub/rewind.c index b0027551..db4000fd 100644 --- a/lib/stub/rewind.c +++ b/lib/stub/rewind.c @@ -19,6 +19,7 @@ */ #include +#include int rewind (int x) diff --git a/lib/stub/setbuf.c b/lib/stub/setbuf.c index b0d3e4bc..b038600a 100644 --- a/lib/stub/setbuf.c +++ b/lib/stub/setbuf.c @@ -19,6 +19,7 @@ */ #include +#include int setbuf (int x) diff --git a/lib/stub/sigsetmask.c b/lib/stub/sigsetmask.c index f455ce06..bded297c 100644 --- a/lib/stub/sigsetmask.c +++ b/lib/stub/sigsetmask.c @@ -19,6 +19,7 @@ */ #include +#include int sigsetmask (int x) diff --git a/lib/stub/sys_siglist.c b/lib/stub/sys_siglist.c index 97411002..885854ff 100644 --- a/lib/stub/sys_siglist.c +++ b/lib/stub/sys_siglist.c @@ -19,6 +19,7 @@ */ #include +#include int sys_siglist (int x) diff --git a/lib/stub/system.c b/lib/stub/system.c index 8cfdd1de..49663fb0 100644 --- a/lib/stub/system.c +++ b/lib/stub/system.c @@ -19,6 +19,7 @@ */ #include +#include int system (int x) diff --git a/lib/stub/ttyname.c b/lib/stub/ttyname.c index 018dbd2b..95e2ff95 100644 --- a/lib/stub/ttyname.c +++ b/lib/stub/ttyname.c @@ -19,6 +19,7 @@ */ #include +#include #include char * diff --git a/lib/stub/umask.c b/lib/stub/umask.c index ca2e2ec9..1544c089 100644 --- a/lib/stub/umask.c +++ b/lib/stub/umask.c @@ -19,6 +19,7 @@ */ #include +#include int umask (int x) diff --git a/lib/stub/utime.c b/lib/stub/utime.c index 06c8a67a..4306b97c 100644 --- a/lib/stub/utime.c +++ b/lib/stub/utime.c @@ -19,6 +19,7 @@ */ #include +#include int utime (int x) diff --git a/lib/tests/io/90-stat.c b/lib/tests/io/90-stat.c index 41820842..53031900 100644 --- a/lib/tests/io/90-stat.c +++ b/lib/tests/io/90-stat.c @@ -18,6 +18,7 @@ * along with GNU Mes. If not, see . */ +#include #include #include #include diff --git a/lib/tests/scaffold/41-ternary.c b/lib/tests/scaffold/41-ternary.c index 91053570..a5a0cb86 100644 --- a/lib/tests/scaffold/41-ternary.c +++ b/lib/tests/scaffold/41-ternary.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018,2019 Jan (janneke) Nieuwenhuizen * * This file is part of GNU Mes. * @@ -23,7 +23,7 @@ int main () { - int f; + int f = 0; int t = 1; int one = t; diff --git a/lib/tests/scaffold/70-stdarg.c b/lib/tests/scaffold/70-stdarg.c index 28182f11..30757721 100644 --- a/lib/tests/scaffold/70-stdarg.c +++ b/lib/tests/scaffold/70-stdarg.c @@ -30,7 +30,7 @@ stdarg1 (long *one, ...) int r; va_start (ap, one); -#if __GNUC__ && __x86_64__ +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC #define __FUNCTION_ARGS 1 ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; #undef __FUNCTION_ARGS @@ -54,7 +54,7 @@ stdarg2 (long *one, long *two, ...) int r; va_start (ap, two); -#if __GNUC__ && __x86_64__ +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC #define __FUNCTION_ARGS 2 ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; #undef __FUNCTION_ARGS @@ -78,7 +78,7 @@ stdarg3 (long *one, long *two, long *three, ...) int r; va_start (ap, three); -#if __GNUC__ && __x86_64__ +#if __GNUC__ && __x86_64__ && !SYSTEM_LIBC #define __FUNCTION_ARGS 3 ap += (__FOO_VARARGS + (__FUNCTION_ARGS << 1)) << 3; #undef __FUNCTION_ARGS diff --git a/lib/tests/setjmp/80-setjmp.c b/lib/tests/setjmp/80-setjmp.c index 1694ab21..fc118030 100644 --- a/lib/tests/setjmp/80-setjmp.c +++ b/lib/tests/setjmp/80-setjmp.c @@ -25,6 +25,7 @@ #include int foo; +jmp_buf buf; void second ()