Skip to content

ICE when compiling assembly has invalid registers #72570

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
tesuji opened this issue May 25, 2020 · 1 comment · Fixed by #72607
Closed

ICE when compiling assembly has invalid registers #72570

tesuji opened this issue May 25, 2020 · 1 comment · Fixed by #72607
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tesuji
Copy link
Contributor

tesuji commented May 25, 2020

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.

@tesuji tesuji added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 25, 2020
@jonas-schievink jonas-schievink added A-inline-assembly Area: Inline assembly (`asm!(…)`) F-asm `#![feature(asm)]` (not `llvm_asm`) requires-nightly This issue requires a nightly compiler in some way. labels May 25, 2020
@Amanieu
Copy link
Member

Amanieu commented May 25, 2020

Minimal reproduction:

#![feature(asm)]

fn main() {
    unsafe {
        asm!("", in("invalid") "".len());
    }
}

@tesuji tesuji changed the title ICE when compiling x86 asm on aarch64 target ICE when compiling assembly has invalid registers May 25, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 26, 2020
Eagerly lower asm sub-expressions to HIR even if there is an error

Fixes rust-lang#72570

r? @oli-obk
RalfJung added a commit to RalfJung/rust that referenced this issue May 30, 2020
Eagerly lower asm sub-expressions to HIR even if there is an error

Fixes rust-lang#72570

r? @oli-obk
@bors bors closed this as completed in 6faa82b May 30, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants