no_std环境中奇怪的 Rust-LLD 错误

strange rust-lld error in no_std environment

提问人:kamkow1 提问时间:8/31/2023 最后编辑:Chayim Friedmankamkow1 更新时间:8/31/2023 访问量:190

问:

我正在尝试使用 rust-lld 链接用 Rust 编写的自定义内核,但我收到这个奇怪的错误:

error: linking with `rust-lld` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/kamil/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/kamil/go/bin:/snap/bin:/home/kamil/.cargo/bin:/archive/ARCHIVE/zig/build/stage3/bin:/archive/ARCHIVE/Odin:/archive/ARCHIVE/Nim/bin:/archive/ARCHIVE/boomer:/archive/ARCHIVE/c3/linux:/archive/ARCHIVE/pycharm/pycharm-2022.3.3/bin:/archive/ARCHIVE/z88dk/bin:/archive/ARCHIVE/s:/home/kamil/.local/bin:/usr/sbin:/archive/ARCHIVE/emscripten:/archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin:/home/kamil/.config/emcacs/bin:/archive/ARCHIVE/nnn:/home/kamil/go/bin:/snap/bin:/home/kamil/.cargo/bin:/archive/ARCHIVE/zig/build/stage3/bin:/archive/ARCHIVE/Odin:/archive/ARCHIVE/Nim/bin:/archive/ARCHIVE/boomer:/archive/ARCHIVE/c3/linux:/archive/ARCHIVE/pycharm/pycharm-2022.3.3/bin:/archive/ARCHIVE/z88dk/bin:/archive/ARCHIVE/s:/home/kamil/.local/bin:/usr/sbin:/archive/ARCHIVE/emscripten:/archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin:/home/kamil/.config/emcacs/bin:/archive/ARCHIVE/nnn:/archive/ARCHIVE/alacritty/target/release:/home/kamil/build-i686-elf/i686-elf-tools-linux/bin:/home/kamil/go/bin:/snap/bin:/home/kamil/.cargo/bin:/archive/ARCHIVE/zig/build/stage3/bin:/archive/ARCHIVE/Odin:/archive/ARCHIVE/Nim/bin:/archive/ARCHIVE/boomer:/archive/ARCHIVE/c3/linux:/archive/ARCHIVE/pycharm/pycharm-2022.3.3/bin:/archive/ARCHIVE/z88dk/bin:/archive/ARCHIVE/s:/home/kamil/.local/bin:/usr/sbin:/archive/ARCHIVE/emscripten:/archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin:/home/kamil/.config/emcacs/bin:/archive/ARCHIVE/nnn:/archive/ARCHIVE/alacritty/target/release:/home/kamil/build-i686-elf/i686-elf-tools-linux/bin:/home/kamil/go/bin:/snap/bin:/home/kamil/.cargo/bin:/archive/ARCHIVE/zig/build/stage3/bin:/archive/ARCHIVE/Odin:/archive/ARCHIVE/Nim/bin:/archive/ARCHIVE/boomer:/archive/ARCHIVE/c3/linux:/archive/ARCHIVE/pycharm/pycharm-2022.3.3/bin:/archive/ARCHIVE/z88dk/bin:/archive/ARCHIVE/s:/home/kamil/.local/bin:/usr/sbin:/archive/ARCHIVE/emscripten:/archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin:/home/kamil/.config/emcacs/bin:/archive/ARCHIVE/nnn:/archive/ARCHIVE/alacritty/target/release:/home/kamil/build-i686-elf/i686-elf-tools-linux/bin:/archive/ARCHIVE/gnvim/target/optimized:/home/kamil/go/bin:/snap/bin:/home/kamil/.cargo/bin:/archive/ARCHIVE/zig/build/stage3/bin:/archive/ARCHIVE/Odin:/archive/ARCHIVE/Nim/bin:/archive/ARCHIVE/boomer:/archive/ARCHIVE/c3/linux:/archive/ARCHIVE/pycharm/pycharm-2022.3.3/bin:/archive/ARCHIVE/z88dk/bin:/archive/ARCHIVE/s:/home/kamil/.local/bin:/usr/sbin:/archive/ARCHIVE/emscripten:/archive/ARCHIVE/zig-bootstrap-0.10.1/zig-bootstrap-0.10.1/out/host/bin:/home/kamil/.config/emcacs/bin:/archive/ARCHIVE/nnn:/archive/ARCHIVE/alacritty/target/release:/home/kamil/build-i686-elf/i686-elf-tools-linux/bin:/archive/ARCHIVE/gnvim/target/optimized" VSLANG="1033" "rust-lld" "-flavor" "gnu" "/tmp/rustcm3FPJ6/symbols.o" "/archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps/shell-e91b1ead495f896e.sys_api-2af3a7608b83c355.4bhx0jy1147mf53z.rcgu.o.rcgu.o" "--as-needed" "-L" "/archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps" "-L" "/archive/ARCHIVE/sources/cos/programs/shell/target/debug/deps" "-L" "/home/kamil/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib" "-Bstatic" "/archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps/libcompiler_builtins-ec434174929fe3ec.rlib" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "/home/kamil/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-none/lib" "-o" "/archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps/shell-e91b1ead495f896e" "--gc-sections" "-pie" "-z" "relro" "-z" "now" "--strip-all" "-n" "-N" "--no-dynamic-linker" "-build-id=none" "--no-eh-frame-hdr"
  = note: rust-lld: error: undefined symbol: core::panicking::panic_nounwind::h16c15692d6463ed7
          >>> referenced by intrinsics.rs:2510 (/home/kamil/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics.rs:2510)
          >>>               compiler_builtins-ec434174929fe3ec.compiler_builtins.578c66a02b9c8733-cgu.0.rcgu.o:(core::ptr::const_ptr::_$LT$impl$u20$$BP$const$u20$T$GT$::read_unaligned::h3b6c56eaac55cbb8) in archive /archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps/libcompiler_builtins-ec434174929fe3ec.rlib
          >>> referenced by intrinsics.rs:2510 (/home/kamil/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics.rs:2510)
          >>>               compiler_builtins-ec434174929fe3ec.compiler_builtins.578c66a02b9c8733-cgu.0.rcgu.o:(core::ptr::const_ptr::_$LT$impl$u20$$BP$const$u20$T$GT$::read_unaligned::h48c3b5a4cc6e53f3) in archive /archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps/libcompiler_builtins-ec434174929fe3ec.rlib
          >>> referenced by intrinsics.rs:2510 (/home/kamil/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics.rs:2510)
          >>>               compiler_builtins-ec434174929fe3ec.compiler_builtins.578c66a02b9c8733-cgu.0.rcgu.o:(core::ptr::const_ptr::_$LT$impl$u20$$BP$const$u20$T$GT$::read_unaligned::h8c7c7d6c241634dc) in archive /archive/ARCHIVE/sources/cos/programs/shell/target/x86_64-unknown-none/debug/deps/libcompiler_builtins-ec434174929fe3ec.rlib
          >>> referenced 2 more times

