From: Than McIntosh Date: Wed, 18 Dec 2019 15:57:15 +0000 (-0500) Subject: [dev.link] cmd/link: fix some bugs in loader X-Git-Tag: go1.15beta1~679^2~165 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9a5468edff1b0f8e3b6be02ed59b238679cf5c2f;p=gostls13.git [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 Reviewed-by: Cherry Zhang --- diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index d4f2ccba56..f774c0c8dd 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -232,18 +232,26 @@ const ( func NewLoader(flags uint32) *Loader { nbuiltin := goobj2.NBuiltin() return &Loader{ - start: make(map[*oReader]Sym), - objs: []objIdx{{nil, 0, 0}}, - symsByName: [2]map[string]Sym{make(map[string]Sym), make(map[string]Sym)}, - objByPkg: make(map[string]*oReader), - outer: make(map[Sym]Sym), - sub: make(map[Sym]Sym), - align: make(map[Sym]int32), - overwrite: make(map[Sym]Sym), - itablink: make(map[Sym]struct{}), - extStaticSyms: make(map[nameVer]Sym), - builtinSyms: make([]Sym, nbuiltin), - flags: flags, + start: make(map[*oReader]Sym), + objs: []objIdx{{nil, 0, 0}}, + symsByName: [2]map[string]Sym{make(map[string]Sym), make(map[string]Sym)}, + objByPkg: make(map[string]*oReader), + outer: make(map[Sym]Sym), + sub: make(map[Sym]Sym), + align: make(map[Sym]int32), + dynimplib: make(map[Sym]string), + dynimpvers: make(map[Sym]string), + localentry: make(map[Sym]uint8), + extname: make(map[Sym]string), + 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() { // These are indexed by global symbol 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) 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 // without adding it to any lookup tables, returning a Sym index for it. 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