在编译no_std二进制文件时,rustc会永远挂起

时间:2018-04-09 12:07:46

标签: rust

我正在阅读second edition of Writing an OS in Rust。在第三章我遇到了一个问题 - 定义静态spin::Mutex会挂起编译器。我设法将代码缩减为:

  • 的src / main.rs

    #![feature(lang_items, start)]
    #![no_std]
    #![no_main]
    
    use core::sync::atomic::{Ordering, ATOMIC_BOOL_INIT};
    
    #[no_mangle]
    pub extern "C" fn _start() -> ! {
        let b = ATOMIC_BOOL_INIT;
        b.store(true, Ordering::SeqCst);
        loop {}
    }
    
    #[lang = "eh_personality"] pub extern fn eh_personality() {}
    #[lang = "panic_fmt"] pub extern fn panic_fmt() -> ! { loop {} }
    
  • Cargo.toml

    [package]
    name = "repro"
    version = "0.1.0"
    
    [profile.dev]
    panic = "abort"
    
    [profile.release]
    panic = "abort"
    
  • x86_64的-repro.json

    {
        "llvm-target": "x86_64-unknown-none",
        "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
        "linker-flavor": "ld.lld",
        "target-endian": "little",
        "target-pointer-width": "64",
        "target-c-int-width": "32",
        "arch": "x86_64",
        "os": "none",
        "executables": true,
        "disable-redzone": true,
        "features": "-mmx,-sse,+soft-float",
        "panic-strategy": "abort"
    }
    

有了这个,当我运行xargo build --target=x86_64-repro时,它似乎永远挂在Compiling repro v0.1.0 (file:...)上。我离开它10分钟,它似乎没有取得任何进展(没有处理器使用,使用的内存量不会改变)。

  • 操作系统:Windows 10
  • 工具链:nightly-x86_64-pc-windows-gnu
  • rustc:rustc 1.27.0-nightly (056f589fb 2018-04-07)
  • 货物:cargo 1.26.0-nightly (b70ab13b3 2018-04-04)
  • Xargo:xargo 0.3.12

