mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: assign special indices for builtin functions
Compiler-generated function references (e.g. call to runtime.newobject) appear frequently. We assign special indices for them, so they don't need to be referenced by name. Change-Id: I2072594cbc56c9e1037a26e4aae12e68c2436e9f Reviewed-on: https://go-review.googlesource.com/c/go/+/202085 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
df01b7968b
commit
fb06609817
6 changed files with 391 additions and 7 deletions
|
|
@ -91,11 +91,12 @@ func makeBitmap(n int) bitmap {
|
|||
|
||||
// A Loader loads new object files and resolves indexed symbol references.
|
||||
type Loader struct {
|
||||
start map[*oReader]Sym // map from object file to its start index
|
||||
objs []objIdx // sorted by start index (i.e. objIdx.i)
|
||||
max Sym // current max index
|
||||
extStart Sym // from this index on, the symbols are externally defined
|
||||
extSyms []nameVer // externally defined symbols
|
||||
start map[*oReader]Sym // map from object file to its start index
|
||||
objs []objIdx // sorted by start index (i.e. objIdx.i)
|
||||
max Sym // current max index
|
||||
extStart Sym // from this index on, the symbols are externally defined
|
||||
extSyms []nameVer // externally defined symbols
|
||||
builtinSyms []Sym // global index of builtin symbols
|
||||
|
||||
symsByName [2]map[string]Sym // map symbol name to index, two maps are for ABI0 and ABIInternal
|
||||
extStaticSyms map[nameVer]Sym // externally defined static symbols, keyed by name
|
||||
|
|
@ -111,6 +112,7 @@ type Loader struct {
|
|||
}
|
||||
|
||||
func NewLoader() *Loader {
|
||||
nbuiltin := goobj2.NBuiltin()
|
||||
return &Loader{
|
||||
start: make(map[*oReader]Sym),
|
||||
objs: []objIdx{{nil, 0}},
|
||||
|
|
@ -119,6 +121,7 @@ func NewLoader() *Loader {
|
|||
overwrite: make(map[Sym]Sym),
|
||||
itablink: make(map[Sym]struct{}),
|
||||
extStaticSyms: make(map[nameVer]Sym),
|
||||
builtinSyms: make([]Sym, nbuiltin),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,7 +275,7 @@ func (l *Loader) resolve(r *oReader, s goobj2.SymRef) Sym {
|
|||
v := abiToVer(osym.ABI, r.version)
|
||||
return l.Lookup(name, v)
|
||||
case goobj2.PkgIdxBuiltin:
|
||||
panic("PkgIdxBuiltin not used")
|
||||
return l.builtinSyms[s.SymIdx]
|
||||
case goobj2.PkgIdxSelf:
|
||||
rr = r
|
||||
default:
|
||||
|
|
@ -575,6 +578,12 @@ func (l *Loader) Preload(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *
|
|||
if added && strings.HasPrefix(name, "go.itablink.") {
|
||||
l.itablink[istart+Sym(i)] = struct{}{}
|
||||
}
|
||||
if added && strings.HasPrefix(name, "runtime.") {
|
||||
if bi := goobj2.BuiltinIdx(name, v); bi != -1 {
|
||||
// This is a definition of a builtin symbol. Record where it is.
|
||||
l.builtinSyms[bi] = istart + Sym(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The caller expects us consuming all the data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue