From d9557523c2febc29ad3ecab8b1a4358abd709b30 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 25 May 2016 20:01:25 -0400 Subject: [PATCH] runtime: make framepointer mode safe for Windows A few other architectures have already defined a NOFRAME flag. Use it to disable frame pointer code on a few very low-level functions that must behave like Windows code. Makes the failing os/signal test pass on a Windows gomote. Change-Id: I982365f2c59a0aa302b4428c970846c61027cf3e Reviewed-on: https://go-review.googlesource.com/23456 Reviewed-by: Austin Clements --- src/cmd/internal/obj/x86/obj6.go | 3 +-- src/runtime/sys_windows_amd64.s | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go index df774437ac..0f1f28d36d 100644 --- a/src/cmd/internal/obj/x86/obj6.go +++ b/src/cmd/internal/obj/x86/obj6.go @@ -610,12 +610,11 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) { } var bpsize int - if p.Mode == 64 && obj.Framepointer_enabled != 0 && autoffset > 0 { + if p.Mode == 64 && obj.Framepointer_enabled != 0 && autoffset > 0 && p.From3.Offset&obj.NOFRAME == 0 { // Make room for to save a base pointer. If autoffset == 0, // this might do something special like a tail jump to // another function, so in that case we omit this. bpsize = ctxt.Arch.PtrSize - autoffset += int32(bpsize) p.To.Offset += int64(bpsize) } else { diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s index d550a818ce..9c197379fb 100644 --- a/src/runtime/sys_windows_amd64.s +++ b/src/runtime/sys_windows_amd64.s @@ -11,7 +11,7 @@ #define maxargs 16 // void runtime·asmstdcall(void *c); -TEXT runtime·asmstdcall(SB),NOSPLIT,$0 +TEXT runtime·asmstdcall(SB),NOSPLIT|NOFRAME,$0 // asmcgocall will put first argument into CX. PUSHQ CX // save for later MOVQ libcall_fn(CX), AX @@ -62,7 +62,7 @@ loadregs: RET -TEXT runtime·badsignal2(SB),NOSPLIT,$48 +TEXT runtime·badsignal2(SB),NOSPLIT|NOFRAME,$48 // stderr MOVQ $-12, CX // stderr MOVQ CX, 0(SP) @@ -102,7 +102,7 @@ TEXT runtime·setlasterror(SB),NOSPLIT,$0 // exception record and context pointers. // Handler function is stored in AX. // Return 0 for 'not handled', -1 for handled. -TEXT runtime·sigtramp(SB),NOSPLIT,$0-0 +TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0-0 // CX: PEXCEPTION_POINTERS ExceptionInfo // DI SI BP BX R12 R13 R14 R15 registers and DF flag are preserved @@ -190,32 +190,32 @@ done: RET -TEXT runtime·exceptiontramp(SB),NOSPLIT,$0 +TEXT runtime·exceptiontramp(SB),NOSPLIT|NOFRAME,$0 MOVQ $runtime·exceptionhandler(SB), AX JMP runtime·sigtramp(SB) -TEXT runtime·firstcontinuetramp(SB),NOSPLIT,$0-0 +TEXT runtime·firstcontinuetramp(SB),NOSPLIT|NOFRAME,$0-0 MOVQ $runtime·firstcontinuehandler(SB), AX JMP runtime·sigtramp(SB) -TEXT runtime·lastcontinuetramp(SB),NOSPLIT,$0-0 +TEXT runtime·lastcontinuetramp(SB),NOSPLIT|NOFRAME,$0-0 MOVQ $runtime·lastcontinuehandler(SB), AX JMP runtime·sigtramp(SB) -TEXT runtime·ctrlhandler(SB),NOSPLIT,$8 +TEXT runtime·ctrlhandler(SB),NOSPLIT|NOFRAME,$8 MOVQ CX, 16(SP) // spill MOVQ $runtime·ctrlhandler1(SB), CX MOVQ CX, 0(SP) CALL runtime·externalthreadhandler(SB) RET -TEXT runtime·profileloop(SB),NOSPLIT,$8 +TEXT runtime·profileloop(SB),NOSPLIT|NOFRAME,$8 MOVQ $runtime·profileloop1(SB), CX MOVQ CX, 0(SP) CALL runtime·externalthreadhandler(SB) RET -TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0 +TEXT runtime·externalthreadhandler(SB),NOSPLIT|NOFRAME,$0 PUSHQ BP MOVQ SP, BP PUSHQ BX @@ -228,7 +228,7 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0 SUBQ $m__size, SP // space for M MOVQ SP, 0(SP) MOVQ $m__size, 8(SP) - CALL runtime·memclr(SB) // smashes AX,BX,CX + CALL runtime·memclr(SB) // smashes AX,BX,CX, maybe BP LEAQ m_tls(SP), CX MOVQ CX, 0x28(GS) @@ -239,7 +239,7 @@ TEXT runtime·externalthreadhandler(SB),NOSPLIT,$0 MOVQ SP, 0(SP) MOVQ $g__size, 8(SP) - CALL runtime·memclr(SB) // smashes AX,BX,CX + CALL runtime·memclr(SB) // smashes AX,BX,CX, maybe BP LEAQ g__size(SP), BX MOVQ BX, g_m(SP) @@ -430,7 +430,7 @@ ret: // Runs on OS stack. duration (in 100ns units) is in BX. // The function leaves room for 4 syscall parameters // (as per windows amd64 calling convention). -TEXT runtime·usleep2(SB),NOSPLIT,$48 +TEXT runtime·usleep2(SB),NOSPLIT|NOFRAME,$48 MOVQ SP, AX ANDQ $~15, SP // alignment as per Windows requirement MOVQ AX, 40(SP) @@ -446,7 +446,7 @@ TEXT runtime·usleep2(SB),NOSPLIT,$48 RET // Runs on OS stack. -TEXT runtime·switchtothread(SB),NOSPLIT,$0 +TEXT runtime·switchtothread(SB),NOSPLIT|NOFRAME,$0 MOVQ SP, AX ANDQ $~15, SP // alignment as per Windows requirement SUBQ $(48), SP // room for SP and 4 args as per Windows requirement -- 2.50.0