[dev.link] cmd/link: fix some bugs in loader

This patch fixes a couple of bugs introduced in CL 210778 and CL 207606:

- apply the same version selection scheme in loader.CreateExtSym that
  we're currently using for loader.Create (since the two functions
  will be used in the same way by the host object loader)

- add code to the loader's NewLoader function to create initial map
  values for some of the map-based symbol attributes (somewhere along
  the line the code to do this seems to have gotten lost, so this
  patch adds it back).

- fix a coding error in growAttrBitmaps (wrong bitmap passed to
  append when extending attrOnList)

Change-Id: Ie0c8c6876428bb21d788c19a7a2db945ac649fac
Reviewed-on: https://go-review.googlesource.com/c/go/+/212097
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Than McIntosh 2019-12-18 10:57:15 -05:00
parent e4a8da499b
commit 9a5468edff

View file

@ -232,18 +232,26 @@ const (
func NewLoader(flags uint32) *Loader { func NewLoader(flags uint32) *Loader {
nbuiltin := goobj2.NBuiltin() nbuiltin := goobj2.NBuiltin()
return &Loader{ return &Loader{
start: make(map[*oReader]Sym), start: make(map[*oReader]Sym),
objs: []objIdx{{nil, 0, 0}}, objs: []objIdx{{nil, 0, 0}},
symsByName: [2]map[string]Sym{make(map[string]Sym), make(map[string]Sym)}, symsByName: [2]map[string]Sym{make(map[string]Sym), make(map[string]Sym)},
objByPkg: make(map[string]*oReader), objByPkg: make(map[string]*oReader),
outer: make(map[Sym]Sym), outer: make(map[Sym]Sym),
sub: make(map[Sym]Sym), sub: make(map[Sym]Sym),
align: make(map[Sym]int32), align: make(map[Sym]int32),
overwrite: make(map[Sym]Sym), dynimplib: make(map[Sym]string),
itablink: make(map[Sym]struct{}), dynimpvers: make(map[Sym]string),
extStaticSyms: make(map[nameVer]Sym), localentry: make(map[Sym]uint8),
builtinSyms: make([]Sym, nbuiltin), extname: make(map[Sym]string),
flags: flags, attrTopFrame: make(map[Sym]struct{}),
attrSpecial: make(map[Sym]struct{}),
attrCgoExportDynamic: make(map[Sym]struct{}),
attrCgoExportStatic: make(map[Sym]struct{}),
overwrite: make(map[Sym]Sym),
itablink: make(map[Sym]struct{}),
extStaticSyms: make(map[nameVer]Sym),
builtinSyms: make([]Sym, nbuiltin),
flags: flags,
} }
} }
@ -1173,7 +1181,7 @@ func (l *Loader) growAttrBitmaps(reqLen int) {
if reqLen > l.attrReachable.len() { if reqLen > l.attrReachable.len() {
// These are indexed by global symbol // These are indexed by global symbol
l.attrReachable = growBitmap(reqLen, l.attrReachable) l.attrReachable = growBitmap(reqLen, l.attrReachable)
l.attrOnList = growBitmap(reqLen, l.attrReachable) l.attrOnList = growBitmap(reqLen, l.attrOnList)
} }
// These are indexed by external symbol offset (e.g. i - l.extStart) // These are indexed by external symbol offset (e.g. i - l.extStart)
if l.extStart == 0 { if l.extStart == 0 {
@ -1665,7 +1673,11 @@ func (l *Loader) LookupOrCreate(name string, version int) *sym.Symbol {
// CreateExtSym creates a new external symbol with the specified name // CreateExtSym creates a new external symbol with the specified name
// without adding it to any lookup tables, returning a Sym index for it. // without adding it to any lookup tables, returning a Sym index for it.
func (l *Loader) CreateExtSym(name string) Sym { func (l *Loader) CreateExtSym(name string) Sym {
return l.newExtSym(name, sym.SymVerABI0) // Assign a new unique negative version -- this is to mark the
// symbol so that it can be skipped when ExtractSymbols is adding
// ext syms to the sym.Symbols hash.
l.anonVersion--
return l.newExtSym(name, l.anonVersion)
} }
// Create creates a symbol with the specified name, returning a // Create creates a symbol with the specified name, returning a