Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Crash on asm!("int $3"): Wrong MachineOperand accessor #23458

Closed
kryptan opened this issue Mar 17, 2015 · 6 comments
Closed

Crash on asm!("int $3"): Wrong MachineOperand accessor #23458

kryptan opened this issue Mar 17, 2015 · 6 comments
Labels
A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@kryptan
Copy link
Contributor

kryptan commented Mar 17, 2015

While compiling the following program:

#![feature(asm)]

fn main() {
    unsafe {
        asm!("int $3");
    } 
}

rustc crashes:

D:\rust>rustc crash.rs
Assertion failed!

Program: C:\Program Files\Rust-nightly\bin\rustc.exe
File: C:/bot/slave/nightly-dist-rustc-win-64/build/src/llvm/include/llvm/CodeGen/MachineOperand.h, Line 408

Expression: isImm() && "Wrong MachineOperand accessor"

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

Meta

D:\rust>rustc --version --verbose
rustc 1.0.0-nightly (30e1f9a1c 2015-03-14) (built 2015-03-15)
binary: rustc
commit-hash: 30e1f9a1c2bf7134135800bc9afd082773defadc
commit-date: 2015-03-14
build-date: 2015-03-15
host: x86_64-pc-windows-gnu
release: 1.0.0-nightly
@kmcallister kmcallister added A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Mar 18, 2015
@achanda
Copy link
Contributor

achanda commented Apr 11, 2015

Could not repro this on OSX

Abhishek@Abhisheks-MacBook-Pro:~/src/rust (master %=)$ ./x86_64-apple-darwin/stage2/bin/rustc crash.rs
crash.rs:5:9: 5:24 error: <inline asm>:1:2: error: too few operands for instruction
        int
        ^

crash.rs:5         asm!("int $3");
                   ^~~~~~~~~~~~~~~
error: aborting due to previous error
Abhishek@Abhisheks-MacBook-Pro:~/src/rust (master %=)$ ./x86_64-apple-darwin/stage2/bin/rustc --version --verbose
rustc 1.0.0-dev (c897ac04e 2015-04-10) (built 2015-04-10)
binary: rustc
commit-hash: c897ac04e2ebda378fd9e38f6ec0878ae3a2baf7
commit-date: 2015-04-10
build-date: 2015-04-10
host: x86_64-apple-darwin
release: 1.0.0-dev
Abhishek@Abhisheks-MacBook-Pro:~/src/rust (master %=)$ cat crash.rs
#![feature(asm)]

fn main() {
    unsafe {
        asm!("int $3");
    }
}

bltavares added a commit to bltavares/glacier that referenced this issue Oct 31, 2015
@steveklabnik
Copy link
Member

steveklabnik commented May 24, 2016

This still reproduces for me today on Linux.

@Ekleog
Copy link

Ekleog commented Jun 7, 2017

Just had the same issue. For the record, using asm!(".byte 0xCC"); is a workaround on x86_64, when using the intrinsics is not a possibility (like when in a #[naked] function).

@Ekleog
Copy link

Ekleog commented Jun 20, 2017

For the record (bis), asm!("int3") is a cleaner workaround.

@jcranmer
Copy link

FWIW, LLVM's inline ASM uses $ as the sigil for substitution, not % as in Clang and GCC.

Using asm!("int $$3"); works.

@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. and removed C-bug Category: This is a bug. labels Jul 22, 2017
euclio added a commit to euclio/rust that referenced this issue Oct 19, 2018
`DiagnosticInfoInlineAsm::getInstruction` may return a null pointer, so
the instruction shouldn't be blindly unwrapped.

Fixes rust-lang#23458.
@cyplo
Copy link
Contributor

cyplo commented Dec 23, 2018

Still ICEs, different message;

Using asm!("int $$3"); makes the program compile with rustc 1.33.0-nightly (2d3e909e4 2018-12-22) while the original code with asm!("int $3"); still ICEs, the message is different now though:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:355:21                                                                                   
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[1]    13385 illegal hardware instruction (core dumped)  rustc test.rs

bors added a commit that referenced this issue Mar 25, 2019
make asm diagnostic instruction optional

`DiagnosticInfoInlineAsm::getInstruction` may return a null pointer, so
the instruction shouldn't be blindly unwrapped.

Reopening from #55193. I was unable to trigger the assertion on Windows after rebasing.

Fixes #23458.
Fixes #55216.
steveklabnik added a commit to rust-lang/glacier that referenced this issue Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

8 participants