enable libstdc++fs & clock functions

This commit is contained in:
Dave Murphy 2018-06-05 16:43:16 +01:00
parent 789ec8cf00
commit e95e74c5bb
3 changed files with 282 additions and 79 deletions

View File

@ -1,6 +1,6 @@
#!/bin/bash
#---------------------------------------------------------------------------------
# devkitARM release 48
# devkitARM release 49
# devkitPPC release 30
# devkitA64 release 10
#---------------------------------------------------------------------------------

View File

@ -33,7 +33,7 @@ index 6da164352..f18f17447 100644
AS=${AS-as}
diff --git a/libgloss/libsysbase/Makefile.in b/libgloss/libsysbase/Makefile.in
new file mode 100644
index 000000000..7fd7357de
index 000000000..eaa11f765
--- /dev/null
+++ b/libgloss/libsysbase/Makefile.in
@@ -0,0 +1,148 @@
@ -104,12 +104,12 @@ index 000000000..7fd7357de
+ else t='$(program_transform_name)'; echo objcopy | sed -e $$t ; fi`
+
+# object files needed
+OBJS = abort.o iosupport.o close.o environ.o execve.o fork.o fstat.o getpid.o gettod.o \
+ isatty.o kill.o link.o lseek.o open.o read.o sbrk.o stat.o times.o \
+OBJS = abort.o iosupport.o clocks.o close.o environ.o execve.o fork.o fstat.o getpid.o gettod.o \
+ isatty.o kill.o link.o lseek.o lstat.o nanosleep.o open.o read.o sbrk.o sleep.o stat.o usleep.o times.o \
+ unlink.o wait.o write.o _exit.o malloc_vars.o \
+ chdir.o mkdir.o rename.o build_argv.o statvfs.o \
+ flock.o syscall_support.o handle_manager.o truncate.o ftruncate.o dirent.o fsync.o \
+ fchmod.o chmod.o getreent.o rmdir.o
+ fchmod.o chmod.o getreent.o rmdir.o utime.o
+
+# Object files specific to particular targets.
+EVALOBJS = ${OBJS}
@ -887,6 +887,46 @@ index 000000000..3668b5801
+ return ret;
+}
+
diff --git a/libgloss/libsysbase/clocks.c b/libgloss/libsysbase/clocks.c
new file mode 100644
index 000000000..01cfee469
--- /dev/null
+++ b/libgloss/libsysbase/clocks.c
@@ -0,0 +1,34 @@
+#include <errno.h>
+#include <time.h>
+#include <sys/iosupport.h>
+
+int clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+ if ( __syscalls.clock_gettime ) {
+ return __syscalls.clock_gettime(clock_id, tp);
+ } else {
+ errno = ENOSYS;
+ return -1;
+ }
+}
+
+int clock_settime(clockid_t clock_id, const struct timespec *tp)
+{
+ if ( __syscalls.clock_settime ) {
+ return __syscalls.clock_settime(clock_id, tp);
+ } else {
+ errno = ENOSYS;
+ return -1;
+ }
+}
+
+int clock_getres (clockid_t clock_id, struct timespec *res)
+{
+ if ( __syscalls.clock_getres ) {
+ return __syscalls.clock_getres(clock_id, res);
+ } else {
+ errno = ENOSYS;
+ return -1;
+ }
+}
+
diff --git a/libgloss/libsysbase/close.c b/libgloss/libsysbase/close.c
new file mode 100644
index 000000000..931ad07b1
@ -6140,10 +6180,10 @@ index 000000000..f3fcc88f7
+}
diff --git a/libgloss/libsysbase/iosupport.c b/libgloss/libsysbase/iosupport.c
new file mode 100644
index 000000000..4f131275e
index 000000000..948c6ef93
--- /dev/null
+++ b/libgloss/libsysbase/iosupport.c
@@ -0,0 +1,138 @@
@@ -0,0 +1,140 @@
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
@ -6194,6 +6234,8 @@ index 000000000..4f131275e
+ NULL, // chmod_r
+ NULL, // fchmod_r
+ NULL, // rmdir_r
+ NULL, // lstat_r
+ NULL, // utimes_r
+};
+
+//---------------------------------------------------------------------------------
@ -6422,6 +6464,43 @@ index 000000000..eb232c86b
+ return ret;
+
+}
diff --git a/libgloss/libsysbase/lstat.c b/libgloss/libsysbase/lstat.c
new file mode 100644
index 000000000..fc393430b
--- /dev/null
+++ b/libgloss/libsysbase/lstat.c
@@ -0,0 +1,31 @@
+#include "config.h"
+#include <_ansi.h>
+#include <_syslist.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/iosupport.h>
+#include <errno.h>
+
+
+//---------------------------------------------------------------------------------
+int lstat (const char *__restrict __path, struct stat *__restrict __buf ) {
+//---------------------------------------------------------------------------------
+ struct _reent *r = _REENT;
+ int dev,ret;
+
+ dev = FindDevice(__path);
+
+ if(dev!=-1) {
+ if (devoptab_list[dev]->lstat_r) {
+ r->deviceData = devoptab_list[dev]->deviceData;
+ ret = devoptab_list[dev]->lstat_r(r,__path,__buf);
+ } else {
+ r->_errno=ENOSYS;
+ }
+ } else {
+ ret = -1;
+ r->_errno = ENODEV;
+ }
+ return ret;
+}
+
diff --git a/libgloss/libsysbase/malloc_vars.c b/libgloss/libsysbase/malloc_vars.c
new file mode 100644
index 000000000..456590956
@ -6455,6 +6534,26 @@ index 000000000..b4fcbd3d7
+
+ return ret;
+}
diff --git a/libgloss/libsysbase/nanosleep.c b/libgloss/libsysbase/nanosleep.c
new file mode 100644
index 000000000..3c96fc61b
--- /dev/null
+++ b/libgloss/libsysbase/nanosleep.c
@@ -0,0 +1,14 @@
+#include <errno.h>
+#include <time.h>
+#include <sys/iosupport.h>
+
+int nanosleep(const struct timespec *req, struct timespec *rem)
+{
+ if ( __syscalls.nanosleep ) {
+ return __syscalls.nanosleep(req, rem);
+ } else {
+ *rem = *req;
+ errno = ENOSYS;
+ return -1;
+ }
+}
diff --git a/libgloss/libsysbase/open.c b/libgloss/libsysbase/open.c
new file mode 100644
index 000000000..f8d98fd3b
@ -6696,6 +6795,30 @@ index 000000000..5dd550c5c
+ heap_start += incr;
+ return (caddr_t) prev_heap_start;
+}
diff --git a/libgloss/libsysbase/sleep.c b/libgloss/libsysbase/sleep.c
new file mode 100644
index 000000000..f3aa97954
--- /dev/null
+++ b/libgloss/libsysbase/sleep.c
@@ -0,0 +1,18 @@
+/* Copied from libc/posix/sleep.c, removed the check for HAVE_NANOSLEEP */
+
+/* Written 2000 by Werner Almesberger */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+unsigned sleep(unsigned seconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = seconds;
+ ts.tv_nsec = 0;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
diff --git a/libgloss/libsysbase/stat.c b/libgloss/libsysbase/stat.c
new file mode 100644
index 000000000..d0ad00202
@ -6772,10 +6895,10 @@ index 000000000..84e221340
+}
diff --git a/libgloss/libsysbase/syscall_support.c b/libgloss/libsysbase/syscall_support.c
new file mode 100644
index 000000000..044f12d16
index 000000000..53fead72a
--- /dev/null
+++ b/libgloss/libsysbase/syscall_support.c
@@ -0,0 +1,99 @@
@@ -0,0 +1,103 @@
+#include <sys/iosupport.h>
+
+//---------------------------------------------------------------------------------
@ -6795,6 +6918,10 @@ index 000000000..044f12d16
+ NULL, // lock_release_recursive
+ NULL, // lock_close_recursive
+ NULL, // __getreent
+ NULL, // clock_gettime
+ NULL, // clock_settime
+ NULL, // clock_getres
+ NULL, // nanosleep
+};
+
+void __libc_lock_init(_LOCK_T *lock) {
@ -6998,6 +7125,81 @@ index 000000000..7920b79ac
+ return ret;
+}
+
diff --git a/libgloss/libsysbase/usleep.c b/libgloss/libsysbase/usleep.c
new file mode 100644
index 000000000..b54714775
--- /dev/null
+++ b/libgloss/libsysbase/usleep.c
@@ -0,0 +1,18 @@
+/* Copied from libc/posix/sleep.c, removed the check for HAVE_NANOSLEEP */
+
+/* Written 2000 by Werner Almesberger */
+
+#include <errno.h>
+#include <time.h>
+#include <unistd.h>
+
+int usleep(useconds_t useconds)
+{
+ struct timespec ts;
+
+ ts.tv_sec = (long int)useconds / 1000000;
+ ts.tv_nsec = ((long int)useconds % 1000000) * 1000;
+ if (!nanosleep(&ts,&ts)) return 0;
+ if (errno == EINTR) return ts.tv_sec;
+ return -1;
+}
diff --git a/libgloss/libsysbase/utime.c b/libgloss/libsysbase/utime.c
new file mode 100644
index 000000000..f72bf9fc6
--- /dev/null
+++ b/libgloss/libsysbase/utime.c
@@ -0,0 +1,45 @@
+#include "config.h"
+
+#include <errno.h>
+#include <stdio.h>
+#include <time.h>
+#include <utime.h>
+#include <sys/iosupport.h>
+
+int utimes(const char *filename, const struct timeval times[2])
+{
+ struct _reent *r = _REENT;
+ int dev,ret;
+
+ dev = FindDevice(filename);
+
+ if(dev!=-1) {
+ if (devoptab_list[dev]->utimes_r) {
+ r->deviceData = devoptab_list[dev]->deviceData;
+ ret = devoptab_list[dev]->utimes_r(r,filename,times);
+ } else {
+ r->_errno=ENOSYS;
+ }
+ } else {
+ ret = -1;
+ r->_errno = ENODEV;
+ }
+ return ret;
+
+
+
+}
+
+
+int utime(const char *filename, const struct utimbuf *times)
+{
+ struct timeval t[2];
+ if (times) {
+ t[0].tv_sec = times->actime;
+ t[0].tv_usec = 0;
+ t[1].tv_sec = times->modtime;
+ t[1].tv_usec = 0;
+ }
+
+ return utimes(filename, t);
+}
diff --git a/libgloss/libsysbase/wait.c b/libgloss/libsysbase/wait.c
new file mode 100644
index 000000000..247486e42
@ -7141,37 +7343,18 @@ index eb645868b..9cb69fde9 100644
syscall_dir=syscalls
;;
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index cbc0fa989..5de5d1b81 100644
index cbc0fa989..10960f912 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -227,13 +227,13 @@ int fgetpos (FILE *, _fpos_t *);
#else
int fgetpos (FILE *__restrict, fpos_t *__restrict);
#endif
-int fseek (FILE *, long, int);
+int fseek (FILE *, off_t, int);
#ifdef _COMPILING_NEWLIB
int fsetpos (FILE *, const _fpos_t *);
@@ -233,7 +233,7 @@ int fsetpos (FILE *, const _fpos_t *);
#else
int fsetpos (FILE *, const fpos_t *);
#endif
-long ftell ( FILE *);
+off_t ftell ( FILE *);
+long ftell ( FILE *);
void rewind (FILE *);
void clearerr (FILE *);
int feof (FILE *);
@@ -438,9 +438,9 @@ size_t _fread_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FIL
size_t _fread_unlocked_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
int _fscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
_ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
-int _fseek_r (struct _reent *, FILE *, long, int);
+int _fseek_r (struct _reent *, FILE *, off_t, int);
int _fseeko_r (struct _reent *, FILE *, _off_t, int);
-long _ftell_r (struct _reent *, FILE *);
+off_t _ftell_r (struct _reent *, FILE *);
_off_t _ftello_r (struct _reent *, FILE *);
void _rewind_r (struct _reent *, FILE *);
size_t _fwrite_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h
index 2082dfdb1..e535f189b 100644
--- a/newlib/libc/include/sys/config.h
@ -7246,12 +7429,26 @@ index a3fb5c02c..1ead46ba0 100644
#endif
+
+#endif // _dirent_h_
diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h
index 2900b332f..6efb54eb3 100644
--- a/newlib/libc/include/sys/features.h
+++ b/newlib/libc/include/sys/features.h
@@ -330,6 +330,9 @@ extern "C" {
# define __SSP_FORTIFY_LEVEL 0
#endif
+#define _POSIX_MONOTONIC_CLOCK 200112L
+#define _POSIX_TIMERS 1
+
/* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */
#ifdef __rtems__
diff --git a/newlib/libc/include/sys/iosupport.h b/newlib/libc/include/sys/iosupport.h
new file mode 100644
index 000000000..10a6a716d
index 000000000..ee14d2610
--- /dev/null
+++ b/newlib/libc/include/sys/iosupport.h
@@ -0,0 +1,105 @@
@@ -0,0 +1,112 @@
+//---------------------------------------------------------------------------------
+#ifndef __iosupp_h__
+#define __iosupp_h__
@ -7264,6 +7461,7 @@ index 000000000..10a6a716d
+#include <reent.h>
+#include <sys/stat.h>
+#include <sys/statvfs.h>
+#include <time.h>
+
+enum {
+ STD_IN,
@ -7316,6 +7514,8 @@ index 000000000..10a6a716d
+ int (*chmod_r)(struct _reent *r, const char *path, mode_t mode);
+ int (*fchmod_r)(struct _reent *r, void *fd, mode_t mode);
+ int (*rmdir_r)(struct _reent *r, const char *name);
+ int (*lstat_r)(struct _reent *r, const char *file, struct stat *st);
+ int (*utimes_r)(struct _reent *r, const char *filename, const struct timeval times[2]);
+
+} devoptab_t;
+
@ -7336,6 +7536,10 @@ index 000000000..10a6a716d
+ void (*lock_release_recursive) (_LOCK_RECURSIVE_T *lock);
+ void (*lock_close_recursive) (_LOCK_RECURSIVE_T *lock);
+ struct _reent *(*getreent) ();
+ int (*clock_gettime)(clockid_t clock_id, struct timespec *tp);
+ int (*clock_settime)(clockid_t clock_id, const struct timespec *tp);
+ int (*clock_getres)(clockid_t clock_id, struct timespec *res);
+ int (*nanosleep)(const struct timespec *req, struct timespec *rem);
+} __syscalls_t;
+
+extern __syscalls_t __syscalls;
@ -7378,6 +7582,21 @@ index 1ef226194..ce3721a14 100644
};
#ifdef _REENT_GLOBAL_STDIO_STREAMS
diff --git a/newlib/libc/include/sys/stat.h b/newlib/libc/include/sys/stat.h
index eee98db64..aed9c1746 100644
--- a/newlib/libc/include/sys/stat.h
+++ b/newlib/libc/include/sys/stat.h
@@ -152,8 +152,9 @@ int mkfifo (const char *__path, mode_t __mode );
int stat (const char *__restrict __path, struct stat *__restrict __sbuf );
mode_t umask (mode_t __mask );
-#if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
int lstat (const char *__restrict __path, struct stat *__restrict __buf );
+
+#if defined (__SPU__) || defined(__rtems__) || defined(__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
int mknod (const char *__path, mode_t __mode, dev_t __dev );
#endif
diff --git a/newlib/libc/include/sys/statvfs.h b/newlib/libc/include/sys/statvfs.h
new file mode 100644
index 000000000..380329d34
@ -7420,6 +7639,32 @@ index 000000000..380329d34
+
+#endif // _SYS_STATVFS_H
\ No newline at end of file
diff --git a/newlib/libc/include/sys/utime.h b/newlib/libc/include/sys/utime.h
index 5e937f103..635a7a6b8 100644
--- a/newlib/libc/include/sys/utime.h
+++ b/newlib/libc/include/sys/utime.h
@@ -9,12 +9,19 @@
extern "C" {
#endif
-struct utimbuf
+struct utimbuf
{
time_t actime;
- time_t modtime;
+ time_t modtime;
};
+/* Functions */
+
+int utime(
+ const char *path,
+ const struct utimbuf *times
+);
+
#ifdef __cplusplus
};
#endif
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index baa5451a6..a11f89473 100644
--- a/newlib/libc/locale/locale.c
@ -7730,50 +7975,6 @@ index b358d2b4a..29cec0229 100644
{
/* no more input: return partial result */
#ifdef __SCLE
diff --git a/newlib/libc/stdio/fseek.c b/newlib/libc/stdio/fseek.c
index 9b3ea986c..7c633e11f 100644
--- a/newlib/libc/stdio/fseek.c
+++ b/newlib/libc/stdio/fseek.c
@@ -83,7 +83,7 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
int
_fseek_r (struct _reent *ptr,
register FILE *fp,
- long offset,
+ off_t offset,
int whence)
{
return _fseeko_r (ptr, fp, offset, whence);
@@ -93,7 +93,7 @@ _fseek_r (struct _reent *ptr,
int
fseek (register FILE *fp,
- long offset,
+ off_t offset,
int whence)
{
return _fseek_r (_REENT, fp, offset, whence);
diff --git a/newlib/libc/stdio/ftell.c b/newlib/libc/stdio/ftell.c
index e4a246199..f73baab68 100644
--- a/newlib/libc/stdio/ftell.c
+++ b/newlib/libc/stdio/ftell.c
@@ -82,7 +82,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <errno.h>
#include "local.h"
-long
+off_t
_ftell_r (struct _reent *ptr,
register FILE * fp)
{
@@ -99,7 +99,7 @@ _ftell_r (struct _reent *ptr,
#ifndef _REENT_ONLY
-long
+off_t
ftell (register FILE * fp)
{
return _ftell_r (_REENT, fp);
diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c
index c4bf2dbe3..d756df37d 100644
--- a/newlib/libc/stdio/vfprintf.c

View File

@ -12,7 +12,7 @@ if [ ! -f configured-binutils ]
then
CFLAGS=$cflags LDFLAGS=$ldflags ../../binutils-$BINUTILS_VER/configure \
--prefix=$prefix --target=$target --disable-nls --disable-werror \
--enable-lto --enable-plugins --enable-poison-system-directories \
--enable-lto --enable-plugins --enable-gold \
$CROSS_PARAMS \
|| { echo "Error configuring binutils"; exit 1; }
touch configured-binutils
@ -56,13 +56,15 @@ then
--enable-threads --disable-win32-registry --disable-nls --disable-debug\
--disable-libmudflap --disable-libssp --disable-libgomp \
--disable-libstdcxx-pch \
--enable-libstdcxx-time=yes \
--enable-libstdcxx-filesystem-ts \
--target=$target \
--with-newlib \
--with-headers=../../newlib-$NEWLIB_VER/newlib/libc/include \
--prefix=$prefix \
--enable-lto\
--with-system-zlib \
--with-bugurl="http://wiki.devkitpro.org/index.php/Bug_Reports" --with-pkgversion="devkitARM release 48" \
--with-bugurl="http://wiki.devkitpro.org/index.php/Bug_Reports" --with-pkgversion="devkitARM release 49" \
$CROSS_PARAMS \
$CROSS_GCC_PARAMS \
|| { echo "Error configuring gcc"; exit 1; }