1
0
mirror of https://github.com/golang/go synced 2024-07-01 07:56:09 +00:00

cmd/compile: generate args_stackmap for ABI0 assembly func regardless of linkname

Currently, the compiler generates the argument stack map based on
the function signature for bodyless function declarations, if it
is not linknamed. The assumption is that linknamed function is
provided by (Go code in) another package, so its args stack map
will be generated when compiling that package.

Now we have linknames added to declarations of assembly functions,
to signal that this function is accessed externally. Examples
include runtime.morestack_noctxt, math/big.addVV. In the current
implementation the compiler does not generate its args stack map.
That causes the assembly function's args stack map missing.
Instead, change it to generate the stack map if it is a
declaration of an ABI0 function, which can only be defined in
assembly and passed to the compiler through the -symabis flag. The
stack map generation currently only works with ABI0 layout anyway,
so we don't need to handle ABIInternal assembly functions.

Change-Id: Ic9da3b4854c604e64ed01584da3865994f5b95b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/587928
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Mui 2024-05-24 15:00:56 -04:00
parent 98529a8e7c
commit 0b72631a82
5 changed files with 49 additions and 2 deletions

View File

@ -58,8 +58,13 @@ func enqueueFunc(fn *ir.Func) {
types.CalcSize(fn.Type())
a := ssagen.AbiForBodylessFuncStackMap(fn)
abiInfo := a.ABIAnalyzeFuncType(fn.Type()) // abiInfo has spill/home locations for wrapper
liveness.WriteFuncMap(fn, abiInfo)
if fn.ABI == obj.ABI0 {
// The current args_stackmap generation assumes the function
// is ABI0, and only ABI0 assembly function can have a FUNCDATA
// reference to args_stackmap (see cmd/internal/obj/plist.go:Flushplist).
// So avoid introducing an args_stackmap if the func is not ABI0.
liveness.WriteFuncMap(fn, abiInfo)
x := ssagen.EmitArgInfo(fn, abiInfo)
objw.Global(x, int32(len(x.P)), obj.RODATA|obj.LOCAL)
}

View File

@ -1536,7 +1536,7 @@ func isfat(t *types.Type) bool {
// inputs and outputs as the value of symbol <fn>.args_stackmap.
// If fn has outputs, two bitmaps are written, otherwise just one.
func WriteFuncMap(fn *ir.Func, abiInfo *abi.ABIParamResultInfo) {
if ir.FuncName(fn) == "_" || fn.Sym().Linkname != "" {
if ir.FuncName(fn) == "_" {
return
}
nptr := int(abiInfo.ArgWidth() / int64(types.PtrSize))

View File

@ -0,0 +1,7 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
TEXT ·asm(SB),0,$0-8
CALL ·callback(SB)
RET

26
test/linknameasm.dir/x.go Normal file
View File

@ -0,0 +1,26 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that a linkname applied on an assembly declaration
// does not affect stack map generation.
package main
import (
"runtime"
_ "unsafe"
)
//go:linkname asm
func asm(*int)
func main() {
x := new(int)
asm(x)
}
// called from asm
func callback() {
runtime.GC() // scan stack
}

9
test/linknameasm.go Normal file
View File

@ -0,0 +1,9 @@
// buildrundir
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build amd64
package ignored