Source file src/cmd/compile/internal/ssagen/abi.go

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ssagen
     6  
     7  import (
     8  	"fmt"
     9  	"internal/buildcfg"
    10  	"log"
    11  	"os"
    12  	"strings"
    13  
    14  	"cmd/compile/internal/abi"
    15  	"cmd/compile/internal/base"
    16  	"cmd/compile/internal/ir"
    17  	"cmd/compile/internal/objw"
    18  	"cmd/compile/internal/typecheck"
    19  	"cmd/compile/internal/types"
    20  	"cmd/internal/obj"
    21  	"cmd/internal/obj/wasm"
    22  
    23  	rtabi "internal/abi"
    24  )
    25  
    26  // SymABIs records information provided by the assembler about symbol
    27  // definition ABIs and reference ABIs.
    28  type SymABIs struct {
    29  	defs map[string]obj.ABI
    30  	refs map[string]obj.ABISet
    31  }
    32  
    33  func NewSymABIs() *SymABIs {
    34  	return &SymABIs{
    35  		defs: make(map[string]obj.ABI),
    36  		refs: make(map[string]obj.ABISet),
    37  	}
    38  }
    39  
    40  // canonicalize returns the canonical name used for a linker symbol in
    41  // s's maps. Symbols in this package may be written either as "".X or
    42  // with the package's import path already in the symbol. This rewrites
    43  // both to use the full path, which matches compiler-generated linker
    44  // symbol names.
    45  func (s *SymABIs) canonicalize(linksym string) string {
    46  	if strings.HasPrefix(linksym, `"".`) {
    47  		panic("non-canonical symbol name: " + linksym)
    48  	}
    49  	return linksym
    50  }
    51  
    52  // ReadSymABIs reads a symabis file that specifies definitions and
    53  // references of text symbols by ABI.
    54  //
    55  // The symabis format is a set of lines, where each line is a sequence
    56  // of whitespace-separated fields. The first field is a verb and is
    57  // either "def" for defining a symbol ABI or "ref" for referencing a
    58  // symbol using an ABI. For both "def" and "ref", the second field is
    59  // the symbol name and the third field is the ABI name, as one of the
    60  // named cmd/internal/obj.ABI constants.
    61  func (s *SymABIs) ReadSymABIs(file string) {
    62  	data, err := os.ReadFile(file)
    63  	if err != nil {
    64  		log.Fatalf("-symabis: %v", err)
    65  	}
    66  
    67  	for lineNum, line := range strings.Split(string(data), "\n") {
    68  		lineNum++ // 1-based
    69  		line = strings.TrimSpace(line)
    70  		if line == "" || strings.HasPrefix(line, "#") {
    71  			continue
    72  		}
    73  
    74  		parts := strings.Fields(line)
    75  		switch parts[0] {
    76  		case "def", "ref":
    77  			// Parse line.
    78  			if len(parts) != 3 {
    79  				log.Fatalf(`%s:%d: invalid symabi: syntax is "%s sym abi"`, file, lineNum, parts[0])
    80  			}
    81  			sym, abistr := parts[1], parts[2]
    82  			abi, valid := obj.ParseABI(abistr)
    83  			if !valid {
    84  				log.Fatalf(`%s:%d: invalid symabi: unknown abi "%s"`, file, lineNum, abistr)
    85  			}
    86  
    87  			sym = s.canonicalize(sym)
    88  
    89  			// Record for later.
    90  			if parts[0] == "def" {
    91  				s.defs[sym] = abi
    92  			} else {
    93  				s.refs[sym] |= obj.ABISetOf(abi)
    94  			}
    95  		default:
    96  			log.Fatalf(`%s:%d: invalid symabi type "%s"`, file, lineNum, parts[0])
    97  		}
    98  	}
    99  }
   100  
   101  // GenABIWrappers applies ABI information to Funcs and generates ABI
   102  // wrapper functions where necessary.
   103  func (s *SymABIs) GenABIWrappers() {
   104  	// For cgo exported symbols, we tell the linker to export the
   105  	// definition ABI to C. That also means that we don't want to
   106  	// create ABI wrappers even if there's a linkname.
   107  	//
   108  	// TODO(austin): Maybe we want to create the ABI wrappers, but
   109  	// ensure the linker exports the right ABI definition under
   110  	// the unmangled name?
   111  	cgoExports := make(map[string][]*[]string)
   112  	for i, prag := range typecheck.Target.CgoPragmas {
   113  		switch prag[0] {
   114  		case "cgo_export_static", "cgo_export_dynamic":
   115  			symName := s.canonicalize(prag[1])
   116  			pprag := &typecheck.Target.CgoPragmas[i]
   117  			cgoExports[symName] = append(cgoExports[symName], pprag)
   118  		}
   119  	}
   120  
   121  	// Apply ABI defs and refs to Funcs and generate wrappers.
   122  	//
   123  	// This may generate new decls for the wrappers, but we
   124  	// specifically *don't* want to visit those, lest we create
   125  	// wrappers for wrappers.
   126  	for _, fn := range typecheck.Target.Funcs {
   127  		nam := fn.Nname
   128  		if ir.IsBlank(nam) {
   129  			continue
   130  		}
   131  		sym := nam.Sym()
   132  
   133  		symName := sym.Linkname
   134  		if symName == "" {
   135  			symName = sym.Pkg.Prefix + "." + sym.Name
   136  		}
   137  		symName = s.canonicalize(symName)
   138  
   139  		// Apply definitions.
   140  		defABI, hasDefABI := s.defs[symName]
   141  		if hasDefABI {
   142  			if len(fn.Body) != 0 {
   143  				base.ErrorfAt(fn.Pos(), 0, "%v defined in both Go and assembly", fn)
   144  			}
   145  			fn.ABI = defABI
   146  		}
   147  
   148  		if fn.Pragma&ir.CgoUnsafeArgs != 0 {
   149  			// CgoUnsafeArgs indicates the function (or its callee) uses
   150  			// offsets to dispatch arguments, which currently using ABI0
   151  			// frame layout. Pin it to ABI0.
   152  			fn.ABI = obj.ABI0
   153  			// Propagate linkname attribute, which was set on the ABIInternal
   154  			// symbol.
   155  			if sym.Linksym().IsLinkname() {
   156  				sym.LinksymABI(fn.ABI).Set(obj.AttrLinkname, true)
   157  			}
   158  		}
   159  
   160  		// If cgo-exported, add the definition ABI to the cgo
   161  		// pragmas.
   162  		cgoExport := cgoExports[symName]
   163  		for _, pprag := range cgoExport {
   164  			// The export pragmas have the form:
   165  			//
   166  			//   cgo_export_* <local> [<remote>]
   167  			//
   168  			// If <remote> is omitted, it's the same as
   169  			// <local>.
   170  			//
   171  			// Expand to
   172  			//
   173  			//   cgo_export_* <local> <remote> <ABI>
   174  			if len(*pprag) == 2 {
   175  				*pprag = append(*pprag, (*pprag)[1])
   176  			}
   177  			// Add the ABI argument.
   178  			*pprag = append(*pprag, fn.ABI.String())
   179  		}
   180  
   181  		// Apply references.
   182  		if abis, ok := s.refs[symName]; ok {
   183  			fn.ABIRefs |= abis
   184  		}
   185  		// Assume all functions are referenced at least as
   186  		// ABIInternal, since they may be referenced from
   187  		// other packages.
   188  		fn.ABIRefs.Set(obj.ABIInternal, true)
   189  
   190  		// If a symbol is defined in this package (either in
   191  		// Go or assembly) and given a linkname, it may be
   192  		// referenced from another package, so make it
   193  		// callable via any ABI. It's important that we know
   194  		// it's defined in this package since other packages
   195  		// may "pull" symbols using linkname and we don't want
   196  		// to create duplicate ABI wrappers.
   197  		//
   198  		// However, if it's given a linkname for exporting to
   199  		// C, then we don't make ABI wrappers because the cgo
   200  		// tool wants the original definition.
   201  		hasBody := len(fn.Body) != 0
   202  		if sym.Linkname != "" && (hasBody || hasDefABI) && len(cgoExport) == 0 {
   203  			fn.ABIRefs |= obj.ABISetCallable
   204  		}
   205  
   206  		// Double check that cgo-exported symbols don't get
   207  		// any wrappers.
   208  		if len(cgoExport) > 0 && fn.ABIRefs&^obj.ABISetOf(fn.ABI) != 0 {
   209  			base.Fatalf("cgo exported function %v cannot have ABI wrappers", fn)
   210  		}
   211  
   212  		if !buildcfg.Experiment.RegabiWrappers {
   213  			continue
   214  		}
   215  
   216  		forEachWrapperABI(fn, makeABIWrapper)
   217  	}
   218  }
   219  
   220  func forEachWrapperABI(fn *ir.Func, cb func(fn *ir.Func, wrapperABI obj.ABI)) {
   221  	need := fn.ABIRefs &^ obj.ABISetOf(fn.ABI)
   222  	if need == 0 {
   223  		return
   224  	}
   225  
   226  	for wrapperABI := obj.ABI(0); wrapperABI < obj.ABICount; wrapperABI++ {
   227  		if !need.Get(wrapperABI) {
   228  			continue
   229  		}
   230  		cb(fn, wrapperABI)
   231  	}
   232  }
   233  
   234  // makeABIWrapper creates a new function that will be called with
   235  // wrapperABI and calls "f" using f.ABI.
   236  func makeABIWrapper(f *ir.Func, wrapperABI obj.ABI) {
   237  	if base.Debug.ABIWrap != 0 {
   238  		fmt.Fprintf(os.Stderr, "=-= %v to %v wrapper for %v\n", wrapperABI, f.ABI, f)
   239  	}
   240  
   241  	// Q: is this needed?
   242  	savepos := base.Pos
   243  	savedcurfn := ir.CurFunc
   244  
   245  	pos := base.AutogeneratedPos
   246  	base.Pos = pos
   247  
   248  	// At the moment we don't support wrapping a method, we'd need machinery
   249  	// below to handle the receiver. Panic if we see this scenario.
   250  	ft := f.Nname.Type()
   251  	if ft.NumRecvs() != 0 {
   252  		base.ErrorfAt(f.Pos(), 0, "makeABIWrapper support for wrapping methods not implemented")
   253  		return
   254  	}
   255  
   256  	// Reuse f's types.Sym to create a new ODCLFUNC/function.
   257  	// TODO(mdempsky): Means we can't set sym.Def in Declfunc, ugh.
   258  	fn := ir.NewFunc(pos, pos, f.Sym(), types.NewSignature(nil,
   259  		typecheck.NewFuncParams(ft.Params()),
   260  		typecheck.NewFuncParams(ft.Results())))
   261  	fn.ABI = wrapperABI
   262  	typecheck.DeclFunc(fn)
   263  
   264  	fn.SetABIWrapper(true)
   265  	fn.SetDupok(true)
   266  
   267  	// ABI0-to-ABIInternal wrappers will be mainly loading params from
   268  	// stack into registers (and/or storing stack locations back to
   269  	// registers after the wrapped call); in most cases they won't
   270  	// need to allocate stack space, so it should be OK to mark them
   271  	// as NOSPLIT in these cases. In addition, my assumption is that
   272  	// functions written in assembly are NOSPLIT in most (but not all)
   273  	// cases. In the case of an ABIInternal target that has too many
   274  	// parameters to fit into registers, the wrapper would need to
   275  	// allocate stack space, but this seems like an unlikely scenario.
   276  	// Hence: mark these wrappers NOSPLIT.
   277  	//
   278  	// ABIInternal-to-ABI0 wrappers on the other hand will be taking
   279  	// things in registers and pushing them onto the stack prior to
   280  	// the ABI0 call, meaning that they will always need to allocate
   281  	// stack space. If the compiler marks them as NOSPLIT this seems
   282  	// as though it could lead to situations where the linker's
   283  	// nosplit-overflow analysis would trigger a link failure. On the
   284  	// other hand if they not tagged NOSPLIT then this could cause
   285  	// problems when building the runtime (since there may be calls to
   286  	// asm routine in cases where it's not safe to grow the stack). In
   287  	// most cases the wrapper would be (in effect) inlined, but are
   288  	// there (perhaps) indirect calls from the runtime that could run
   289  	// into trouble here.
   290  	// FIXME: at the moment all.bash does not pass when I leave out
   291  	// NOSPLIT for these wrappers, so all are currently tagged with NOSPLIT.
   292  	fn.Pragma |= ir.Nosplit
   293  
   294  	// Generate call. Use tail call if no params and no returns,
   295  	// but a regular call otherwise.
   296  	//
   297  	// Note: ideally we would be using a tail call in cases where
   298  	// there are params but no returns for ABI0->ABIInternal wrappers,
   299  	// provided that all params fit into registers (e.g. we don't have
   300  	// to allocate any stack space). Doing this will require some
   301  	// extra work in typecheck/walk/ssa, might want to add a new node
   302  	// OTAILCALL or something to this effect.
   303  	tailcall := fn.Type().NumResults() == 0 && fn.Type().NumParams() == 0 && fn.Type().NumRecvs() == 0
   304  	if base.Ctxt.Arch.Name == "ppc64le" && base.Ctxt.Flag_dynlink {
   305  		// cannot tailcall on PPC64 with dynamic linking, as we need
   306  		// to restore R2 after call.
   307  		tailcall = false
   308  	}
   309  	if base.Ctxt.Arch.Name == "amd64" && wrapperABI == obj.ABIInternal {
   310  		// cannot tailcall from ABIInternal to ABI0 on AMD64, as we need
   311  		// to special registers (X15) when returning to ABIInternal.
   312  		tailcall = false
   313  	}
   314  
   315  	var tail ir.Node
   316  	call := ir.NewCallExpr(base.Pos, ir.OCALL, f.Nname, nil)
   317  	call.Args = ir.ParamNames(fn.Type())
   318  	call.IsDDD = fn.Type().IsVariadic()
   319  	tail = call
   320  	if tailcall {
   321  		tail = ir.NewTailCallStmt(base.Pos, call)
   322  	} else if fn.Type().NumResults() > 0 {
   323  		n := ir.NewReturnStmt(base.Pos, nil)
   324  		n.Results = []ir.Node{call}
   325  		tail = n
   326  	}
   327  	fn.Body.Append(tail)
   328  
   329  	typecheck.FinishFuncBody()
   330  
   331  	ir.CurFunc = fn
   332  	typecheck.Stmts(fn.Body)
   333  
   334  	// Restore previous context.
   335  	base.Pos = savepos
   336  	ir.CurFunc = savedcurfn
   337  }
   338  
   339  // CreateWasmImportWrapper creates a wrapper for imported WASM functions to
   340  // adapt them to the Go calling convention. The body for this function is
   341  // generated in cmd/internal/obj/wasm/wasmobj.go
   342  func CreateWasmImportWrapper(fn *ir.Func) bool {
   343  	if fn.WasmImport == nil {
   344  		return false
   345  	}
   346  	if buildcfg.GOARCH != "wasm" {
   347  		base.FatalfAt(fn.Pos(), "CreateWasmImportWrapper call not supported on %s: func was %v", buildcfg.GOARCH, fn)
   348  	}
   349  
   350  	ir.InitLSym(fn, true)
   351  
   352  	setupWasmImport(fn)
   353  
   354  	pp := objw.NewProgs(fn, 0)
   355  	defer pp.Free()
   356  	pp.Text.To.Type = obj.TYPE_TEXTSIZE
   357  	pp.Text.To.Val = int32(types.RoundUp(fn.Type().ArgWidth(), int64(types.RegSize)))
   358  	// Wrapper functions never need their own stack frame
   359  	pp.Text.To.Offset = 0
   360  	pp.Flush()
   361  
   362  	return true
   363  }
   364  
   365  func GenWasmExportWrapper(wrapped *ir.Func) {
   366  	if wrapped.WasmExport == nil {
   367  		return
   368  	}
   369  	if buildcfg.GOARCH != "wasm" {
   370  		base.FatalfAt(wrapped.Pos(), "GenWasmExportWrapper call not supported on %s: func was %v", buildcfg.GOARCH, wrapped)
   371  	}
   372  
   373  	pos := base.AutogeneratedPos
   374  	sym := &types.Sym{
   375  		Name:     wrapped.WasmExport.Name,
   376  		Linkname: wrapped.WasmExport.Name,
   377  	}
   378  	ft := wrapped.Nname.Type()
   379  	fn := ir.NewFunc(pos, pos, sym, types.NewSignature(nil,
   380  		typecheck.NewFuncParams(ft.Params()),
   381  		typecheck.NewFuncParams(ft.Results())))
   382  	fn.ABI = obj.ABI0 // actually wasm ABI
   383  	// The wrapper function has a special calling convention that
   384  	// morestack currently doesn't handle. For now we require that
   385  	// the argument size fits in StackSmall, which we know we have
   386  	// on stack, so we don't need to split stack.
   387  	// cmd/internal/obj/wasm supports only 16 argument "registers"
   388  	// anyway.
   389  	if ft.ArgWidth() > rtabi.StackSmall {
   390  		base.ErrorfAt(wrapped.Pos(), 0, "wasmexport function argument too large")
   391  	}
   392  	fn.Pragma |= ir.Nosplit
   393  
   394  	ir.InitLSym(fn, true)
   395  
   396  	setupWasmExport(fn, wrapped)
   397  
   398  	pp := objw.NewProgs(fn, 0)
   399  	defer pp.Free()
   400  	// TEXT. Has a frame to pass args on stack to the Go function.
   401  	pp.Text.To.Type = obj.TYPE_TEXTSIZE
   402  	pp.Text.To.Val = int32(0)
   403  	pp.Text.To.Offset = types.RoundUp(ft.ArgWidth(), int64(types.RegSize))
   404  	// No locals. (Callee's args are covered in the callee's stackmap.)
   405  	p := pp.Prog(obj.AFUNCDATA)
   406  	p.From.SetConst(rtabi.FUNCDATA_LocalsPointerMaps)
   407  	p.To.Type = obj.TYPE_MEM
   408  	p.To.Name = obj.NAME_EXTERN
   409  	p.To.Sym = base.Ctxt.Lookup("no_pointers_stackmap")
   410  	pp.Flush()
   411  	// Actual code geneneration is in cmd/internal/obj/wasm.
   412  }
   413  
   414  func paramsToWasmFields(f *ir.Func, pragma string, result *abi.ABIParamResultInfo, abiParams []abi.ABIParamAssignment) []obj.WasmField {
   415  	wfs := make([]obj.WasmField, 0, len(abiParams))
   416  	for _, p := range abiParams {
   417  		t := p.Type
   418  		var wt obj.WasmFieldType
   419  		switch t.Kind() {
   420  		case types.TINT32, types.TUINT32:
   421  			wt = obj.WasmI32
   422  		case types.TINT64, types.TUINT64:
   423  			wt = obj.WasmI64
   424  		case types.TFLOAT32:
   425  			wt = obj.WasmF32
   426  		case types.TFLOAT64:
   427  			wt = obj.WasmF64
   428  		case types.TUNSAFEPTR, types.TUINTPTR:
   429  			wt = obj.WasmPtr
   430  		case types.TBOOL:
   431  			wt = obj.WasmBool
   432  		case types.TSTRING:
   433  			// Two parts, (ptr, len)
   434  			wt = obj.WasmPtr
   435  			wfs = append(wfs, obj.WasmField{Type: wt, Offset: p.FrameOffset(result)})
   436  			wfs = append(wfs, obj.WasmField{Type: wt, Offset: p.FrameOffset(result) + int64(types.PtrSize)})
   437  			continue
   438  		case types.TPTR:
   439  			if wasmElemTypeAllowed(t.Elem()) {
   440  				wt = obj.WasmPtr
   441  				break
   442  			}
   443  			fallthrough
   444  		default:
   445  			base.ErrorfAt(f.Pos(), 0, "%s: unsupported parameter type %s", pragma, t.String())
   446  		}
   447  		wfs = append(wfs, obj.WasmField{Type: wt, Offset: p.FrameOffset(result)})
   448  	}
   449  	return wfs
   450  }
   451  
   452  func resultsToWasmFields(f *ir.Func, pragma string, result *abi.ABIParamResultInfo, abiParams []abi.ABIParamAssignment) []obj.WasmField {
   453  	if len(abiParams) > 1 {
   454  		base.ErrorfAt(f.Pos(), 0, "%s: too many return values", pragma)
   455  		return nil
   456  	}
   457  	wfs := make([]obj.WasmField, len(abiParams))
   458  	for i, p := range abiParams {
   459  		t := p.Type
   460  		switch t.Kind() {
   461  		case types.TINT32, types.TUINT32:
   462  			wfs[i].Type = obj.WasmI32
   463  		case types.TINT64, types.TUINT64:
   464  			wfs[i].Type = obj.WasmI64
   465  		case types.TFLOAT32:
   466  			wfs[i].Type = obj.WasmF32
   467  		case types.TFLOAT64:
   468  			wfs[i].Type = obj.WasmF64
   469  		case types.TUNSAFEPTR, types.TUINTPTR:
   470  			wfs[i].Type = obj.WasmPtr
   471  		case types.TBOOL:
   472  			wfs[i].Type = obj.WasmBool
   473  		case types.TPTR:
   474  			if wasmElemTypeAllowed(t.Elem()) {
   475  				wfs[i].Type = obj.WasmPtr
   476  				break
   477  			}
   478  			fallthrough
   479  		default:
   480  			base.ErrorfAt(f.Pos(), 0, "%s: unsupported result type %s", pragma, t.String())
   481  		}
   482  		wfs[i].Offset = p.FrameOffset(result)
   483  	}
   484  	return wfs
   485  }
   486  
   487  // wasmElemTypeAllowed reports whether t is allowed to be passed in memory
   488  // (as a pointer's element type, a field of it, etc.) between the Go wasm
   489  // module and the host.
   490  func wasmElemTypeAllowed(t *types.Type) bool {
   491  	switch t.Kind() {
   492  	case types.TINT8, types.TUINT8, types.TINT16, types.TUINT16,
   493  		types.TINT32, types.TUINT32, types.TINT64, types.TUINT64,
   494  		types.TFLOAT32, types.TFLOAT64, types.TBOOL:
   495  		return true
   496  	case types.TARRAY:
   497  		return wasmElemTypeAllowed(t.Elem())
   498  	case types.TSTRUCT:
   499  		if len(t.Fields()) == 0 {
   500  			return true
   501  		}
   502  		seenHostLayout := false
   503  		for _, f := range t.Fields() {
   504  			sym := f.Type.Sym()
   505  			if sym != nil && sym.Name == "HostLayout" && sym.Pkg.Path == "structs" {
   506  				seenHostLayout = true
   507  				continue
   508  			}
   509  			if !wasmElemTypeAllowed(f.Type) {
   510  				return false
   511  			}
   512  		}
   513  		return seenHostLayout
   514  	}
   515  	// Pointer, and all pointerful types are not allowed, as pointers have
   516  	// different width on the Go side and the host side. (It will be allowed
   517  	// on GOARCH=wasm32.)
   518  	return false
   519  }
   520  
   521  // setupWasmImport calculates the params and results in terms of WebAssembly values for the given function,
   522  // and sets up the wasmimport metadata.
   523  func setupWasmImport(f *ir.Func) {
   524  	wi := obj.WasmImport{
   525  		Module: f.WasmImport.Module,
   526  		Name:   f.WasmImport.Name,
   527  	}
   528  	if wi.Module == wasm.GojsModule {
   529  		// Functions that are imported from the "gojs" module use a special
   530  		// ABI that just accepts the stack pointer.
   531  		// Example:
   532  		//
   533  		// 	//go:wasmimport gojs add
   534  		// 	func importedAdd(a, b uint) uint
   535  		//
   536  		// will roughly become
   537  		//
   538  		// 	(import "gojs" "add" (func (param i32)))
   539  		wi.Params = []obj.WasmField{{Type: obj.WasmI32}}
   540  	} else {
   541  		// All other imported functions use the normal WASM ABI.
   542  		// Example:
   543  		//
   544  		// 	//go:wasmimport a_module add
   545  		// 	func importedAdd(a, b uint) uint
   546  		//
   547  		// will roughly become
   548  		//
   549  		// 	(import "a_module" "add" (func (param i32 i32) (result i32)))
   550  		abiConfig := AbiForBodylessFuncStackMap(f)
   551  		abiInfo := abiConfig.ABIAnalyzeFuncType(f.Type())
   552  		wi.Params = paramsToWasmFields(f, "go:wasmimport", abiInfo, abiInfo.InParams())
   553  		wi.Results = resultsToWasmFields(f, "go:wasmimport", abiInfo, abiInfo.OutParams())
   554  	}
   555  	f.LSym.Func().WasmImport = &wi
   556  }
   557  
   558  // setupWasmExport calculates the params and results in terms of WebAssembly values for the given function,
   559  // and sets up the wasmexport metadata.
   560  func setupWasmExport(f, wrapped *ir.Func) {
   561  	we := obj.WasmExport{
   562  		WrappedSym: wrapped.LSym,
   563  	}
   564  	abiConfig := AbiForBodylessFuncStackMap(wrapped)
   565  	abiInfo := abiConfig.ABIAnalyzeFuncType(wrapped.Type())
   566  	we.Params = paramsToWasmFields(wrapped, "go:wasmexport", abiInfo, abiInfo.InParams())
   567  	we.Results = resultsToWasmFields(wrapped, "go:wasmexport", abiInfo, abiInfo.OutParams())
   568  	f.LSym.Func().WasmExport = &we
   569  }
   570  

View as plain text