If I compile an empty C function
void nothing(void)
{
}
using gcc -O2 -S
(and clang
) on MacOS, it generates:
_nothing:
pushq %rbp
movq %rsp, %rbp
popq %rbp
ret
Why does gcc
not remove everything but the ret
? It seems like an easy optimisation to make unless it really does something (seems not to, to me). This pattern (push/move at the beginning, pop at the end) is also visible in other non-empty functions where rbp
is otherwise unused.
On Linux using a more recent gcc
(4.4.5) I see just
nothing:
rep
ret
Why the rep
? The rep
is absent in non-empty functions.