mipsisa*r6*-unknown-linux-gnu*

级别: 3

MIPS Release 6,简称 MIPS R6,是 MIPS 指令集架构(ISA)的最新版本。

MIPS R6 本质上是实验性的,因为目前还没有真正的硬件。但是,可以使用 Qemu 模拟,并且我们维护了两个 Linux 发行版用于开发和评估。本文档介绍了 Rust 对 mipsisa*r6*-unknown-linux-gnu* 下的 MIPS R6 目标的支持。

目标名称遵循以下格式: <machine>-<vendor>-<os><abi_suffix>,其中 <machine> 指定 CPU 系列/型号,<vendor> 指定供应商,<os> 指定操作系统名称。<abi_suffix> 表示基本 ABI (32/n32/64/o64)。

ABI 后缀描述
abi64使用 64 位 (64) ABI
abin32使用 n32 ABI
N/A使用(假定)32 位 (32) ABI

目标维护者

要求

C/C++ 工具链

需要 MIPS R6 目标的 GNU 工具链。AOSC OS 提供了可工作的本机和交叉编译构建环境。您也可以提供您自己的由最新版本的 GCC 和 Binutils 组成的工具链。

目标库

执行动态链接需要最少的一组库

  • GNU glibc
  • OpenSSL
  • Zlib
  • Linux API 头文件

应该安装这组库以构成最小的目标系统根目录。

对于 AOSC OS,您可以使用以下命令安装这样的系统根目录

cd /tmp

# linux+api, glibc, and file system structure are included in the toolchain.
sudo apt install gcc+cross-mips64r6el binutils+cross-mips64r6el

# Download and extract required libraries.
wget https://repo.aosc.io/debs/pool/stable/main/z/zlib_1.2.13-0_mips64r6el.deb -O zlib.deb
wget https://repo.aosc.io/debs/pool/stable/main/o/openssl_1.1.1q-1_mips64r6el.deb -O openssl.deb

# Extract them to your desired location.
for i in zlib openssl ; do
    sudo dpkg-deb -vx $i.deb /var/ab/cross-root/mips64r6el
done

# Workaround a possible ld bug when using -Wl,-Bdynamic.
sudo sed -i 's|/usr|=/usr|g' /var/ab/cross-root/mips64r6el/usr/lib/libc.so

对于其他发行版,您可以手动构建它们。

构建

以下过程概述了使用 64 位 (64) ABI (mipsisa64r6el-unknown-linux-gnuabi64) 的 MIPS64 R6 目标的构建过程。

先决条件:禁用调试信息

如果启用调试或调试信息生成,则 LLVM 错误会导致 rustc 崩溃。 您需要编辑 config.toml 以禁用此功能

[rust]
debug = false
debug-info-level = 0

先决条件:启用 rustix 的 libc 后端

crate rustix 可能会尝试将其自身链接到 MIPS R2 汇编,从而导致链接错误。为避免这种情况,您可以通过设置相关的 RUSTFLAGS 强制 rustix 使用其后备 libc 后端

export RUSTFLAGS="--cfg rustix_use_libc"

这将在构建期间触发警告,因为默认情况下启用了 -D warnings。通过编辑 config.toml 附加以下内容来禁用 -D warnings

[rust]
deny-warnings = false

先决条件:提供 OpenSSL

作为 3 级目标,openssl_sys 缺少此目标的供应商 OpenSSL 库。您需要提供一个预构建的 OpenSSL 库来链接 cargo。由于我们有一个预配置的系统根目录,我们可以直接指向它

export MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_OPENSSL_NO_VENDOR=y
export MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_OPENSSL_DIR="/var/ab/cross-root/mips64r6el/usr"

在 Debian 上,您可能需要单独提供库路径和包含路径

export MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_OPENSSL_NO_VENDOR=y
export MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_OPENSSL_LIB_DIR="/usr/lib/mipsisa64r6el-linux-gnuabi64/"
export MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_OPENSSL_INCLUDE_DIR="/usr/include"

启动 x.py

[build]
target = ["mipsisa64r6el-unknown-linux-gnuabi64"]

确保 mipsisa64r6el-unknown-linux-gnuabi64-gcc 可从您的可执行文件搜索路径 ($PATH) 中获取。

或者,您可以在 config.toml 中指定所有必要工具链可执行文件的目录

[target.mipsisa64r6el-unknown-linux-gnuabi64]
# Adjust the paths below to point to your toolchain installation prefix.
cc = "/toolchain_prefix/bin/mipsisa64r6el-unknown-linux-gnuabi64-gcc"
cxx = "/toolchain_prefix/bin/mipsisa64r6el-unknown-linux-gnuabi64-g++"
ar = "/toolchain_prefix/bin/mipsisa64r6el-unknown-linux-gnuabi64-gcc-ar"
ranlib = "/toolchain_prefix/bin/mipsisa64r6el-unknown-linux-gnuabi64-ranlib"
linker = "/toolchain_prefix/bin/mipsisa64r6el-unknown-linux-gnuabi64-gcc"

或者,您可以使用环境变量指定交叉编译器工具链

export CROSS_COMPILE="/opt/abcross/mips64r6el/bin/mipsisa64r6el-aosc-linux-gnuabi64-"

最后,启动构建脚本

./x.py build

提示

  • 避免将 cargo-native-static 设置为 false,因为这会在构建 clippy 时导致冗余工件错误
    duplicate artifacts found when compiling a tool, this typically means that something was recompiled because a transitive dependency has different features activated than in a previous build:
    
    the following dependencies have different features:
        syn 2.0.8 (registry+https://github.com/rust-lang/crates.io-index)
    `clippy-driver` additionally enabled features {"full"} at ...
    `cargo` additionally enabled features {} at ...
    
    to fix this you will probably want to edit the local src/tools/rustc-workspace-hack/Cargo.toml crate, as that will update the dependency graph to ensure that these crates all share the same feature set
    thread 'main' panicked at 'tools should not compile multiple copies of the same crate', tool.rs:250:13
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

构建 Rust 程序

要为 MIPS R6 目标构建 Rust 程序,例如, mipsisa64r6el-unknown-linux-gnuabi64 目标

cargo build --target mipsisa64r6el-unknown-linux-gnuabi64

测试

要在您的构建系统上测试交叉编译的二进制文件,请安装支持 MIPS R6 架构的 Qemu 用户模拟器 (qemu-user-mipselqemu-user-mips64el)。目标架构的 GCC 运行时库 (libgcc_s) 应存在于目标系统根目录中以运行该程序。

env \
    CARGO_TARGET_MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_LINKER="/opt/abcross/mips64r6el/bin/mipsisa64r6el-aosc-linux-gnuabi64-gcc" \
    CARGO_TARGET_MIPSISA64R6EL_UNKNOWN_LINUX_GNUABI64_RUNNER="qemu-mips64el-static -L /var/ab/cross-root/mips64r6el" \
    cargo run --release \
        --target mipsisa64r6el-unknown-linux-gnuabi64

构建 MIPS R6 的 Rust 程序的提示

  • 在我们完成修复之前,请确保始终应用上述针对 rustix crate 和 LLVM 的解决方法。这可以通过设置相关的环境变量并在构建之前编辑 Cargo.toml 来实现。