mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Currently there's a lot of logic within package types for creating Linksyms. This CL pulls it out into base, where it can be more easily reused by other compiler code that shouldn't need to depend on package types. Package base probably isn't the best place for this, but it's convenient because it's a package that types already depends on. It's also where the Ctxt object lives, which these functions depend upon. Passes toolstash -cmp w/ -gcflags=all=-abiwrap. Change-Id: I50d8b7e4596955205036969eab24d7dab053b363 Reviewed-on: https://go-review.googlesource.com/c/go/+/284231 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Trust: Matthew Dempsky <mdempsky@google.com>
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
// Copyright 2021 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.
|
|
|
|
package base
|
|
|
|
import (
|
|
"cmd/internal/obj"
|
|
)
|
|
|
|
var Ctxt *obj.Link
|
|
|
|
// TODO(mdempsky): These should probably be obj.Link methods.
|
|
|
|
// PkgLinksym returns the linker symbol for name within the given
|
|
// package prefix. For user packages, prefix should be the package
|
|
// path encoded with objabi.PathToPrefix.
|
|
func PkgLinksym(prefix, name string, abi obj.ABI) *obj.LSym {
|
|
if name == "_" {
|
|
// TODO(mdempsky): Cleanup callers and Fatalf instead.
|
|
return linksym(prefix, "_", abi)
|
|
}
|
|
return linksym(prefix, prefix+"."+name, abi)
|
|
}
|
|
|
|
// Linkname returns the linker symbol for the given name as it might
|
|
// appear within a //go:linkname directive.
|
|
func Linkname(name string, abi obj.ABI) *obj.LSym {
|
|
return linksym("_", name, abi)
|
|
}
|
|
|
|
// linksym is an internal helper function for implementing the above
|
|
// exported APIs.
|
|
func linksym(pkg, name string, abi obj.ABI) *obj.LSym {
|
|
return Ctxt.LookupABIInit(name, abi, func(r *obj.LSym) { r.Pkg = pkg })
|
|
}
|