s117 / anycore-riscv

The AnyCore toolset targetting the RISC-V ISA
Other
0 stars 0 forks source link

Need linux toolchain to compile more SPEC benchmark #6

Closed s117 closed 4 years ago

s117 commented 4 years ago

Some SPEC2006 and SPEC2017 benchmarks written in C/C++ doesn't compile with newlib because of lacking function and headers.

Also, a bunch of SPEC floating point benchmarks is written in Fortran, which needs gfortran to compile.

The common solution is to bring up the Linux toolchain, which uses glibc and provides gfortran.

But glibc checks the version of the runtime environment by calling sys_uname. Our old PK failed to pass this checking. and cannot run the program compiled by Linux toolchain. A patch is needed.

$ riscv64-unknown-linux-gnu-gcc -static -Wl,-Ttext-segment,0x10000 -g helloworld.c -o helloworld

$ spike pk helloworld
Requesting target memory 0x100000000
******* Resetting core ********** 
****Initializing the processor system****
******* Resetting core ********** 
******* Resetting core ********** 
****Initialization complete****
FATAL: kernel too old
bad syscall array_size 1063 #178->0!
******* Resetting core **********

In glibc, the version checking is originated from https://github.com/s117/riscv-glibc/blob/06983fe52cfe8e4779035c27e8cc5d2caab31531/csu/libc-start.c#L217

s117 commented 4 years ago

https://github.com/s117/riscv-pk/commit/bf29abfa893b3885ede284afba58c809af5a37a7

Pulled sys_dup3 and sys_clock_gettime from upstream.

I didn't pull sys_chdir and sys_renameat, because they require changes to FESVR. If the new toolchain really needs them I will add it later though.

s117 commented 4 years ago

https://github.com/s117/riscv-pk/commit/07a6e7d342ed1eb1386ef98655f11f7c58bb2dcd After patched the PK to return a higher version string, the binary generated by the Linux toolchain starts working.

I return 4.15.1 because the latest PK returns 4.15.0.

$ riscv64-unknown-linux-gnu-gcc -static -Wl,-Ttext-segment,0x10000 -g helloworld.c -o helloworld

$ spike pk helloworld 
Requesting target memory 0x100000000
******* Resetting core ********** 
****Initializing the processor system****
******* Resetting core ********** 
******* Resetting core ********** 
****Initialization complete****
hello world
******* Resetting core **********

This patch is included by 0233947.

s117 commented 4 years ago

The minimal kernel version requirement seems defined here (not tested): https://github.com/s117/riscv-glibc/blob/c484da610d8d97ea8b8e14a9e35838bd68b7b5b8/sysdeps/unix/sysv/linux/riscv/configure.ac#L5