Issues cross-compiling on WSL2 -> RISCV in order to simulate with GEM5

74 Views Asked by At

sorry if i'm a newbie and maybe i didn't used the interface properly. I'm developing a project for uni where i have to simulate a RISCV-based OoO CPU executing a C benchmark. As Gem5 have to be compiled and ran on Linux, but VMs were too slow, i decided to use WSL2 included in Windows11, with Ubuntu-22.04. I cloned the git repository and successfully compiler gem5 for RISCV architecture. However, the problem is not with Gem5 apparently: when i run my script, the compilation of the main.c (benchmark) fails, not generating the .elf file and reporting this:

alessandro@DESKTOP-B2O2HHH:/opt/ase_riscv_gem5_sim$ /sudo ./simulate.sh -i ./programs/my_c_benchmark/ -nogui
Simulating my_c_benchmark
Compiling program my_c_benchmark
CLEAN my_c_benchmark.elf obj/main.o
/usr/bin/riscv64-linux-gnu-gcc-11 $OPTIMIZATION_FLAGS -mcmodel=medlow  -march=rv64g -mabi=lp64d  -static -Wall -Wextra -D_GEM5_ -I$GEM5_SRC/include -I$GEM5_SRC/include/gem5/asm/generic -nostartfiles  -T./linker.ld  -lc -L$CC_INSTALLATION_PATH/lib -c -o obj/main.o main.c
main.c: In function ‘main’:
main.c:26:21: warning: variable ‘v7’ set but not used [-Wunused-but-set-variable]
   26 |     volatile double v7[N];
      |                     ^~
/usr/bin/riscv64-linux-gnu-gcc-11 -o $program.elf   $GEM5_SRC/util/m5/src/abi/riscv/m5op.S ./crt0.S  obj/main.o  $OPTIMIZATION_FLAGS -mcmodel=medlow  -march=rv64g -mabi=lp64d  -static -Wall -Wextra -D_GEM5_ -I$GEM5_SRC/include -I$GEM5_SRC/include/gem5/asm/generic -nostartfiles  -T./linker.ld  -lc -L$CC_INSTALLATION_PATH/lib
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: /usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/lib/libc.a(libc-start.o): in function `.L0 ':
(.text+0x4): undefined reference to `__fini_array_start'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: (.text+0xc): undefined reference to `__fini_array_end'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: (.text+0x15e): undefined reference to `__ehdr_start'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: (.text+0x2a6): undefined reference to `__preinit_array_start'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: (.text+0x2ae): undefined reference to `__preinit_array_end'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: (.text+0x2da): undefined reference to `__init_array_start'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: (.text+0x2e2): undefined reference to `__init_array_end'
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: my_c_benchmark.elf: hidden symbol `__fini_array_end' isn't defined
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make: *** [Makefile:38: $program.elf] Error 1
Simulating program my_c_benchmark
/opt/gem5/build/RISCV/gem5.opt --debug-flags=O3PipeView,O3CPUAll  --debug-file=/opt/ase_riscv_gem5_sim/results/my_c_benchmark/trace.out --outdir=/opt/ase_riscv_gem5_sim/results/my_c_benchmark/ --verbose  ./gem5/riscv_o3_custom.py --caches  -c ./programs/my_c_benchmark//my_c_benchmark.elf --directory=/opt/ase_riscv_gem5_sim/results/my_c_benchmark  --errout=/opt/ase_riscv_gem5_sim/results/my_c_benchmark/programm.err
gem5 Simulator System.  https://www.gem5.org
gem5 is copyrighted software; use the --copyright option for details.

gem5 version 23.0.1.0
gem5 compiled Nov 16 2023 15:48:41
gem5 started Nov 16 2023 16:02:12
gem5 executing on DESKTOP-B2O2HHH, pid 23025
command line: /opt/gem5/build/RISCV/gem5.opt --debug-flags=O3PipeView,O3CPUAll --debug-file=/opt/ase_riscv_gem5_sim/results/my_c_benchmark/trace.out --outdir=/opt/ase_riscv_gem5_sim/results/my_c_benchmark/ --verbose ./gem5/riscv_o3_custom.py --caches -c ./programs/my_c_benchmark//my_c_benchmark.elf --directory=/opt/ase_riscv_gem5_sim/results/my_c_benchmark --errout=/opt/ase_riscv_gem5_sim/results/my_c_benchmark/programm.err

warn: The `get_runtime_isa` function is deprecated. Please migrate away from using this function.
Simulating until tick=18446744073709551615
src/base/loader/image_file_data.cc:110: fatal: fatal condition fd < 0 occurred: Failed to open file /opt/ase_riscv_gem5_sim/programs/my_c_benchmark/my_c_benchmark.elf.
This error typically occurs when the file path specified is incorrect.
Memory Usage: 108208 KBytes

Apparently the problem is that the cross-compiler doesn't find some libraries, as we can point that the error message start with

/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: /usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/lib/libc.a(libc-start.o): in function `.L0 ':
(.text+0x4): undefined reference to `__fini_array_start'
...
...
my_c_benchmark.elf: hidden symbol `__fini_array_end' isn't defined
/usr/lib/gcc-cross/riscv64-linux-gnu/11/../../../../riscv64-linux-gnu/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status

and so the compilation fails. This error seems to propagate to the simulator, as the .elf file is no longer found, as written at the end of the output log. I don't know if my interpretation is good, but i need help solving this (problably WSL2 is not recommended i know, as Windows messes with the build process, but i can only use WSL2).

I don't know if it's a good idea using the riscv toolchain for windows instead of the linux one, as integrating it in WSL may make a mess (?)

0

There are 0 best solutions below