-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Description
Wrapper functions (such as those found in CL 36809) have an extra prologue inserted during preprocessing. Quoting cmd/internal/obj/xk86/obj6.go (after CL 36833), what this does is:
// if g._panic != nil && g._panic.argp == FP {
// g._panic.argp = bottom-of-frame
// }
//
// MOVQ g_panic(CX), BX
// TESTQ BX, BX
// JEQ end
// LEAQ (autoffset+8)(SP), DI
// CMPQ panic_argp(BX), DI
// JNE end
// MOVQ SP, panic_argp(BX)
// end:
// NOP
These jumps are the wrong direction. Static branch prediction says forward jumps are not taken, but the first forward jump is almost always taken. Rearrange the code to fix that.
I have a CL, to be mailed momentarily, that does this. However, I am having a hard time writing a test for this, because I cannot find a way to trigger the rare (in-a-panic) cases. From reading the panic sources, this only happens when panicking inside a deferred statement (?), but even then I see the wrapper function in the traceback.
What exactly is this prologue for? How do I test that it is doing its job correctly?
cc @randall77 @minux