Closed abrodkin closed 5 months ago
@kolerov has kindly offered to look into this.
@abrodkin I see that _times
relies on gettimeofday
system call which is available in libgloss
environment. However, that system call is not even defined in semihosting specification for RISC-V (it uses ARM's set of semihosting system calls). In short, the implementation for libgloss
does not fit to semihosting interface. In short - there was no a motivation doing it. I can try to implement it without using gettimeofday
Here is the pull request which may fix this issue for semihosting: https://github.com/foss-for-synopsys-dwc-arc-processors/newlib/pull/59
Fixed with the most recent GNU toolchain build 6698.
$ riscv64-elf-gcc --version
riscv64-elf-gcc (RISC-V elf toolchain - build 6698) 14.0.1 20240226 (experimental)
$ riscv64-elf-gcc --specs=semihost.specs --specs=arcv.specs -mabi=ilp32 -mtune=rmx100 -march=rv32i -T arcv.ld clock.c
$ nm a.out | grep clock
000001f8 T clock
Consider the following example:
Try to compile it for RISC-V with
libsemihost
with help of ARC GNU tools for ARC-V processors 2023.12 (https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/tag/arc-2023.12-release):That happens because Newlib implements
clock()
(see https://github.com/bminor/newlib/blob/master/newlib/libc/time/clock.c#L53) with help of_times_r()
(see https://github.com/bminor/newlib/blob/master/newlib/libc/reent/timesr.c#L47), which in its turn uses_times()
, which is only implemented inlibgloss
(see https://github.com/bminor/newlib/blob/master/libgloss/riscv/sys_times.c#L22), but notlibsemihost
.So, if we want to use
clock()
(which is BTW is a valid C99 function) then we need to enhance Newlib to be capable of doing it withlibsemihost
for RISC-V.