]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: fix some bugs in loader
authorThan McIntosh <thanm@google.com>
Wed, 18 Dec 2019 15:57:15 +0000 (10:57 -0500)
committerThan McIntosh <thanm@google.com>
Fri, 20 Dec 2019 21:05:06 +0000 (21:05 +0000)
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)\ 1

- 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>
src/cmd/link/internal/loader/loader.go

index d4f2ccba56733462ceea332ce1122974c804371f..f774c0c8dda4e22a394dd43774f28e3ea800fd4a 100644 (file)
@@ -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