-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
Proposal Details
We consider the frame pointer as a scratch register however the assembler and compiler toolchain avoids it at all cost (restoring SP
using additions in function epilogues, making stack operations SP
relative) and we still materialize the frame pointer, will not use it in register allocation.
All of this because tracing, profiling and debugging code relies on it being correct for backtraces.
We make a point about fixing bugs related to frame pointer corruptions / fixing assembly routines using the frame pointer: https://github.com/golang/go/issues?q=is%3Aissue%20state%3Aclosed%20frame%20pointer%20in%3Atitle
Unless I am missing something these bugs are only found the hard way, so I propose that we add the checkframepointer
debugging option, when enabled as part of all function epilogues the assembler will compare the frame pointer restored from SP
addition with the frame pointer used by tracing / profiling / debugging code.
If they do not match the program will throw (irrecoverably crash).
It's somewhat limited in the bugs it can catch, preemptive tools rely on the frame pointer being correct at any instruction in the program, but this is more expensive to check.
You can fool function epilogue check by corrupting the frame pointer and then restoring it before returning.
This would allow us to run some buildbots with this option enabled and should catch some bugs before they get to users.
Third party go modules with assembly routines can also use this in their tests and make sure they are not accidentally corrupting the frame pointer.