在 编译riscv-pk时出错,报错信息为:
unrecognized opcode `fence.i‘, extension `zifencei‘ required
在github上查找解决方法,得到的解决方法为:添加编译选项--with-arch=rv64gc_zifencei
,即:
../configure --prefix=$RISCV --host=riscv64-unknown-linux-gnu --with-arch=rv64gc_zifencei
修改后编译,仍然报错:
n file included from /opt/RISCV/riscv64/sysroot/usr/include/features.h:515,
from /opt/RISCV/riscv64/sysroot/usr/include/bits/libc-header-start.h:33,
from /opt/RISCV/riscv64/sysroot/usr/include/stdint.h:26,
from /opt/RISCV/riscv64/lib/gcc/riscv64-unknown-linux-gnu/12.2.0/include/stdint.h:9,
from ../util/snprintf.c:3:
/opt/RISCV/riscv64/sysroot/usr/include/gnu/stubs.h:14:11: fatal error: gnu/stubs-lp64.h: No such file or directory
14 | # include <gnu/stubs-lp64.h>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:336: snprintf.o] Error 1
github上的解决方法为:复制stubs-lp64.h
文件到该文件夹下。进入/opt/RISCV/riscv64/sysroot/usr/include/gnu
文件夹下,随便打开一个文件,显示This file is automatically generated.
这些文件都是自动生成的,没办法复制。
继续观察报错信息:
riscv64-unknown-linux-gnu-gcc -MMD -MP -Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks -fno-PIE -march=rv64gc_zifencei -mabi=lp64 -DBBL_LOGO_FILE=\"bbl_logo_file\" -DMEM_START=0x80000000 -fno-stack-protector -U_FORTIFY_SOURCE -DBBL_PAYLOAD=\"bbl_payload\" -I. -I../pk -I../bbl -I../softfloat -I../dummy_payload -I../machine -I../util -c ../pk/file.c
riscv64-unknown-linux-gnu-gcc -MMD -MP -Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks -fno-PIE -march=rv64gc_zifencei -mabi=lp64 -DBBL_LOGO_FILE=\"bbl_logo_file\" -DMEM_START=0x80000000 -fno-stack-protector -U_FORTIFY_SOURCE -DBBL_PAYLOAD=\"bbl_payload\" -I. -I../pk -I../bbl -I../softfloat -I../dummy_payload -I../machine -I../util -c ../pk/syscall.c
riscv64-unknown-linux-gnu-gcc -MMD -MP -Wall -Werror -D__NO_INLINE__ -mcmodel=medany -O2 -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks -fno-PIE -march=rv64gc_zifencei -mabi=lp64 -DBBL_LOGO_FILE=\"bbl_logo_file\" -DMEM_START=0x80000000 -fno-stack-protector -U_FORTIFY_SOURCE -DBBL_PAYLOAD=\"bbl_payload\" -I. -I../pk -I../bbl -I../softfloat -I../dummy_payload -I../machine -I../util -c ../pk/handlers.c
里面显示-mabi=lp64
,而我在编译riscv-toolchain的时候指定的mabi是lp64d
。
打开Makefile文件,在第64行发现,编译选项里指定的是lp64。
ifneq (rv64gc_zifencei,)
march := -march=rv64gc_zifencei
is_32bit := $(findstring 32,$(march))
ifeq (,)
mabi := -mabi=$(if $(is_32bit),ilp32,lp64)
endif
endif
将lp64
修改为lp64d
,保存,重新编译,即可编译成功。
ifneq (rv64gc_zifencei,)
march := -march=rv64gc_zifencei
is_32bit := $(findstring 32,$(march))
ifeq (,)
mabi := -mabi=$(if $(is_32bit),ilp32,lp64d)
endif
endif