Saving unnecessary stack during disassembly?

(Using Apple LLVM version 8.1.0 (clang-802.0.42) Target: x86_64-apple-darwin16.6.0 )

When disassembling some code compiled with -O2 , I noticed that many of them have seemingly unnecessary saving and restoring the rbp base pointer, which usually looks like this

 pushq %rbp movq %rsp, %rbp ... popq %rbp 

I know what this would be for, but it seems to be used even in situations where it seems completely unnecessary, for example, in the next parsed convolution identification function emitted by objdump

 __Z8identityI5arrayIiLm2EEET_S2_: 60: 55 pushq %rbp 61: 48 89 e5 movq %rsp, %rbp 64: 48 89 f8 movq %rdi, %rax 67: 5d popq %rbp 68: c3 retq 69: 0f 1f 80 00 00 00 00 nopl (%rax) 

where the only two meaningful instructions are moving from rdi to rax (the first argument to return the register) and obviously the necessary retq (I assume that nopl intended to fill or align for any subsequent).

Is there a reason for this seemingly unnecessary context save?

+5
source share

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


All Articles