I was just wondering what exactly causes a function without a prologue/epilogue to be generated? If a program is compiled with just stdcall/cdecl convention, why is it that there are some calls which lead to a subroutine that doesn't have the typical push ebp -> mov ebp,esp. Are these just sanity checks generated by the compiler? Are these subroutines important? Or is that impossible to say without actually analysing it? For example, would a compiler produce a call to a subroutine which moves one value into eax and then returns or would that be the programmer changing the binary of the executable?
-
Do you know what the purpose is from a prologue/epilogue?– JongwareJan 4, 2018 at 13:49
-
What this prologue code does is save the stack frame address. Later on at the end of the function, in the epilogue code, the stack frame gets restored again. You can disable this behaviour in the compiler flags if you wish.– user2073973Jan 4, 2018 at 15:02
-
Related: stackoverflow.com/questions/43310704/…– Ciro Santilli OurBigBook.comMar 23, 2020 at 19:58
2 Answers
The prologue and epilogue are not required by the CPU to execute functions, so most compilers only generate them when necessary, or optimization is not enabled. In particular, leaf functions (those that don't call other functions) do not usually need a prolog (unless required by the ABI) and the compiler may safely omit it.
Frame-Pointer Omission compiler option: https://msdn.microsoft.com/en-us/library/2kxx5t2c.aspx
For gcc see -fomit-frame-pointer https://gcc.gnu.org/onlinedocs/gcc-4.5.2/gcc/Optimize-Options.html
-
That is quite specific for Microsoft's compiler – which indicates that without, it will generate a prologue/epilogue even when not needed. I dare say there is another, better reason.– JongwareJan 4, 2018 at 16:51
-
No, it disables prologue/epilogue generation it /Oy specified. And this is default behavior for the Release build. But you may specify /Oy- if you still want prologues in release code. Jan 5, 2018 at 9:36