Skip to content

inline asm jmp 'invalid operand for instruction' #48797

Closed

Description

@aasosaa

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.

Activity

  1. added
    A-inline-assemblyArea: Inline assembly (`asm!(…)`)
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Mar 6, 2018
  2. parched commented on Mar 7, 2018

    @parched
    Contributor

    The will have been the upgrade to LLVM 6.

  3. parched commented on Mar 7, 2018

    @parched
    Contributor

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

  4. paoloteti commented on Mar 7, 2018

    @paoloteti
    Contributor

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

  5. aasosaa commented on Mar 7, 2018

    @aasosaa
    Author

    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
    
    
  6. paoloteti commented on Mar 8, 2018

    @paoloteti
    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.

  7. aasosaa commented on Mar 8, 2018

    @aasosaa
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions