Are prologs and epilogues mandatory when writing assembly functions?

I recently rewrote some libc functions in assembler and for some of them (those that did not need any call or system call instructions, for example, strlen), I refused the prolog and epilog because my tests did not fail without it ( perhaps they were not complicated enough). During the review, someone told me that dropping them is a bad practice, but could not explain why.

So, do I encounter problems when I call asm functions that do not have a prolog / epilogue combination?

Is it useful to add it even if the stack does not require additional space?

If this is necessary for some reason, why the assembler (I used nasm) will not take care of this?

+6
source share
1 answer

If you do not configure the correct stack frame, it may be difficult for the debugger to know what function you are currently in. For ELF purposes, you must manually provide CFI data (see this article ) if you have not explicitly configured the stack frame. Without CFI data, stack unwinding does not work, and the debugger may not determine what function you are in. If you do not want to manually add CFI data (which is somewhat tedious and easy to make mistakes), I recommend that you accept a slight performance loss and just set the full frame frame.

+5
source

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


All Articles