ReturnInfinity / BareMetal-OS-legacy

BareMetal is a 64-bit OS for x86-64 based computers. The OS is written entirely in Assembly while applications can be written in Assembly, C/C++, and Rust.
1.74k stars 302 forks source link

Provide a minimal implementation of the newlib syscalls times function #77

Closed vilhelmgray closed 9 years ago

vilhelmgray commented 9 years ago

The newlib syscalls times function is undefined for BareMetal; this causes problems when trying to link a program that calls a standard C library function that depends on the times function, such as the standard C library clock function.

Take for example the following C program:

#include <stdio.h>
#include <time.h>

int main(void){
    printf("%u\n", (unsigned)clock());
    return 0;
}

The following error occurs:

root@debian:# gcc -std=c99 -pedantic -I newlib-2.2.0/newlib/libc/include/ -c clocktest.c -o clocktest.o
root@debian:# ld -T app.ld -o clocktest.app crt0.o clocktest.o libc.a 
libc.a(lib_a-timesr.o): In function `_times_r':
/root/BareMetal/newlib/build/x86_64-pc-baremetal/newlib/libc/reent/../../../../../newlib-2.2.0/newlib/libc/reent/timesr.c:60: undefined reference to `times'

Although this is only a minimal implementation of the times function, it will allow programs that depends on the times function to link and fail gracefully.