问题
Recently I rewrote some libc functions in assembly and for some of them (the one that didn't need any call or syscall instructions, like strlen), I discarded the prologue and epilogue because my tests didn't failed without it (maybe they were not complex enough). During peer review, someone told me it was bad practice to discard them, but couldn't explain me why.
So, am I running into problems when I call asm functions that don't have the prologue/epilogue combination?
Is it a good practice to add it even when no additionnal space is needed on the stack?
If mandatory for some reasons, why doesn't the assembler (I used nasm) take care of it?
回答1:
If you do not set up a proper stack frame, it can be hard for a debugger to know what function you are in right now. On ELF-targets, you have to manually provide CFI data (cf. this article) if you do not explicitly set up a stack frame. Without CFI data, stack unwinding doesn't work and the debugger might not be able to find out what function you are in. Unless you want to manually add CFI data (which is somewhat tedious and easy to get wrong), I recommend you to accept the minor performance loss and just set up a full stack frame.
来源:https://stackoverflow.com/questions/42208087/are-the-prologue-and-epilogue-mandatory-when-writing-assembly-functions