Why are there additional ASM instructions in the open Rust function?

I am wrapping a low-level ABI in Rust using a function function naked. Here is my code and related disassembly

#![feature(asm)]
#![feature(naked_functions)]

struct MyStruct {
    someVar: i64, // not important
                  // ...
}

impl MyStruct {
    #[naked]
    extern "C" fn wrap(&self) {
        unsafe {
            asm!("NOP" :::: "volatile");
            // not sure if the volatile option is needed, but I
            // figured it wouldn't hurt
        }
    }
}

Parsing with LLDB:

ABIWrap`ABIWrap::{{impl}}::wrap:
  * 0x100001310 <+0>:  movq   %rdi, -0x10(%rbp)
  * 0x100001314 <+4>:  movq   %rsi, -0x8(%rbp)
  * 0x100001318 <+8>:  movq   -0x10(%rbp), %rax
  * 0x10000131c <+12>: movq   -0x8(%rbp), %rcx
  * 0x100001320 <+16>: movq   %rax, -0x20(%rbp)
  * 0x100001324 <+20>: movq   %rcx, -0x18(%rbp)
    0x100001328 <+24>: nop    
    0x100001329 <+25>: retq   
    0x10000132a <+26>: nopw   (%rax,%rax)

6 lines preceding NOP (I marked *), I am confused. Should the directive nakedgo away due to the lack of a better term, a bare function?

I am trying to allow the arguments to simply go through this function in the ABI, since this roughly corresponds to the same call as Rust, I just need to change one or two registers, hence the built-in assembly.

6 ? ABI, , , . , , - , .

: "" ? , .

+4
1

, ( , ), , (, , -O0).

-O2 , , #[inline(never)]. , :)

, -O2 , ...

+2

Source: https://habr.com/ru/post/1669765/


All Articles