Bootstrap

在Arch 上安装Risc-v工具链

前要

课程地址:
第5章-part3-RISC-V 汇编语言编程_哔哩哔哩_bilibili

在学习本课程时,用的系统是 ArchLinux ,而课程中要求的环境是基于 Ubuntu 的,显然为了此目的再开一个虚拟机太消耗资源了,因此我就想能不能在 Arch上 安装相关开发环境。

最终成功了,结果:

$ make debug

Press Ctrl-C and then input 'quit' to exit GDB and QEMU
-------------------------------------------------------
Reading symbols from test.elf...
Breakpoint 1 at 0x80000000: file test.s, line 12.
0x00001000 in ?? ()
=> 0x00001000:  97 02 00 00     auipc   t0,0x0
1: /z $x5 = 0x00000000
2: /z $x6 = 0x00000000
3: /z $x7 = 0x00000000

Breakpoint 1, _start () at test.s:12
12              li x6, 1                # x6 = 1
=> 0x80000000 <_start+0>:       13 03 10 00     li      t1,1
1: /z $x5 = 0x80000000
2: /z $x6 = 0x00000000
3: /z $x7 = 0x00000000
(gdb)

配置开发环境

所需环境:

根据实验需求,我们需要如下工具:

  1. 交叉编译工具链
  2. 调试工具
  3. 虚拟机

riscv-gnu-toolchain-bin 工具链

安装相关依赖:

sudo pacman -Syyu autoconf automake curl python3 libmpc mpfr gmp gawk base-devel bison flex texinfo gperf libtool patchutils bc zlib expat

这是 riscv-gnu-toolchain-bin 工具链的依赖。

随后直接安装工具链:

yay -S riscv-gnu-toolchain-bin

备注:

  1. 此包的大小有点大,如果想要自定义安装可以参考网上教程。
  2. 此包中也包含调试工具,不过与课程的不一致,需要后续更改。

虚拟机

yay -S qemu-full

更换gdb

打开位于code目录下的 common.mk 文件更改其中的:

GDB = gdb-multiarch

GDB = ${CROSS_COMPILE}gdb

错误

1. 缺少 libguile-2.2.so.1

错误信息:

gdb-multiarch: error while loading shared libraries: libguile-2.2.so.1: No such file or directory

安装:

yay -S guile2.2

2. 缺少 libpython3.8.so.1.0

错误信息:

riscv64-unknown-elf-gdb: error while loading shared libraries: libpython3.8.so.1.0: cannot open shared object file: No such file or directory

安装:

yay -S python38

3. 执行 make debug卡住

错误信息:

$ make debug
Press Ctrl-C and then input 'quit' to exit GDB and QEMU
-------------------------------------------------------
qemu-system-riscv32: -s: Failed to find an available port: Address already in use
Reading symbols from test.elf...
Breakpoint 1 at 0x80000000: file test.s, line 12.
stop () at test.s:17
17              j stop                  # Infinite loop to stop execution
=> 0x8000000c <stop+0>: 6f 00 00 00     j       0x8000000c <stop>
1: /z $x5 = 0x00000003
2: /z $x6 = 0x00000001
3: /z $x7 = 0x00000002
#卡在这里

Ctrl+c即可退出。

这是因为上一次启动的qemu未正常关闭,找到qemu相关进程,kill 掉就能正常执行 make debug

参考

  1. riscv-gnu-toolchain-bin 工具链仓库地址:riscv-collabriscv-gnu-toolchain GNU toolchain for RISC-V, including GCC

  2. riscv-gnu-toolchain-bin包:AUR (en) - gdb-multiarch

  3. AUR (en) - gdb-multiarch

  4. arm-none-eabi-gdb Exception caught while booting Guile. Pacman & Package Upgrade Issues Arch Linux Forums

  5. pwndbg install issue on Arch Linux · Issue 101 · pwndbgpwndbg

  6. Arch Linux - guile2.2 2.2.7-3 (x86_64)

  7. SOLVED Missing library after 2017-03-29 update Pacman & Package Upgrade Issues Arch Linux Forums

;