使用$env:RUST_LOG=debug启用rustc日志记录表明编译似乎停留在链接上:

    DEBUG 2018-04-09T11:38:55Z: cargo::core::workspace: find_root - trying C:\Users\djade\Desktop\osprojrep\Cargo.toml
    DEBUG 2018-04-09T11:38:55Z: cargo::core::workspace: find_root - trying C:\Users\djade\Desktop\Cargo.toml
    DEBUG 2018-04-09T11:38:55Z: cargo::core::workspace: find_root - trying C:\Users\djade\Cargo.toml
    DEBUG 2018-04-09T11:38:55Z: cargo::core::workspace: find_root - trying C:\Users\Cargo.toml
    DEBUG 2018-04-09T11:38:55Z: cargo::core::workspace: find_root - trying C:\Cargo.toml
    DEBUG 2018-04-09T11:38:55Z: cargo::core::workspace: find_members - only me as a member
    DEBUG 2018-04-09T11:38:55Z: cargo::ops::resolve: attempting to prefer repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro)
    DEBUG 2018-04-09T11:38:55Z: cargo::core::registry: load/missing  file:///C:/Users/djade/Desktop/osprojrep/repro
    DEBUG 2018-04-09T11:38:55Z: cargo::sources::config: loading: file:///C:/Users/djade/Desktop/osprojrep/repro
    DEBUG 2018-04-09T11:38:55Z: cargo::core::resolver: initial activation: repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro)
    DEBUG 2018-04-09T11:38:55Z: cargo::ops::resolve: attempting to prefer repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro)
    DEBUG 2018-04-09T11:38:55Z: cargo::core::registry: load/locked   file:///C:/Users/djade/Desktop/osprojrep/repro
    DEBUG 2018-04-09T11:38:55Z: cargo::core::resolver: initial activation: repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro)
    INFO 2018-04-09T11:38:55Z: jobserver::imp: created jobserver Client { sem: Handle(0x230), name: "__rust_jobserver_semaphore_3539026941" }
    DEBUG 2018-04-09T11:38:55Z: cargo::ops::cargo_rustc::context: probe_target_info
    DEBUG 2018-04-09T11:38:56Z: cargo::ops::cargo_rustc::fingerprint: fingerprint at: C:\Users\djade\Desktop\osprojrep\repro\target\x86_64-repro\debug\.fingerprint\repro-1e7ce729192ba73b\bin-repro-1e7ce729192ba73b
    INFO 2018-04-09T11:38:56Z: cargo::ops::cargo_rustc::fingerprint: fingerprint error for repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro): failed to read `C:\Users\djade\Desktop\osprojrep\repro\target\x86_64-repro\debug\.fingerprint\repro-1e7ce729192ba73b\bin-repro-1e7ce729192ba73b`
    INFO 2018-04-09T11:38:56Z: cargo::ops::cargo_rustc::fingerprint:   cause: The system cannot find the file specified. (os error 2)
    INFO 2018-04-09T11:38:56Z: cargo::ops::cargo_rustc::context::compilation_files: Target filenames: [OutputFile { path: "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b", hardlink: Some("C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\repro"), flavor: Normal }]
    INFO 2018-04-09T11:38:56Z: cargo::ops::cargo_rustc::job_queue: start: repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro) => Target(bin: repro)/Profile(build) => Target
    Compiling repro v0.1.0 (file:///C:/Users/djade/Desktop/osprojrep/repro)
    INFO 2018-04-09T11:38:56Z: jobserver::imp: opened environment semaphore __rust_jobserver_semaphore_3539026941
    INFO 2018-04-09T11:38:56Z: rustc_driver: codegen backend candidate: C:\Users\djade\.rustup\toolchains\nightly-x86_64-pc-windows-gnu\lib\rustlib\x86_64-pc-windows-gnu\codegen-backends
    INFO 2018-04-09T11:38:56Z: rustc_driver: probing C:\Users\djade\.rustup\toolchains\nightly-x86_64-pc-windows-gnu\lib\rustlib\x86_64-pc-windows-gnu\codegen-backends for a codegen backend
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: resolving crate `extern crate compiler_builtins as compiler_builtins`
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: falling back to a load
    INFO 2018-04-09T11:38:56Z: rustc_metadata::locator: lib candidate: C:\Users\djade\.xargo\lib\rustlib\x86_64-repro\lib\libcompiler_builtins-95e63877493349a0.rlib
    INFO 2018-04-09T11:38:56Z: rustc_metadata::locator: rlib reading metadata from: \\?\C:\Users\djade\.xargo\lib\rustlib\x86_64-repro\lib\libcompiler_builtins-95e63877493349a0.rlib
    INFO 2018-04-09T11:38:56Z: rustc_metadata::locator: reading "libcompiler_builtins-95e63877493349a0.rlib" => Duration { secs: 0, nanos: 223543 }
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: register crate `extern crate compiler_builtins as compiler_builtins`
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: resolving dep crate core hash: `59386c7ce0d7be7a` extra filename: `-fd00811e13d47697`
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: resolving crate `extern crate core as core`
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: falling back to a load
    INFO 2018-04-09T11:38:56Z: rustc_metadata::locator: lib candidate: C:\Users\djade\.xargo\lib\rustlib\x86_64-repro\lib\libcore-fd00811e13d47697.rlib
    INFO 2018-04-09T11:38:56Z: rustc_metadata::locator: rlib reading metadata from: \\?\C:\Users\djade\.xargo\lib\rustlib\x86_64-repro\lib\libcore-fd00811e13d47697.rlib
    INFO 2018-04-09T11:38:56Z: rustc_metadata::locator: reading "libcore-fd00811e13d47697.rlib" => Duration { secs: 0, nanos: 219532 }
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: register crate `extern crate core as core`
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: resolving crate `extern crate core as core`
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader: resolved crates:
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   name: compiler_builtins
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   cnum: 1
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   hash: 5fe7de92c54e02b5
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   reqd: Explicit
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:    rlib: \\?\C:\Users\djade\.xargo\lib\rustlib\x86_64-repro\lib\libcompiler_builtins-95e63877493349a0.rlib
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   name: core
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   cnum: 2
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   hash: 59386c7ce0d7be7a
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:   reqd: Explicit
    INFO 2018-04-09T11:38:56Z: rustc_metadata::creader:    rlib: \\?\C:\Users\djade\.xargo\lib\rustlib\x86_64-repro\lib\libcore-fd00811e13d47697.rlib
    INFO 2018-04-09T11:38:56Z: rustc_mir::build: fn_id DefId(0/0:7 ~ repro[4180]::_start[0]) has attrs Borrowed([Attribute { id: AttrId(3), style: Outer, path: path(no_mangle), tokens: TokenStream { kind: Empty }, is_sugared_doc: false, span: src\main.rs:7:1: 7:13 }])
    INFO 2018-04-09T11:38:56Z: rustc_mir::build: fn_id DefId(0/0:8 ~ repro[4180]::eh_personality[0]) has attrs Borrowed([Attribute { id: AttrId(4), style: Outer, path: path(lang), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src\main.rs:14:8: 14:9, Eq)) }, TokenStream { kind: Tree(Token(src\main.rs:14:10: 14:26, Literal(Str_(eh_personality), None))) }]) }, is_sugared_doc: false, span: src\main.rs:14:1: 14:27 }])
    INFO 2018-04-09T11:38:56Z: rustc_mir::build: fn_id DefId(0/0:9 ~ repro[4180]::panic_fmt[0]) has attrs Borrowed([Attribute { id: AttrId(5), style: Outer, path: path(lang), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src\main.rs:15:8: 15:9, Eq)) }, TokenStream { kind: Tree(Token(src\main.rs:15:10: 15:21, Literal(Str_(panic_fmt), None))) }]) }, is_sugared_doc: false, span: src\main.rs:15:1: 15:22 }])
    Pre-trans
    Ty interner             total           ty region  both
        TyAdt             :    129 75.9%,  0.0%   0.0%  0.0%
        TyArray           :      0  0.0%,  0.0%   0.0%  0.0%
        TySlice           :      0  0.0%,  0.0%   0.0%  0.0%
        TyRawPtr          :      4  2.4%,  0.0%   0.0%  0.0%
        TyRef             :     19 11.2%,  0.0%   0.0%  0.0%
        TyFnDef           :      4  2.4%,  0.0%   0.0%  0.0%
        TyFnPtr           :      0  0.0%,  0.0%   0.0%  0.0%
        TyGenerator       :      0  0.0%,  0.0%   0.0%  0.0%
        TyGeneratorWitness:      0  0.0%,  0.0%   0.0%  0.0%
        TyDynamic         :      0  0.0%,  0.0%   0.0%  0.0%
        TyClosure         :      0  0.0%,  0.0%   0.0%  0.0%
        TyTuple           :      1  0.6%,  0.0%   0.0%  0.0%
        TyParam           :     11  6.5%,  0.0%   0.0%  0.0%
        TyInfer           :      1  0.6%,  0.6%   0.0%  0.0%
        TyProjection      :      1  0.6%,  0.0%   0.0%  0.0%
        TyAnon            :      0  0.0%,  0.0%   0.0%  0.0%
        TyForeign         :      0  0.0%,  0.0%   0.0%  0.0%
                    total    170         0.6%   0.0%  0.0%
    Substs interner: #45
    Region interner: #47
    Stability interner: #2
    Interpret interner: #0
    Layout interner: #0
    INFO 2018-04-09T11:38:56Z: rustc_trans_utils::link: LinkMeta { crate_hash: Svh { hash: 14623612180396971999 } }
    INFO 2018-04-09T11:38:56Z: rustc_trans::base: trans_instance(core::sync::atomic::atomic_store::<u8>)
    INFO 2018-04-09T11:38:56Z: rustc_trans::base: trans_instance(<core::cell::UnsafeCell<T>><u8>::get)
    INFO 2018-04-09T11:38:56Z: rustc_trans::base: trans_instance(core::sync::atomic::AtomicBool::store)
    INFO 2018-04-09T11:38:56Z: rustc_trans::base: trans_instance(_start)
    Post-trans
    Ty interner             total           ty region  both
        TyAdt             :    129 60.6%,  0.0%   0.0%  0.0%
        TyArray           :      0  0.0%,  0.0%   0.0%  0.0%
        TySlice           :      0  0.0%,  0.0%   0.0%  0.0%
        TyRawPtr          :      6  2.8%,  0.0%   0.0%  0.0%
        TyRef             :     37 17.4%,  0.0%   0.0%  0.0%
        TyFnDef           :     18  8.5%,  0.0%   0.0%  0.0%
        TyFnPtr           :      7  3.3%,  0.0%   0.0%  0.0%
        TyGenerator       :      0  0.0%,  0.0%   0.0%  0.0%
        TyGeneratorWitness:      0  0.0%,  0.0%   0.0%  0.0%
        TyDynamic         :      0  0.0%,  0.0%   0.0%  0.0%
        TyClosure         :      0  0.0%,  0.0%   0.0%  0.0%
        TyTuple           :      3  1.4%,  0.0%   0.0%  0.0%
        TyParam           :     11  5.2%,  0.0%   0.0%  0.0%
        TyInfer           :      1  0.5%,  0.5%   0.0%  0.0%
        TyProjection      :      1  0.5%,  0.0%   0.0%  0.0%
        TyAnon            :      0  0.0%,  0.0%   0.0%  0.0%
        TyForeign         :      0  0.0%,  0.0%   0.0%  0.0%
                    total    213         0.5%   0.0%  0.0%
    Substs interner: #50
    Region interner: #48
    Stability interner: #2
    Interpret interner: #11
    Layout interner: #15
    INFO 2018-04-09T11:38:56Z: rustc_trans::back::link: preparing CrateTypeExecutable to "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b"
    INFO 2018-04-09T11:38:56Z: rustc_trans::back::link: "lld" "-flavor" "gnu" "-L" "C:\\Users\\djade\\.xargo\\lib\\rustlib\\x86_64-repro\\lib" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b.3ik0x0hz6l66cx38.rcgu.o" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b.45pc7c65foh9i35f.rcgu.o" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b.4hrpdi97o8cjelph.rcgu.o" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b.57k06xfugllsc526.rcgu.o" "-o" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps\\repro-1e7ce729192ba73b" "--gc-sections" "-L" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\x86_64-repro\\debug\\deps" "-L" "C:\\Users\\djade\\Desktop\\osprojrep\\repro\\target\\debug\\deps" "-L" "C:\\Users\\djade\\.xargo\\lib\\rustlib\\x86_64-repro\\lib" "-Bstatic" "C:\\Users\\djade\\.xargo\\lib\\rustlib\\x86_64-repro\\lib\\libcore-fd00811e13d47697.rlib" "C:\\Users\\djade\\.xargo\\lib\\rustlib\\x86_64-repro\\lib\\libcompiler_builtins-95e63877493349a0.rlib" "-Bdynamic"

还有一些可能感兴趣的事情:

  • 使用xargo进行默认目标而不是x86_64-repro进行编译失败,并在file format not recognized内的某个对象文件中出现链接器错误.xargo
  • 使用货物为默认目标进行编译失败,并且关于缺少对rust_eh_personality的引用的链接器消息更长。
  • main.rs更改为lib.rs会使其成功编译。
  • 删除b.store(...);使其成功编译。

那么,这是什么? Xargo bug? Rustc bug?链接器错误?我的配置在某处错了吗?

0 个答案:

没有答案