Skip to content

ICE when compiling assembly has invalid registers #72570

@tesuji

Description

@tesuji
Contributor

Code

The example is taken from rust-lang/blog.rust-lang.org#600.

#![feature(asm)]

pub fn foo() {
    let buf = "Hello from asm!\n";
    let ret: i32;
    unsafe {
        asm!(
            "syscall",
            in("rax") 1, // syscall number
            in("rdi") 1, // fd
            in("rsi") buf.as_ptr(),
            in("rdx") buf.len(),
            out("rcx") _, // clobbered by syscalls
            out("r11") _, // clobbered by syscalls
            lateout("rax") ret,
        );
    }
    println!("write returned: {}", ret);
}

Meta

rustc --version --verbose: rustc 1.45.0-nightly (46e85b4 2020-05-24) running on x86_64-unknown-linux-gnu

Error output

Run: cargo build --target=aarch64-unknown-linux-gnu

   Compiling check v0.1.0 (/home/lzutao/fork/rust/check)
error: invalid register `rax`: unknown register
 --> src/lib.rs:9:13
  |
9 |             in("rax") 1, // syscall number
  |             ^^^^^^^^^^^

error: invalid register `rdi`: unknown register
  --> src/lib.rs:10:13
   |
10 |             in("rdi") 1, // fd
   |             ^^^^^^^^^^^

error: invalid register `rsi`: unknown register
  --> src/lib.rs:11:13
   |
11 |             in("rsi") buf.as_ptr(),
   |             ^^^^^^^^^^^^^^^^^^^^^^

error: invalid register `rdx`: unknown register
  --> src/lib.rs:12:13
   |
12 |             in("rdx") buf.len(),
   |             ^^^^^^^^^^^^^^^^^^^

error: invalid register `rcx`: unknown register
  --> src/lib.rs:13:13
   |
13 |             out("rcx") _, // clobbered by syscalls
   |             ^^^^^^^^^^^^

error: invalid register `r11`: unknown register
  --> src/lib.rs:14:13
   |
14 |             out("r11") _, // clobbered by syscalls
   |             ^^^^^^^^^^^^

error: invalid register `rax`: unknown register
  --> src/lib.rs:15:13
   |
15 |             lateout("rax") ret,
   |             ^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/46e85b4328fe18492894093c1092dfe509df4370/src/librustc_hir/definitions.rs:358:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.45.0-nightly (46e85b432 2020-05-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: aborting due to 7 previous errors
Backtrace

stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:490
  12: rust_begin_unwind
             at src/libstd/panicking.rs:388
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:101
  14: core::panicking::panic
             at src/libcore/panicking.rs:56
  15: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  16: <std::collections::hash::map::HashMap<K,V,S> as core::iter::traits::collect::FromIterator<(K,V)>>::from_iter
  17: rustc_resolve::Resolver::into_outputs
  18: rustc_interface::passes::configure_and_expand::{{closure}}
  19: rustc_interface::passes::BoxedResolver::to_resolver_outputs
  20: rustc_interface::queries::Queries::lower_to_hir
  21: rustc_interface::queries::Queries::global_ctxt
  22: rustc_interface::interface::run_compiler_in_existing_thread_pool
  23: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Activity

added
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 25, 2020
added
A-inline-assemblyArea: Inline assembly (`asm!(…)`)
F-asm`#![feature(asm)]` (not `llvm_asm`)
requires-nightlyThis issue requires a nightly compiler in some way.
on May 25, 2020
Amanieu

Amanieu commented on May 25, 2020

@Amanieu
Member

Minimal reproduction:

#![feature(asm)]

fn main() {
    unsafe {
        asm!("", in("invalid") "".len());
    }
}
changed the title [-]ICE when compiling x86 asm on aarch64 target[/-] [+]ICE when compiling assembly has invalid registers[/+] on May 25, 2020
added a commit that references this issue on May 26, 2020
6faa82b
added a commit that references this issue on May 26, 2020
06e3a1d
added a commit that references this issue on May 30, 2020
69310de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.F-asm`#![feature(asm)]` (not `llvm_asm`)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @Amanieu@jonas-schievink@tesuji

      Issue actions

        ICE when compiling assembly has invalid registers · Issue #72570 · rust-lang/rust