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

inline asm jmp 'invalid operand for instruction' #48797

Closed
aasosaa opened this issue Mar 6, 2018 · 6 comments
Closed

inline asm jmp 'invalid operand for instruction' #48797

aasosaa opened this issue Mar 6, 2018 · 6 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aasosaa
Copy link

aasosaa commented Mar 6, 2018

Rust nightly version 2018-02-11 broke some inline assembly in code that previously worked.
Specifically, the jmp instruction on x86_64 doesn't work as it has before.

A minimum example to reproduce is that


fn foo(bytes: &[u8]) -> u32 {
    let result: u32;
    unsafe {
        asm!(
            "
           1:
	      jmp 1b

           "
            : "={ax}"(result)                         // Output register
            : "r"(bytes.as_ptr()), "r"(bytes.len())   // Input registers
            : "rax"                                        // Clobbered registers
            : "intel", "volatile"                     // Options (intel syntax, don't optimize out)
        );
    }
    result
}

now fails to compile with error:
error: <inline asm>:5:2: error: invalid operand for instruction jmp 1b
The code snippet above compiles with rust-nightly-x86_64-unknown-linux-gnu nightly 2018-02-10 and earlier, but returns an error on nightly 2018-02-11 and beyond. I tried looking through the commits that happened that day but couldn't find the exact source of the issue.

@Centril Centril added A-inline-assembly Area: Inline assembly (`asm!(…)`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 6, 2018
@parched
Copy link
Contributor

parched commented Mar 7, 2018

The will have been the upgrade to LLVM 6.

@parched
Copy link
Contributor

parched commented Mar 7, 2018

Try again once the LLVM 6 fixes are in, but I can't see an obvious fix for this.

@paoloteti
Copy link
Contributor

Your example compile without errors on nightly 2018-03-05

@aasosaa
Copy link
Author

aasosaa commented Mar 7, 2018

No I tried 2018-03-05 and it failed with same error.

rust from https://static.rust-lang.org/dist/2018-03-05/rust-nightly-x86_64-unknown-linux-gnu.tar.gz

command:

LD_LIBRARY_PATH=path/rust_linux_x86_64/rustc/lib DYLD_LIBRARY_PATH=path/rust_linux_x86_64/rustc/lib HOST=x86_64-unknown-linux-gnu TARGET=x86_64-unknown-linux-gnu path/rust_linux_x86_64/rustc/bin/rustc src/lib.rs --crate-name crate_name --crate-type lib -L all=path/rust_linux_x86_64/rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib -C panic=abort

@paoloteti
Copy link
Contributor

Yes sorry I was wrong, I mixed up open terminals. BTW this issue looks like: https://bugs.llvm.org/show_bug.cgi?id=36144.

So you can't use 1 or 0 as local labels. Changing label to 5: jmp 5b the issue disappear.

@aasosaa
Copy link
Author

aasosaa commented Mar 8, 2018

Great, thanks for finding that! Fixes the issue.

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants