Skip to content

Compiler null dereference when there are conflicting asm labels #74262

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

Closed
addrianyy opened this issue Jul 12, 2020 · 7 comments
Closed

Compiler null dereference when there are conflicting asm labels #74262

addrianyy opened this issue Jul 12, 2020 · 7 comments
Assignees
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@addrianyy
Copy link

addrianyy commented Jul 12, 2020

Code

#![feature(asm)]

#[inline(always)]
fn f() {
    unsafe {
        asm!("test: nop");
    }
}

fn main() {
    f();
    f();
}

Meta

rustc 1.46.0-nightly (346aec9b0 2020-07-11)
binary: rustc
commit-hash: 346aec9b02f3c74f3fce97fd6bda24709d220e49
commit-date: 2020-07-11
host: x86_64-pc-windows-msvc
release: 1.46.0-nightly
LLVM version: 10.0

Error output

error: invalid symbol redefinition
 --> .\crash.rs:6:15
  |
6 |         asm!("test: nop");
  |               ^
  |
note: instantiated into assembly here
 --> <inline asm>:2:2
  |
2 |     test: nop
  |     ^
[crash due to null dereference]

Details

This bug only happens when compiling for Windows target with debug information. Command to reproduce crash:

rustc crash.rs --target x86_64-pc-windows-msvc -g

It was identified by eddyb that crash happens in LLVM function WinCOFFObjectWriter::assignFileOffsets.

@jonas-schievink jonas-schievink added A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. F-asm `#![feature(asm)]` (not `llvm_asm`) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 12, 2020
@jonas-schievink
Copy link
Contributor

On the playground this seems to hang instead

@jonas-schievink jonas-schievink added the I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. label Jul 12, 2020
@Amanieu
Copy link
Member

Amanieu commented Jul 15, 2020

The asm! RFC and documentation specifically say that you should not define labels in inline assembly and instead only use local labels (0:, 1:, etc).

So your code is invalid, but having the compiler crash on invalid code is still a bug.

@asquared31415
Copy link
Contributor

@rustbot claim

@Amanieu
Copy link
Member

Amanieu commented Apr 7, 2021

This no longer seems to crash. Probably fixed by LLVM at some point.

@Amanieu Amanieu closed this as completed Apr 7, 2021
@Amanieu
Copy link
Member

Amanieu commented Apr 7, 2021

Actually it seems to still be crashing on x86_64-pc-windows-gnu and x86_64-pc-windows-msvc.

@Amanieu Amanieu reopened this Apr 7, 2021
@asquared31415
Copy link
Contributor

#87324 lints against using labels in this way, which is prohibited by the asm RFC and documented. #81088 is the primary issue for an ideal solution that lets this work.

Since this now errors by default, should this be closed?

@Amanieu
Copy link
Member

Amanieu commented Oct 21, 2021

Yes, I think we can close this.

@Amanieu Amanieu closed this as completed Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. 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.

4 participants