rust-lang/rustc_codegen_gcc

x86_64 asm: Build error when using r[8-15]b

taiki-e opened this issue · 1 comments

The following code passes build with cg_llvm, but fails with cg_gcc.

#[inline(never)]
pub unsafe fn f() {
    core::arch::asm!(
        "",
        out("al") _,
        out("bl") _,
        out("cl") _,
        out("dl") _,
        out("sil") _,
        out("dil") _,
        // out("bpl") _, // frame pointer
        out("r8b") _,
        out("r9b") _,
        out("r10b") _,
        out("r11b") _,
        out("r12b") _,
        out("r13b") _,
        out("r14b") _,
        out("r15b") _,
    );
}

The following is the error message when building with cg_gcc.

libgccjit.so: error: unknown register name 'r15b' in 'asm'
libgccjit.so: error: unknown register name 'r14b' in 'asm'
libgccjit.so: error: unknown register name 'r13b' in 'asm'
libgccjit.so: error: unknown register name 'r12b' in 'asm'
libgccjit.so: error: unknown register name 'r11b' in 'asm'
libgccjit.so: error: unknown register name 'r10b' in 'asm'
libgccjit.so: error: unknown register name 'r9b' in 'asm'
libgccjit.so: error: unknown register name 'r8b' in 'asm'
error: could not copy "/app/output.example.fb61ce7e3f5ff483-cgu.0.rcgu.s" to "/app/output.s": No such file or directory (os error 2)

playground

I could reproduce this with both playground and the latest master branch (75f0ab5).

Reference: https://doc.rust-lang.org/nightly/reference/inline-assembly.html#register-operands

Architecture Register class Registers LLVM constraint code
x86-64 reg_byte* al, bl, cl, dl, sil, dil, bpl, r[8-15]b q

Thanks for the bug report!

It seems GCC doesn't support the b suffix, so we'll need to convert those to the GCC way.