Skip to content

Commit 521d261

Browse files
committed
runtime: use explicit NOFRAME on linux/amd64
This CL marks some linux assembly functions as NOFRAME to avoid relying on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions without stack were also marked as NOFRAME. Updates #58378 Change-Id: I7792cff4f6e539bfa56c02868f2965088ca1975a Reviewed-on: https://go-review.googlesource.com/c/go/+/466316 Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Quim Muntal <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 133e0bc commit 521d261

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/cmd/internal/obj/x86/obj6.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,23 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
611611
}
612612
}
613613

614+
var usefpheuristic bool
615+
switch ctxt.Headtype {
616+
case objabi.Hwindows, objabi.Hdarwin, objabi.Hlinux:
617+
default:
618+
usefpheuristic = true
619+
}
620+
614621
var bpsize int
615622
if ctxt.Arch.Family == sys.AMD64 &&
616623
!p.From.Sym.NoFrame() && // (1) below
617-
!(autoffset == 0 && p.From.Sym.NoSplit() && ctxt.Headtype != objabi.Hwindows && ctxt.Headtype != objabi.Hdarwin) && // (2) below
624+
!(autoffset == 0 && p.From.Sym.NoSplit() && usefpheuristic) && // (2) below
618625
!(autoffset == 0 && !hasCall) { // (3) below
619626
// Make room to save a base pointer.
620627
// There are 2 cases we must avoid:
621628
// 1) If noframe is set (which we do for functions which tail call).
622629
// 2) Scary runtime internals which would be all messed up by frame pointers.
623630
// We detect these using a heuristic: frameless nosplit functions.
624-
// Windows and Darwin do not use this heuristic anymore.
625631
// TODO: Maybe someday we label them all with NOFRAME and get rid of this heuristic.
626632
// For performance, we also want to avoid:
627633
// 3) Frameless leaf functions

src/cmd/link/internal/ld/testdata/stackcheck/main.s

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// license that can be found in the LICENSE file.
44

55
#define NOSPLIT 7
6+
#define NOFRAME 512
67

78
TEXT ·asmMain(SB),0,$0-0
89
CALL ·startSelf(SB)
@@ -32,9 +33,9 @@ TEXT ·chainEnd(SB),NOSPLIT,$1000-0 // Should be reported twice
3233
RET
3334

3435
// Test reporting of rootless recursion
35-
TEXT ·startRec(SB),NOSPLIT,$0-0
36+
TEXT ·startRec(SB),NOSPLIT|NOFRAME,$0-0
3637
CALL ·startRec0(SB)
3738
RET
38-
TEXT ·startRec0(SB),NOSPLIT,$0-0
39+
TEXT ·startRec0(SB),NOSPLIT|NOFRAME,$0-0
3940
CALL ·startRec(SB)
4041
RET

src/runtime/sys_linux_amd64.s

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,14 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
325325
MOVL sig+8(FP), DI
326326
MOVQ info+16(FP), SI
327327
MOVQ ctx+24(FP), DX
328-
PUSHQ BP
329-
MOVQ SP, BP
328+
MOVQ SP, BX // callee-saved
330329
ANDQ $~15, SP // alignment for x86_64 ABI
331330
CALL AX
332-
MOVQ BP, SP
333-
POPQ BP
331+
MOVQ BX, SP
334332
RET
335333

336334
// Called using C ABI.
337-
TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
335+
TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
338336
// Transition from C ABI to Go ABI.
339337
PUSH_REGS_HOST_TO_ABI0()
340338

@@ -359,7 +357,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
359357
RET
360358

361359
// Called using C ABI.
362-
TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$0
360+
TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT|NOFRAME,$0
363361
// Transition from C ABI to Go ABI.
364362
PUSH_REGS_HOST_TO_ABI0()
365363

@@ -556,7 +554,7 @@ TEXT runtime·futex(SB),NOSPLIT,$0
556554
RET
557555

558556
// int32 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
559-
TEXT runtime·clone(SB),NOSPLIT,$0
557+
TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
560558
MOVL flags+0(FP), DI
561559
MOVQ stk+8(FP), SI
562560
MOVQ $0, DX
@@ -620,7 +618,7 @@ nog2:
620618
SYSCALL
621619
JMP -3(PC) // keep exiting
622620

623-
TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
621+
TEXT runtime·sigaltstack(SB),NOSPLIT,$0
624622
MOVQ new+0(FP), DI
625623
MOVQ old+8(FP), SI
626624
MOVQ $SYS_sigaltstack, AX

0 commit comments

Comments
 (0)