All
I am trying to use gcov on a freestanding environment with riscv64-unknow-elf-gcc 13.2.0.
I tried to follow the idea of gcc gcov tutorial here. And it works on my host system.
Then I try to porting this example to my riscv64 environment, which is a baremetal MCU, and has no file system and stdlib.
#Compile
riscv64-unknow-elf-gcc -mcmodel=medany -static
-O0 -ffast-math -fno-common -fno-builtin-printf
--coverage -fprofile-info-section -ffunction-sections -fdata-sections
-g -c test_gcov.c
#Link
riscv64-unknown-elf-gcc -static -nostdlib -nostartfiles
--coverage -T ../common/test_gcov.ld *.o -Wl,-Map=test_gcov.riscv.map
-Wl,--gc-sections -Wl,--verbose -o test_gcov.riscv
It fails while linking
attempt to open /opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/libgcov.a succeeded
/opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/libgcov.a
(/opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/libgcov.a)_gcov_merge_add.o
(/opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/libgcov.a)_gcov.o
/opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: warning: test_gcov.riscv has a LOAD segment with RWX permissions
/opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/../../../../riscv64-unknown-elf/bin/ld: /opt/riscv/lib/gcc/riscv64-unknown-elf/13.2.0/libgcov.a(_gcov.o): in function `gcov_read_bytes':
/media/jmst/tmpSSD/riscv-gnu-toolchain/build-gcc-newlib-stage2/riscv64-unknown-elf/libgcc/../../.././gcc/libgcc/libgcov-driver.c:399:(.text+0x1c): undefined reference to `fread'
It seems the libgcov.a need a define of fread
, which is stdlib function here.
Is there anyway to let the coverage code not use stdlib, since file system is not avaliable on my system.
Thanks