[PATCH] Emulate clock and other stubs on nvptx

Roger Sayle roger@nextmovesoftware.com
Wed Aug 18 16:43:20 GMT 2021


Please be gentle, this is my first patch to newlib.

This patch to the libc/machine/nvptx port of newlib implements an
approximation
of "clock" and provides some additional stub routines.  These changes not
only
reduce the number of (link) failures in the GCC testsuite when targeting
nvptx-none,
but also allow the NIST scimark4 benchmark to compile and run without
modification.

newlib already contains support for backends to provide their own clock
implementations
via -DCLOCK_PROVIDED.  That functionality is used here to return an
approximate
elapsed time based on the NVidia GPU's clock64 cycle counter.  Although not
great,
this is better than the current behaviour of link error from the unresolved
symbol
_times_r.

The other part of the patch is to add a small number of stub functions to
nvptx's
misc.c.  Adding isatty, for example, resolves linking problems in libc from
the
dependency in __smakebuf_r, and the sync stub, for example, fixes the
failure
with GCC's testsuite/gfortran.dg/ISO_Fortran_binding_14.f90 [which simply
tests that gfortran can call a/any C function].

Hopefully, these changes are acceptable.  If so, if someone could please
commit
them for me that would be much appreciated (as I don't have repository
access).
Likewise, these changes should be obvious enough to not require a copyright
assignment, but to avoid any objections, I'm happy to put them in the public
domain.

2021-08-18  Roger Sayle  <roger@nextmovesoftware.com>

newlib/
	configure.host: Add -DCLOCK_PROVIDED to newlib_cflags on nvptx*.

newlib/libc/machine/nvptx
	Makefile.am: Add clock.c to lib_a_SOURCES.
	clock.c: New source file to implement/approximate clock().
	misc.c: Add stubs for fstat, isatty, open, sync and unlink.
	Makefile.in: Regenerate.

Many thanks in advance,
Roger
--
Roger Sayle
NextMove Software Limited
Cambridge, UK

-------------- next part --------------
A non-text attachment was scrubbed...
Name: newlib.patch
Type: application/octet-stream
Size: 1662 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20210818/5961a106/attachment.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: clock.c
URL: <https://sourceware.org/pipermail/newlib/attachments/20210818/5961a106/attachment.c>


More information about the Newlib mailing list