1
0
mirror of https://github.com/golang/go synced 2024-11-23 12:00:14 -07:00

runtime: use explicit NOFRAME on darwin/amd64

This CL marks some darwin assembly functions as NOFRAME to avoid relying
on the implicit amd64 NOFRAME heuristic, where NOSPLIT functions
without stack were also marked as NOFRAME.

Change-Id: I797f3909bcf7f7aad304e4ede820c884231e54f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/460235
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
qmuntal 2023-01-02 15:54:44 +01:00 committed by Quim Muntal
parent 89de906aa2
commit cea70301e2
2 changed files with 15 additions and 160 deletions

View File

@ -614,14 +614,14 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
var bpsize int
if ctxt.Arch.Family == sys.AMD64 &&
!p.From.Sym.NoFrame() && // (1) below
!(autoffset == 0 && p.From.Sym.NoSplit() && ctxt.Headtype != objabi.Hwindows) && // (2) below
!(autoffset == 0 && p.From.Sym.NoSplit() && ctxt.Headtype != objabi.Hwindows && ctxt.Headtype != objabi.Hdarwin) && // (2) below
!(autoffset == 0 && !hasCall) { // (3) below
// Make room to save a base pointer.
// There are 2 cases we must avoid:
// 1) If noframe is set (which we do for functions which tail call).
// 2) Scary runtime internals which would be all messed up by frame pointers.
// We detect these using a heuristic: frameless nosplit functions.
// Windows does not use this heuristic anymore.
// Windows and Darwin do not use this heuristic anymore.
// TODO: Maybe someday we label them all with NOFRAME and get rid of this heuristic.
// For performance, we also want to avoid:
// 3) Frameless leaf functions

View File

@ -15,36 +15,25 @@
// Exit the entire program (like C exit)
TEXT runtime·exit_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 0(DI), DI // arg 1 exit status
CALL libc_exit(SB)
MOVL $0xf1, 0xf1 // crash
POPQ BP
RET
TEXT runtime·open_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 8(DI), SI // arg 2 flags
MOVL 12(DI), DX // arg 3 mode
MOVQ 0(DI), DI // arg 1 pathname
XORL AX, AX // vararg: say "no float args"
CALL libc_open(SB)
POPQ BP
RET
TEXT runtime·close_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 0(DI), DI // arg 1 fd
CALL libc_close(SB)
POPQ BP
RET
TEXT runtime·read_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 buf
MOVL 16(DI), DX // arg 3 count
MOVL 0(DI), DI // arg 1 fd
@ -55,12 +44,9 @@ TEXT runtime·read_trampoline(SB),NOSPLIT,$0
MOVL (AX), AX
NEGL AX // caller expects negative errno value
noerr:
POPQ BP
RET
TEXT runtime·write_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 buf
MOVL 16(DI), DX // arg 3 count
MOVQ 0(DI), DI // arg 1 fd
@ -71,39 +57,29 @@ TEXT runtime·write_trampoline(SB),NOSPLIT,$0
MOVL (AX), AX
NEGL AX // caller expects negative errno value
noerr:
POPQ BP
RET
TEXT runtime·pipe_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
CALL libc_pipe(SB) // pointer already in DI
TESTL AX, AX
JEQ 3(PC)
CALL libc_error(SB) // return negative errno value
NEGL AX
POPQ BP
RET
TEXT runtime·setitimer_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 new
MOVQ 16(DI), DX // arg 3 old
MOVL 0(DI), DI // arg 1 which
CALL libc_setitimer(SB)
POPQ BP
RET
TEXT runtime·madvise_trampoline(SB), NOSPLIT, $0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 len
MOVL 16(DI), DX // arg 3 advice
MOVQ 0(DI), DI // arg 1 addr
CALL libc_madvise(SB)
// ignore failure - maybe pages are locked
POPQ BP
RET
TEXT runtime·mlock_trampoline(SB), NOSPLIT, $0
@ -112,8 +88,6 @@ TEXT runtime·mlock_trampoline(SB), NOSPLIT, $0
GLOBL timebase<>(SB),NOPTR,$(machTimebaseInfo__size)
TEXT runtime·nanotime_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ DI, BX
CALL libc_mach_absolute_time(SB)
MOVQ AX, 0(BX)
@ -137,21 +111,15 @@ initialized:
MOVL SI, 8(BX)
MOVL DI, 12(BX)
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·walltime_trampoline(SB),NOSPLIT,$0
PUSHQ BP // make a frame; keep stack aligned
MOVQ SP, BP
MOVQ DI, SI // arg 2 timespec
MOVL $CLOCK_REALTIME, DI // arg 1 clock_id
CALL libc_clock_gettime(SB)
POPQ BP
RET
TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 new
MOVQ 16(DI), DX // arg 3 old
MOVL 0(DI), DI // arg 1 sig
@ -159,12 +127,9 @@ TEXT runtime·sigaction_trampoline(SB),NOSPLIT,$0
TESTL AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash
POPQ BP
RET
TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 new
MOVQ 16(DI), DX // arg 3 old
MOVL 0(DI), DI // arg 1 how
@ -172,33 +137,26 @@ TEXT runtime·sigprocmask_trampoline(SB),NOSPLIT,$0
TESTL AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash
POPQ BP
RET
TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 old
MOVQ 0(DI), DI // arg 1 new
CALL libc_sigaltstack(SB)
TESTQ AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash
POPQ BP
RET
TEXT runtime·raiseproc_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 0(DI), BX // signal
CALL libc_getpid(SB)
MOVL AX, DI // arg 1 pid
MOVL BX, SI // arg 2 signal
CALL libc_kill(SB)
POPQ BP
RET
TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
TEXT runtime·sigfwd(SB),NOSPLIT|NOFRAME,$0-32
MOVQ fn+0(FP), AX
MOVL sig+8(FP), DI
MOVQ info+16(FP), SI
@ -214,7 +172,7 @@ TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
// This is the function registered during sigaction and is invoked when
// a signal is received. It just redirects to the Go function sigtrampgo.
// Called using C ABI.
TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME|NOFRAME,$0
// Transition from C ABI to Go ABI.
PUSH_REGS_HOST_TO_ABI0()
@ -239,7 +197,7 @@ TEXT runtime·sigtramp(SB),NOSPLIT|TOPFRAME,$0
RET
// Called using C ABI.
TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$0
TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT|NOFRAME,$0
// Transition from C ABI to Go ABI.
PUSH_REGS_HOST_TO_ABI0()
@ -257,7 +215,7 @@ TEXT runtime·sigprofNonGoWrapper<>(SB),NOSPLIT,$0
// Used instead of sigtramp in programs that use cgo.
// Arguments from kernel are in DI, SI, DX.
TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
TEXT runtime·cgoSigtramp(SB),NOSPLIT|NOFRAME,$0
// If no traceback function, do usual sigtramp.
MOVQ runtime·cgoTraceback(SB), AX
TESTQ AX, AX
@ -332,8 +290,6 @@ sigtrampnog:
JMP AX
TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
PUSHQ BP // make a frame; keep stack aligned
MOVQ SP, BP
MOVQ DI, BX
MOVQ 0(BX), DI // arg 1 addr
MOVQ 8(BX), SI // arg 2 len
@ -351,27 +307,20 @@ TEXT runtime·mmap_trampoline(SB),NOSPLIT,$0
ok:
MOVQ AX, 32(BX)
MOVQ DX, 40(BX)
POPQ BP
RET
TEXT runtime·munmap_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 len
MOVQ 0(DI), DI // arg 1 addr
CALL libc_munmap(SB)
TESTQ AX, AX
JEQ 2(PC)
MOVL $0xf1, 0xf1 // crash
POPQ BP
RET
TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 0(DI), DI // arg 1 usec
CALL libc_usleep(SB)
POPQ BP
RET
TEXT runtime·settls(SB),NOSPLIT,$32
@ -379,8 +328,6 @@ TEXT runtime·settls(SB),NOSPLIT,$32
RET
TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 8(DI), SI // arg 2 miblen
MOVQ 16(DI), DX // arg 3 oldp
MOVQ 24(DI), CX // arg 4 oldlenp
@ -388,31 +335,22 @@ TEXT runtime·sysctl_trampoline(SB),NOSPLIT,$0
MOVQ 40(DI), R9 // arg 6 newlen
MOVQ 0(DI), DI // arg 1 mib
CALL libc_sysctl(SB)
POPQ BP
RET
TEXT runtime·sysctlbyname_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 oldp
MOVQ 16(DI), DX // arg 3 oldlenp
MOVQ 24(DI), CX // arg 4 newp
MOVQ 32(DI), R8 // arg 5 newlen
MOVQ 0(DI), DI // arg 1 name
CALL libc_sysctlbyname(SB)
POPQ BP
RET
TEXT runtime·kqueue_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
CALL libc_kqueue(SB)
POPQ BP
RET
TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 keventt
MOVL 16(DI), DX // arg 3 nch
MOVQ 24(DI), CX // arg 4 ev
@ -426,24 +364,20 @@ TEXT runtime·kevent_trampoline(SB),NOSPLIT,$0
MOVLQSX (AX), AX // errno
NEGQ AX // caller wants it as a negative error code
ok:
POPQ BP
RET
TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 4(DI), SI // arg 2 cmd
MOVL 8(DI), DX // arg 3 arg
MOVL 0(DI), DI // arg 1 fd
XORL AX, AX // vararg: say "no float args"
CALL libc_fcntl(SB)
POPQ BP
RET
// mstart_stub is the first function executed on a new thread started by pthread_create.
// It just does some low-level setup and then calls mstart.
// Note: called with the C calling convention.
TEXT runtime·mstart_stub(SB),NOSPLIT,$0
TEXT runtime·mstart_stub(SB),NOSPLIT|NOFRAME,$0
// DI points to the m.
// We are already on m's g0 stack.
@ -472,129 +406,85 @@ TEXT runtime·mstart_stub(SB),NOSPLIT,$0
// A single int32 result is returned in AX.
// (For more results, make an args/results structure.)
TEXT runtime·pthread_attr_init_trampoline(SB),NOSPLIT,$0
PUSHQ BP // make frame, keep stack 16-byte aligned.
MOVQ SP, BP
MOVQ 0(DI), DI // arg 1 attr
CALL libc_pthread_attr_init(SB)
POPQ BP
RET
TEXT runtime·pthread_attr_getstacksize_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 size
MOVQ 0(DI), DI // arg 1 attr
CALL libc_pthread_attr_getstacksize(SB)
POPQ BP
RET
TEXT runtime·pthread_attr_setdetachstate_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 state
MOVQ 0(DI), DI // arg 1 attr
CALL libc_pthread_attr_setdetachstate(SB)
POPQ BP
RET
TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·pthread_create_trampoline(SB),NOSPLIT,$16
MOVQ 0(DI), SI // arg 2 attr
MOVQ 8(DI), DX // arg 3 start
MOVQ 16(DI), CX // arg 4 arg
MOVQ SP, DI // arg 1 &threadid (which we throw away)
CALL libc_pthread_create(SB)
MOVQ BP, SP
POPQ BP
RET
TEXT runtime·raise_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVL 0(DI), DI // arg 1 signal
CALL libc_raise(SB)
POPQ BP
RET
TEXT runtime·pthread_mutex_init_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 attr
MOVQ 0(DI), DI // arg 1 mutex
CALL libc_pthread_mutex_init(SB)
POPQ BP
RET
TEXT runtime·pthread_mutex_lock_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 0(DI), DI // arg 1 mutex
CALL libc_pthread_mutex_lock(SB)
POPQ BP
RET
TEXT runtime·pthread_mutex_unlock_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 0(DI), DI // arg 1 mutex
CALL libc_pthread_mutex_unlock(SB)
POPQ BP
RET
TEXT runtime·pthread_cond_init_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 attr
MOVQ 0(DI), DI // arg 1 cond
CALL libc_pthread_cond_init(SB)
POPQ BP
RET
TEXT runtime·pthread_cond_wait_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 mutex
MOVQ 0(DI), DI // arg 1 cond
CALL libc_pthread_cond_wait(SB)
POPQ BP
RET
TEXT runtime·pthread_cond_timedwait_relative_np_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 mutex
MOVQ 16(DI), DX // arg 3 timeout
MOVQ 0(DI), DI // arg 1 cond
CALL libc_pthread_cond_timedwait_relative_np(SB)
POPQ BP
RET
TEXT runtime·pthread_cond_signal_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 0(DI), DI // arg 1 cond
CALL libc_pthread_cond_signal(SB)
POPQ BP
RET
TEXT runtime·pthread_self_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ DI, BX // BX is caller-save
CALL libc_pthread_self(SB)
MOVQ AX, 0(BX) // return value
POPQ BP
RET
TEXT runtime·pthread_kill_trampoline(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
MOVQ 8(DI), SI // arg 2 sig
MOVQ 0(DI), DI // arg 1 thread
CALL libc_pthread_kill(SB)
POPQ BP
RET
TEXT runtime·osinit_hack_trampoline(SB),NOSPLIT,$0
@ -622,10 +512,7 @@ TEXT runtime·osinit_hack_trampoline(SB),NOSPLIT,$0
//
// syscall expects a 32-bit result and tests for 32-bit -1
// to decide there was an error.
TEXT runtime·syscall(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscall(SB),NOSPLIT,$16
MOVQ (0*8)(DI), CX // fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -652,8 +539,6 @@ TEXT runtime·syscall(SB),NOSPLIT,$0
ok:
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET
// syscallX calls a function in libc on behalf of the syscall package.
@ -672,10 +557,7 @@ ok:
//
// syscallX is like syscall but expects a 64-bit result
// and tests for 64-bit -1 to decide there was an error.
TEXT runtime·syscallX(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscallX(SB),NOSPLIT,$16
MOVQ (0*8)(DI), CX // fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -702,16 +584,11 @@ TEXT runtime·syscallX(SB),NOSPLIT,$0
ok:
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET
// syscallPtr is like syscallX except that the libc function reports an
// error by returning NULL and setting errno.
TEXT runtime·syscallPtr(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscallPtr(SB),NOSPLIT,$16
MOVQ (0*8)(DI), CX // fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -738,8 +615,6 @@ TEXT runtime·syscallPtr(SB),NOSPLIT,$0
ok:
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET
// syscall6 calls a function in libc on behalf of the syscall package.
@ -761,10 +636,7 @@ ok:
//
// syscall6 expects a 32-bit result and tests for 32-bit -1
// to decide there was an error.
TEXT runtime·syscall6(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscall6(SB),NOSPLIT,$16
MOVQ (0*8)(DI), R11// fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -791,8 +663,6 @@ TEXT runtime·syscall6(SB),NOSPLIT,$0
ok:
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET
// syscall6X calls a function in libc on behalf of the syscall package.
@ -814,10 +684,7 @@ ok:
//
// syscall6X is like syscall6 but expects a 64-bit result
// and tests for 64-bit -1 to decide there was an error.
TEXT runtime·syscall6X(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscall6X(SB),NOSPLIT,$16
MOVQ (0*8)(DI), R11// fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -844,8 +711,6 @@ TEXT runtime·syscall6X(SB),NOSPLIT,$0
ok:
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET
// syscall9 calls a function in libc on behalf of the syscall package.
@ -870,10 +735,7 @@ ok:
//
// syscall9 expects a 32-bit result and tests for 32-bit -1
// to decide there was an error.
TEXT runtime·syscall9(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscall9(SB),NOSPLIT,$16
MOVQ (0*8)(DI), R13// fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -903,17 +765,12 @@ TEXT runtime·syscall9(SB),NOSPLIT,$0
ok:
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET
// syscall_x509 is for crypto/x509. It is like syscall6 but does not check for errors,
// takes 5 uintptrs and 1 float64, and only returns one value,
// for use with standard C ABI functions.
TEXT runtime·syscall_x509(SB),NOSPLIT,$0
PUSHQ BP
MOVQ SP, BP
SUBQ $16, SP
TEXT runtime·syscall_x509(SB),NOSPLIT,$16
MOVQ (0*8)(DI), R11// fn
MOVQ (2*8)(DI), SI // a2
MOVQ (3*8)(DI), DX // a3
@ -930,6 +787,4 @@ TEXT runtime·syscall_x509(SB),NOSPLIT,$0
MOVQ AX, (7*8)(DI) // r1
XORL AX, AX // no error (it's ignored anyway)
MOVQ BP, SP
POPQ BP
RET