编译riscv-pk 出现 unrecognized opcode `fence.i‘, extension `zifencei‘ required

文章讲述了在编译riscv-pk过程中遇到的unrecognizedopcode错误,涉及zifencei扩展。通过在GitHub上查找,发现需要修改编译选项中的mabi设置从lp64改为lp64d以解决冲突,最终成功编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在 编译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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值