rustc --version:rustc 1.73.0-nightly (32303b219 2023-07-29)

cargo --version:cargo 1.73.0-nightly (7ac9416d8 2023-07-24)

ld.lld --version:LLD 15.0.6 (compatible with GNU linkers)

我正在一个没有 main 函数和标准库的环境中工作。我已经实现了一个恐慌处理程序,并用 .只有当我调用代码中的某些函数时才会发生此错误,这些函数完全不相关,即此错误可能会发生也可能不会发生,因此不容易重现#[panic_handler]

编辑: 我忘了提。我没有使用自定义目标。我正在编译的目标是x86_64-unknown-none

rust linker-errors lld rust-no-std

评论

0赞 Chayim Friedman 8/31/2023
在我的头顶上:是一种新的机制,用于即使在展开模式下也永远不会展开的恐慌(例如,调试指针对齐检查)。我不知道他们是否需要在恐慌处理程序中进行任何特殊处理。panic_nounwind
0赞 kamkow1 8/31/2023
同样,我发现这非常奇怪,因为这个链接问题只发生在调用某些函数(由我编写,而不是从核心库中编写)时,有时它会发生,有时不会,所以得到这个错误是一个彩票
0赞 Chayim Friedman 8/31/2023
函数可能会执行需要这些断言的操作(例如取消引用原始指针)。如果我不得不猜测,这在发布模式下不会发生。

答: 暂无答案