@@ -93,11 +93,12 @@ type oReader struct {
93
93
version int // version of static symbol
94
94
flags uint32 // read from object file
95
95
pkgprefix string
96
- syms []Sym // Sym's global index, indexed by local index
97
- ndef int // cache goobj.Reader.NSym()
98
- nhashed64def int // cache goobj.Reader.NHashed64Def()
99
- nhasheddef int // cache goobj.Reader.NHashedDef()
100
- objidx uint32 // index of this reader in the objs slice
96
+ syms []Sym // Sym's global index, indexed by local index
97
+ pkg []uint32 // indices of referenced package by PkgIdx (index into loader.objs array)
98
+ ndef int // cache goobj.Reader.NSym()
99
+ nhashed64def int // cache goobj.Reader.NHashed64Def()
100
+ nhasheddef int // cache goobj.Reader.NHashedDef()
101
+ objidx uint32 // index of this reader in the objs slice
101
102
}
102
103
103
104
// Total number of defined symbols (package symbols, hashed symbols, and
@@ -219,7 +220,7 @@ type Loader struct {
219
220
220
221
deferReturnTramp map [Sym ]bool // whether the symbol is a trampoline of a deferreturn call
221
222
222
- objByPkg map [string ]* oReader // map package path to its Go object reader
223
+ objByPkg map [string ]uint32 // map package path to the index of its Go object reader
223
224
224
225
anonVersion int // most recently assigned ext static sym pseudo-version
225
226
@@ -331,7 +332,7 @@ func NewLoader(flags uint32, elfsetstring elfsetstringFunc, reporter *ErrorRepor
331
332
objSyms : make ([]objSym , 1 , 100000 ), // reserve index 0 for nil symbol
332
333
extReader : extReader ,
333
334
symsByName : [2 ]map [string ]Sym {make (map [string ]Sym , 80000 ), make (map [string ]Sym , 50000 )}, // preallocate ~2MB for ABI0 and ~1MB for ABI1 symbols
334
- objByPkg : make (map [string ]* oReader ),
335
+ objByPkg : make (map [string ]uint32 ),
335
336
outer : make (map [Sym ]Sym ),
336
337
sub : make (map [Sym ]Sym ),
337
338
dynimplib : make (map [Sym ]string ),
@@ -370,7 +371,7 @@ func (l *Loader) addObj(pkg string, r *oReader) Sym {
370
371
}
371
372
pkg = objabi .PathToPrefix (pkg ) // the object file contains escaped package path
372
373
if _ , ok := l .objByPkg [pkg ]; ! ok {
373
- l .objByPkg [pkg ] = r
374
+ l .objByPkg [pkg ] = r . objidx
374
375
}
375
376
i := Sym (len (l .objSyms ))
376
377
l .start [r ] = i
@@ -635,12 +636,7 @@ func (l *Loader) resolve(r *oReader, s goobj.SymRef) Sym {
635
636
case goobj .PkgIdxSelf :
636
637
rr = r
637
638
default :
638
- pkg := r .Pkg (int (p ))
639
- var ok bool
640
- rr , ok = l .objByPkg [pkg ]
641
- if ! ok {
642
- log .Fatalf ("reference of nonexisted package %s, from %v" , pkg , r .unit .Lib )
643
- }
639
+ rr = l.objs [r.pkg [p ]].r
644
640
}
645
641
return l .toGlobal (rr , s .SymIdx )
646
642
}
@@ -2195,6 +2191,18 @@ func loadObjRefs(l *Loader, r *oReader, arch *sys.Arch) {
2195
2191
}
2196
2192
}
2197
2193
2194
+ // referenced packages
2195
+ npkg := r .NPkg ()
2196
+ r .pkg = make ([]uint32 , npkg )
2197
+ for i := 1 ; i < npkg ; i ++ { // PkgIdx 0 is a dummy invalid package
2198
+ pkg := r .Pkg (i )
2199
+ objidx , ok := l .objByPkg [pkg ]
2200
+ if ! ok {
2201
+ log .Fatalf ("reference of nonexisted package %s, from %v" , pkg , r .unit .Lib )
2202
+ }
2203
+ r .pkg [i ] = objidx
2204
+ }
2205
+
2198
2206
// load flags of package refs
2199
2207
for i , n := 0 , r .NRefFlags (); i < n ; i ++ {
2200
2208
rf := r .RefFlags (i )
0 commit comments