Regarding cross-compiling with riscv64-unknown-elf-gcc
Have you guys tried to run C-programs with math.h header file functions in shakti core? I tried cross-compiling a C-program with function calls requiring math.h. riscv cross-compiler is throwing errors regarding functions calls for math.h. I googled the error and it asked to include -lm flag while compiling. It worked with the GCC compiler but I am facing difficulty in including -lm flag in the Makefile. Can you help me with this? I have had build a riscv-gnu cross compiler as well as shakti core with RV64IM.
I have added the following lines in c-class/base-sim/benchmarks/Makefile in :
.PHONY: float_try2
float_try2:
@echo "Compiling float_try2 with"
@mkdir -p output/
$(RISCV_GCC) -lm -I./common -I./float_try2 -DCONFIG_RISCV64=True \
-DITERATIONS=$(iterations) -D$(target)=True -mcmodel=medany -static -std=gnu99 -ffast-math \
-fno-common -fno-builtin-printf -w -static \
-nostartfiles -lgcc -T ./common/link.ld -o $(OUTDIR)/float_try2.riscv ./float_try2/float_try2.c \
./common/syscalls.c ./common/crt.S
@$(RISCV_OBJDUMP) $(OUTDIR)/float_try2.riscv > $(OUTDIR)/float_try2.dump
@$(RISCV_HEX) $(OUTDIR)/float_try2.riscv 2147483648 > $(OUTDIR)/code.mem
I used the following command:
c-class/base-sim/benchmarks$ make float_try2
The result I got:
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: /tmp/cc09VKYc.o: in function `.L12':
float_try2.c:(.text+0x1bc): undefined reference to `log'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: float_try2.c:(.text+0x1e4): undefined reference to `floor'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: /tmp/cc09VKYc.o: in function `.L0 ':
float_try2.c:(.text+0x210): undefined reference to `log'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: float_try2.c:(.text+0x238): undefined reference to `floor'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: float_try2.c:(.text+0x28c): undefined reference to `pow'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: float_try2.c:(.text+0x2f0): undefined reference to `pow'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: float_try2.c:(.text+0xcc4): undefined reference to `pow'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/../../../../riscv64-unknown-elf/bin/ld: /tmp/ccg88fRS.o: in function `barrier':
syscalls.c:(.text+0x364): undefined reference to `__sync_fetch_and_add_4'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/libgcc.a(divdf3.o): in function `__divdf3':
/home/jeet/software/riscv_RV64IM/riscv-gnu-toolchain/build-gcc-newlib-stage2/riscv64-unknown-elf/libgcc/../../.././riscv-gcc/libgcc/soft-fp/divdf3.c:46:(.text+0xb8): relocation truncated to fit: R_RISCV_HI20 against `.L10'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/libgcc.a(muldf3.o): in function `__muldf3':
/home/jeet/software/riscv_RV64IM/riscv-gnu-toolchain/build-gcc-newlib-stage2/riscv64-unknown-elf/libgcc/../../.././riscv-gcc/libgcc/soft-fp/muldf3.c:46:(.text+0xbc): relocation truncated to fit: R_RISCV_HI20 against `.L10'
/home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/libgcc.a(_clzsi2.o): in function `__clzdi2':
/home/jeet/software/riscv_RV64IM/riscv-gnu-toolchain/build-gcc-newlib-stage2/riscv64-unknown-elf/libgcc/../../.././riscv-gcc/libgcc/libgcc2.c:710:(.text+0x18): relocation truncated to fit: R_RISCV_HI20 against symbol `__clz_tab' defined in .rodata section in /home/jeet/software/riscv_RV64IM/riscv_RV64IM/lib/gcc/riscv64-unknown-elf/9.2.0/libgcc.a(_clz.o)
collect2: error: ld returned 1 exit status
Makefile:41: recipe for target 'float_try2' failed
make: *** [float_try2] Error 1
Can you please help me with this?
Edited by Neel Gala