将mandelbrot编译到riscv后,与fp-math链接时提示__addsf3等未定义
用如下命令编译 mandelbrot.c 及 fp-math.c 并链接:
$ ./compiler -riscv mandelbrot.c -o mandelbrot.S
$ clang mandelbrot.S -c -o mandelbrot.o -target riscv32-unknown-linux-elf -march=rv32im -mabi=ilp32
$ clang fp-math.c -c -o fp-math.o -target riscv32-unknown-linux-elf -march=rv32im -mabi=ilp32
$ ld.lld mandelbrot.o fp-math.o -L$CDE_LIBRARY_PATH/riscv32 -lsysy -o mandelbrot
链接时报错:
ld.lld: error: undefined symbol: __addsf3
>>> referenced by fp-math.c
>>> fp-math.o:(fp_add)
ld.lld: error: undefined symbol: __subsf3
>>> referenced by fp-math.c
>>> fp-math.o:(fp_sub)
ld.lld: error: undefined symbol: __mulsf3
>>> referenced by fp-math.c
>>> fp-math.o:(fp_mul)
ld.lld: error: undefined symbol: __divsf3
>>> referenced by fp-math.c
>>> fp-math.o:(fp_div)
ld.lld: error: undefined symbol: __ltsf2
>>> referenced by fp-math.c
>>> fp-math.o:(fp_lt)
ld.lld: error: undefined symbol: __floatsisf
>>> referenced by fp-math.c
>>> fp-math.o:(to_fp)
ld.lld: error: undefined symbol: __fixsfsi
>>> referenced by fp-math.c
>>> fp-math.o:(to_int)
这似乎意味着找不到软件浮点库.
我的解决方法是用选项 -march=rv32imf -mabi=ilp32f
重新编译 mandelbrot.S, fp-math.c 以及 /opt/lib/riscv32/libsysy.a (但我并非完全清楚这些选项的含义). 在这之后可以正常链接并输出正确的结果. 然而这样需要更改 libsysy.a, 感觉有点麻烦, 请问有没有更好的解决办法?