[PUSHED] amdgcn: Provide stub 'gettimeofday'
Commit Message
Similar to nvptx commit 52cb9370044d11a29ae0dc1120ffdf246f5abc20
"nvptx: Provide stub 'gettimeofday'": instead of them FAILing due to
'ld: error: undefined symbol: gettimeofday', this makes PASS a number of GCC
'gfortran.dg' test cases, for example.
---
newlib/Makefile.in | 23 +++++++++++++++++++++--
newlib/libc/sys/amdgcn/Makefile.inc | 2 +-
newlib/libc/sys/amdgcn/gettimeofday.c | 9 +++++++++
3 files changed, 31 insertions(+), 3 deletions(-)
create mode 100644 newlib/libc/sys/amdgcn/gettimeofday.c
Comments
On 2026-04-13 15:40, Thomas Schwinge wrote:
> Similar to nvptx commit 52cb9370044d11a29ae0dc1120ffdf246f5abc20
> "nvptx: Provide stub 'gettimeofday'": instead of them FAILing due to
> 'ld: error: undefined symbol: gettimeofday', this makes PASS a number of GCC
> 'gfortran.dg' test cases, for example.
> ---
> newlib/Makefile.in | 23 +++++++++++++++++++++--
> newlib/libc/sys/amdgcn/Makefile.inc | 2 +-
> newlib/libc/sys/amdgcn/gettimeofday.c | 9 +++++++++
> 3 files changed, 31 insertions(+), 3 deletions(-)
> create mode 100644 newlib/libc/sys/amdgcn/gettimeofday.c
> diff --git a/newlib/libc/sys/amdgcn/gettimeofday.c b/newlib/libc/sys/amdgcn/gettimeofday.c
> new file mode 100644
> index 0000000000..8ce09a210c
> --- /dev/null
> +++ b/newlib/libc/sys/amdgcn/gettimeofday.c
> @@ -0,0 +1,9 @@
> +#include <sys/time.h>
> +#include <errno.h>
> +
> +int
> +gettimeofday (struct timeval *tv, void *tz)
> +{
> + errno = ENOSYS;
> + return -1;
> +}
Would be nice to make the declarations and definitions match POSIX (and Cygwin),
and add the embedded function docs like other man pages; see Timefns:
https://cygwin.com/git?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/time/time.tex
https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/time/time.c
and Posix:
https://cygwin.com/git?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/posix/posix.tex
https://cygwin.com/git?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/posix/popen.c
so they will be generated in the newlib libc info pages; see also:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages-posix.git/tree/man-pages-posix-2017/man3p/gettimeofday.3p
'\" et
.TH GETTIMEOFDAY "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" modified Linux -> newlib
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The newlib implementation of this interface may differ (consult
the corresponding newlib manual page for details of newlib behavior),
or the interface may not be implemented in newlib.
.\"
.SH NAME
gettimeofday
\(em get the date and time
SH SYNOPSIS
.LP
.nf
#include <sys/time.h>
.P
int gettimeofday(struct timeval *restrict \fItp\fP, void *restrict \fItzp\fP);
.fi
...
.SH "RETURN VALUE"
The
\fIgettimeofday\fR()
function shall return 0 and no value shall be reserved to indicate
an error.
.SH ERRORS
No errors are defined.
...
I notice that model arches seem to support both GPU component clock cycle counts
(TIME) and RTC constant frequency counts (REALTIME) instructions
S_MEM_REALTIME/TIME or registers (RDNA3+) that would allow implementations to
provide useful values.
Adjustments to Unix time are left as exercises for the implementers GD&R ;^>
On 2026-04-14 00:04, Brian Inglis wrote:
> On 2026-04-13 15:40, Thomas Schwinge wrote:
>> Similar to nvptx commit 52cb9370044d11a29ae0dc1120ffdf246f5abc20
>> "nvptx: Provide stub 'gettimeofday'": instead of them FAILing due to
>> 'ld: error: undefined symbol: gettimeofday', this makes PASS a number of GCC
>> 'gfortran.dg' test cases, for example.
>> ---
>> newlib/Makefile.in | 23 +++++++++++++++++++++--
>> newlib/libc/sys/amdgcn/Makefile.inc | 2 +-
>> newlib/libc/sys/amdgcn/gettimeofday.c | 9 +++++++++
>> 3 files changed, 31 insertions(+), 3 deletions(-)
>> create mode 100644 newlib/libc/sys/amdgcn/gettimeofday.c
>
>> diff --git a/newlib/libc/sys/amdgcn/gettimeofday.c b/newlib/libc/sys/amdgcn/
>> gettimeofday.c
>> new file mode 100644
>> index 0000000000..8ce09a210c
>> --- /dev/null
>> +++ b/newlib/libc/sys/amdgcn/gettimeofday.c
>> @@ -0,0 +1,9 @@
>> +#include <sys/time.h>
>> +#include <errno.h>
>> +
>> +int
>> +gettimeofday (struct timeval *tv, void *tz)
>> +{
>> + errno = ENOSYS;
>> + return -1;
>> +}
>
> Would be nice to make the declarations and definitions match POSIX (and Cygwin),
> and add the embedded function docs like other man pages; see Timefns:
>
> https://cygwin.com/git?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/time/time.tex
>
> https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/time/time.c
>
> and Posix:
>
> https://cygwin.com/git?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/posix/
> posix.tex
>
> https://cygwin.com/git?p=newlib-cygwin.git;a=blob_plain;f=newlib/libc/posix/popen.c
>
> so they will be generated in the newlib libc info pages; see also:
>
> https://git.kernel.org/pub/scm/docs/man-pages/man-pages-posix.git/tree/man-
> pages-posix-2017/man3p/gettimeofday.3p
>
> '\" et
> .TH GETTIMEOFDAY "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
> .\" modified Linux -> newlib
> .SH PROLOG
> This manual page is part of the POSIX Programmer's Manual.
> The newlib implementation of this interface may differ (consult
> the corresponding newlib manual page for details of newlib behavior),
> or the interface may not be implemented in newlib.
> .\"
> .SH NAME
> gettimeofday
> \(em get the date and time
> SH SYNOPSIS
> .LP
> .nf
> #include <sys/time.h>
> .P
> int gettimeofday(struct timeval *restrict \fItp\fP, void *restrict \fItzp\fP);
> .fi
> ...
> .SH "RETURN VALUE"
> The
> \fIgettimeofday\fR()
> function shall return 0 and no value shall be reserved to indicate
> an error.
> .SH ERRORS
> No errors are defined.
> ...
@@ -562,7 +562,7 @@ check_PROGRAMS =
@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@am__append_43 = \
@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/close.c libc/sys/amdgcn/fstat.c libc/sys/amdgcn/isatty.c libc/sys/amdgcn/lseek.c libc/sys/amdgcn/read.c libc/sys/amdgcn/write.c \
@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/fcntl.c libc/sys/amdgcn/getpid.c libc/sys/amdgcn/kill.c libc/sys/amdgcn/open.c libc/sys/amdgcn/raise.c libc/sys/amdgcn/stat.c \
-@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/unlink.c libc/sys/amdgcn/lock.c libc/sys/amdgcn/creat.c
+@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/unlink.c libc/sys/amdgcn/lock.c libc/sys/amdgcn/creat.c libc/sys/amdgcn/gettimeofday.c
@HAVE_LIBC_SYS_ARM_DIR_TRUE@am__append_44 = libc/sys/arm/access.c libc/sys/arm/aeabi_atexit.c libc/sys/arm/sysconf.c
@HAVE_LIBC_SYS_ARM_DIR_TRUE@@MAY_SUPPLY_SYSCALLS_TRUE@am__append_45 = libc/sys/arm/libcfunc.c libc/sys/arm/trap.S libc/sys/arm/syscalls.c
@@ -1670,7 +1670,8 @@ am__objects_51 = libc/ssp/libc_a-chk_fail.$(OBJEXT) \
@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/libc_a-stat.$(OBJEXT) \
@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/libc_a-unlink.$(OBJEXT) \
@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/libc_a-lock.$(OBJEXT) \
-@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/libc_a-creat.$(OBJEXT)
+@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/libc_a-creat.$(OBJEXT) \
+@HAVE_LIBC_SYS_AMDGCN_DIR_TRUE@ libc/sys/amdgcn/libc_a-gettimeofday.$(OBJEXT)
@HAVE_LIBC_SYS_ARM_DIR_TRUE@am__objects_55 = libc/sys/arm/libc_a-access.$(OBJEXT) \
@HAVE_LIBC_SYS_ARM_DIR_TRUE@ libc/sys/arm/libc_a-aeabi_atexit.$(OBJEXT) \
@HAVE_LIBC_SYS_ARM_DIR_TRUE@ libc/sys/arm/libc_a-sysconf.$(OBJEXT)
@@ -7327,6 +7328,9 @@ libc/sys/amdgcn/libc_a-lock.$(OBJEXT): \
libc/sys/amdgcn/libc_a-creat.$(OBJEXT): \
libc/sys/amdgcn/$(am__dirstamp) \
libc/sys/amdgcn/$(DEPDIR)/$(am__dirstamp)
+libc/sys/amdgcn/libc_a-gettimeofday.$(OBJEXT): \
+ libc/sys/amdgcn/$(am__dirstamp) \
+ libc/sys/amdgcn/$(DEPDIR)/$(am__dirstamp)
libc/sys/arm/$(am__dirstamp):
@$(MKDIR_P) libc/sys/arm
@: > libc/sys/arm/$(am__dirstamp)
@@ -13939,6 +13943,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-fcntl.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-fstat.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-getpid.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-isatty.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-kill.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@libc/sys/amdgcn/$(DEPDIR)/libc_a-lock.Po@am__quote@
@@ -31172,6 +31177,20 @@ libc/sys/amdgcn/libc_a-creat.obj: libc/sys/amdgcn/creat.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/sys/amdgcn/libc_a-creat.obj `if test -f 'libc/sys/amdgcn/creat.c'; then $(CYGPATH_W) 'libc/sys/amdgcn/creat.c'; else $(CYGPATH_W) '$(srcdir)/libc/sys/amdgcn/creat.c'; fi`
+libc/sys/amdgcn/libc_a-gettimeofday.o: libc/sys/amdgcn/gettimeofday.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/sys/amdgcn/libc_a-gettimeofday.o -MD -MP -MF libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Tpo -c -o libc/sys/amdgcn/libc_a-gettimeofday.o `test -f 'libc/sys/amdgcn/gettimeofday.c' || echo '$(srcdir)/'`libc/sys/amdgcn/gettimeofday.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Tpo libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libc/sys/amdgcn/gettimeofday.c' object='libc/sys/amdgcn/libc_a-gettimeofday.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/sys/amdgcn/libc_a-gettimeofday.o `test -f 'libc/sys/amdgcn/gettimeofday.c' || echo '$(srcdir)/'`libc/sys/amdgcn/gettimeofday.c
+
+libc/sys/amdgcn/libc_a-gettimeofday.obj: libc/sys/amdgcn/gettimeofday.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/sys/amdgcn/libc_a-gettimeofday.obj -MD -MP -MF libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Tpo -c -o libc/sys/amdgcn/libc_a-gettimeofday.obj `if test -f 'libc/sys/amdgcn/gettimeofday.c'; then $(CYGPATH_W) 'libc/sys/amdgcn/gettimeofday.c'; else $(CYGPATH_W) '$(srcdir)/libc/sys/amdgcn/gettimeofday.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Tpo libc/sys/amdgcn/$(DEPDIR)/libc_a-gettimeofday.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='libc/sys/amdgcn/gettimeofday.c' object='libc/sys/amdgcn/libc_a-gettimeofday.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/sys/amdgcn/libc_a-gettimeofday.obj `if test -f 'libc/sys/amdgcn/gettimeofday.c'; then $(CYGPATH_W) 'libc/sys/amdgcn/gettimeofday.c'; else $(CYGPATH_W) '$(srcdir)/libc/sys/amdgcn/gettimeofday.c'; fi`
+
libc/sys/arm/libc_a-access.o: libc/sys/arm/access.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/sys/arm/libc_a-access.o -MD -MP -MF libc/sys/arm/$(DEPDIR)/libc_a-access.Tpo -c -o libc/sys/arm/libc_a-access.o `test -f 'libc/sys/arm/access.c' || echo '$(srcdir)/'`libc/sys/arm/access.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) libc/sys/arm/$(DEPDIR)/libc_a-access.Tpo libc/sys/arm/$(DEPDIR)/libc_a-access.Po
@@ -1,4 +1,4 @@
libc_a_SOURCES += \
%D%/close.c %D%/fstat.c %D%/isatty.c %D%/lseek.c %D%/read.c %D%/write.c \
%D%/fcntl.c %D%/getpid.c %D%/kill.c %D%/open.c %D%/raise.c %D%/stat.c \
- %D%/unlink.c %D%/lock.c %D%/creat.c
+ %D%/unlink.c %D%/lock.c %D%/creat.c %D%/gettimeofday.c
new file mode 100644
@@ -0,0 +1,9 @@
+#include <sys/time.h>
+#include <errno.h>
+
+int
+gettimeofday (struct timeval *tv, void *tz)
+{
+ errno = ENOSYS;
+ return -1;
+}