交叉编译[no_std]代码 - 找不到libcore和compiler_builtins

发布于 2025-01-29 02:18:29 字数 3204 浏览 3 评论 0 原文

我正在尝试遵循#![no-STD] 程序,但对于新架构上的新目标。

  1. 该体系结构是在LLVM上以实验目标(“ ARC”)上游的,但Rustc不使用它,因此首先我在LLVM中启用了Rust的LLVM,如说明
[llvm]
download-ci-llvm = false
ninja = true
targets = "X86"
experimental-targets = "ARC"
  1. 然后,我按照解释的步骤手动添加对拱门的支持,(使用此提交作为示例):
  • 创建/src/abi/call/arc.rs
  • 更新rustc_llvm/src/lib.rs
  • 等,
  1. 然后我添加了目标文件 arc-pc-inknown-gnu.json envvar:
{
  "arch": "arc",
  "cpu": "generic",
  "abi": "eabi",
  "c-enum-min-bits": 8,
  "data-layout": "e-m:e-p:32:32-i64:32-f64:32-v64:32-v128:32-a:0:32-n32",
  "eh-frame-header": false,
  "emit-debug-gdb-scripts": false,
  "executables": true,
  "features": "",
  "linker": "rust-lld",
  "linker-flavor": "ld.lld",
  "llvm-target": "arc-pc-unknown-gnu",
  "max-atomic-width": 32,
  "atomic-cas": false,
  "panic-strategy": "abort",
  "relocation-model": "static",
  "target-pointer-width": "32"
}
  1. 构建编译器: ./ x.py build -i-target = arc-pc-inknown-gnu library/core 。它成功完成了,我可以看到 stage1 libs的 arc-pc-pc-inknown-gnu target
  2. 我认为这足够了,但是由于以下内容,代码没有编译问题:
$ rustc --emit=llvm-ir -o rust_main.ll -C panic=abort --target arc-pc-unknown-gnu src/main.rs
error[E0463]: can't find crate for `core`
  |
  = note: the `arc-pc-unknown-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add arc-pc-unknown-gnu`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `compiler_builtins`

error[E0412]: cannot find type `PanicInfo` in this scope
  --> src/main.rs:18:18

