Source file src/cmd/compile/internal/base/link.go

     1  // Copyright 2021 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 base
     6  
     7  import (
     8  	"cmd/internal/obj"
     9  )
    10  
    11  var Ctxt *obj.Link
    12  
    13  // TODO(mdempsky): These should probably be obj.Link methods.
    14  
    15  // PkgLinksym returns the linker symbol for name within the given
    16  // package prefix. For user packages, prefix should be the package
    17  // path encoded with objabi.PathToPrefix.
    18  func PkgLinksym(prefix, name string, abi obj.ABI) *obj.LSym {
    19  	if name == "_" {
    20  		// TODO(mdempsky): Cleanup callers and Fatalf instead.
    21  		return linksym(prefix, "_", abi)
    22  	}
    23  	return linksym(prefix, prefix+"."+name, abi)
    24  }
    25  
    26  // Linkname returns the linker symbol for the given name as it might
    27  // appear within a //go:linkname directive.
    28  func Linkname(name string, abi obj.ABI) *obj.LSym {
    29  	return linksym("_", name, abi)
    30  }
    31  
    32  // linksym is an internal helper function for implementing the above
    33  // exported APIs.
    34  func linksym(pkg, name string, abi obj.ABI) *obj.LSym {
    35  	return Ctxt.LookupABIInit(name, abi, func(r *obj.LSym) { r.Pkg = pkg })
    36  }
    37  

View as plain text