这很奇怪,因为在上一步,我应该为我的目标编译这些液体...

  1. 然后,我可能需要使用 cargo build build std 再次重建libcore(尽管我不喜欢't知道为什么确切,但是网上有人提到了这一点)吗?我尝试了此操作,但是现在有以下错误:
$ cargo build -Z build-std=core --target arc-pc-unknown-gnu
   Compiling compiler_builtins v0.1.70
   Compiling core v0.0.0 (/home/valeriyk/proj/rust-arc/1.60.0/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
error[E0463]: can't find crate for `std`

error: cannot find macro `println` in this scope
  --> /home/valeriyk/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/build.rs:88:9
   |
88 |         println!("cargo:rustc-cfg=kernel_user_helpers")
   |         ^^^^^^^

error: cannot find macro `println` in this scope
  --> /home/valeriyk/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/build.rs:78:9
   |
78 |         println!("cargo:rustc-cfg=thumb_1")
   |         ^^^^^^^
...

libcore 需要 std ?我只想使用stage1 rustc进行交叉编译,然后在我的#![no_std]示例编译中捡起。任何指导将不胜感激。

I'm trying to follow the steps explained in Embeddonomicon to compile the smallest #![no-std] program, but for a new target on a new architecture.

  1. The architecture is upstreamed in LLVM as an experimental target ("ARC") but its not used by rustc, so first I enabled it in the LLVM that comes with Rust as explained here: run ./x.py setup then update the config.toml:
[llvm]
download-ci-llvm = false
ninja = true
targets = "X86"
experimental-targets = "ARC"
  1. Then I manually added the support for the arch following the steps explained here (using this commit as an example):
  • created rustc_target/src/abi/call/arc.rs
  • updated rustc_llvm/src/lib.rs
  • etc
  1. Then I added the target file arc-pc-unknown-gnu.json and made it visible through RUST_TARGET_PATH envvar:
{
  "arch": "arc",
  "cpu": "generic",
  "abi": "eabi",
  "c-enum-min-bits": 8,
  "data-layout": "e-m:e-p:32:32-i64:32-f64:32-v64:32-v128:32-a:0:32-n32",
  "eh-frame-header": false,
  "emit-debug-gdb-scripts": false,
  "executables": true,
  "features": "",
  "linker": "rust-lld",
  "linker-flavor": "ld.lld",
  "llvm-target": "arc-pc-unknown-gnu",
  "max-atomic-width": 32,
  "atomic-cas": false,
  "panic-strategy": "abort",
  "relocation-model": "static",
  "target-pointer-width": "32"
}
  1. Built the compiler: ./x.py build -i --target=arc-pc-unknown-gnu library/core. It finished successfully, I could see stage1 libs for the arc-pc-unknown-gnu target
  2. I thought this would be enough, but the code was not compiling because of the following issues:
$ rustc --emit=llvm-ir -o rust_main.ll -C panic=abort --target arc-pc-unknown-gnu src/main.rs
error[E0463]: can't find crate for `core`
  |
  = note: the `arc-pc-unknown-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add arc-pc-unknown-gnu`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `compiler_builtins`

error[E0412]: cannot find type `PanicInfo` in this scope
  --> src/main.rs:18:18

This is weird because on the previous step I should have compiled these very libs for my target...

  1. Then I though that perhaps I needed to rebuild libcore again using cargo build-std (although I don't know why exactly, but someone on the web mentioned this)? I tried this, but now there are the following errors:
$ cargo build -Z build-std=core --target arc-pc-unknown-gnu
   Compiling compiler_builtins v0.1.70
   Compiling core v0.0.0 (/home/valeriyk/proj/rust-arc/1.60.0/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
error[E0463]: can't find crate for `std`

error: cannot find macro `println` in this scope
  --> /home/valeriyk/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/build.rs:88:9
   |
88 |         println!("cargo:rustc-cfg=kernel_user_helpers")
   |         ^^^^^^^

error: cannot find macro `println` in this scope
  --> /home/valeriyk/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.70/build.rs:78:9
   |
78 |         println!("cargo:rustc-cfg=thumb_1")
   |         ^^^^^^^
...

How come that libcore needs std? I just want to have it cross-compiled using the stage1 rustc, and then picked up during my #![no_std] example compilation. Any guidance is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦明 2025-02-05 02:18:29

这就是我解决问题的方式:

  1. 使用正确的Rustc源代码。我从一个稳定的版本开始,该版本的libcore与最新的 Compiler_builtins 不兼容。请参阅此处有关更多详细信息。然后我需要升级到最新的每晚。

  2. 构建编译器时,不要要求为最后阶段构建libcore,而仅构建Rustc:

$ ./x.py build -i --stage=1 --target=arcv2-none-elf32 compiler/rustc
  1. 使用以下 .cargo/config.toml ,请勿使用 XARGO < /code>或 -z build-std = core 编译器builtins-mem 解释了此处
[unstable]
build-std = [
    "core",
    "compiler_builtins"
]
build-std-features = ["compiler-builtins-mem"]

[build]
target = "arcv2-none-elf32"
  1. 使用简单的货物构建构建代码。它的编译还不错,尽管稍后链接失败了 - 但这是另一个故事。

That's how I solved the issue:

  1. Use the right rustc source code. I started with a stable version whose libcore was not compatible with the latest compiler_builtins. See here for more details. Then I needed to upgrade to the latest nightly.

  2. When building the compiler, don't ask to build libcore for the final stage, instead build rustc only:

$ ./x.py build -i --stage=1 --target=arcv2-none-elf32 compiler/rustc
  1. Use the following for the .cargo/config.toml, don't use Xargo or -Z build-std=core. The compiler-builtins-mem thing is explained here.
[unstable]
build-std = [
    "core",
    "compiler_builtins"
]
build-std-features = ["compiler-builtins-mem"]

[build]
target = "arcv2-none-elf32"
  1. Build the code with a simple cargo build. It compiled just fine, although it failed at linking later - but that's another story.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文