mirror of
https://github.com/golang/go
synced 2024-11-23 19:00:04 -07:00
runtime: have typelinksinit work forwards
For reasons I have forgotten typelinksinit processed modules backwards. (I suspect this was an attempt to process types in the executing binary first.) It does not appear to be necessary, and it is not the order we want when a module can be loaded at an arbitrary point during a program's execution as a plugin. So reverse the order. While here, make it safe to call typelinksinit multiple times. Change-Id: Ie10587c55c8e5efa0542981efb6eb3c12dd59e8c Reviewed-on: https://go-review.googlesource.com/27822 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
8f3c8a33fa
commit
bee4206764
@ -446,14 +446,11 @@ func typelinksinit() {
|
|||||||
if firstmoduledata.next == nil {
|
if firstmoduledata.next == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
typehash := make(map[uint32][]*_type)
|
typehash := make(map[uint32][]*_type, len(firstmoduledata.typelinks))
|
||||||
|
|
||||||
modules := []*moduledata{}
|
prev := &firstmoduledata
|
||||||
for md := &firstmoduledata; md != nil; md = md.next {
|
md := firstmoduledata.next
|
||||||
modules = append(modules, md)
|
for md != nil {
|
||||||
}
|
|
||||||
prev, modules := modules[len(modules)-1], modules[:len(modules)-1]
|
|
||||||
for len(modules) > 0 {
|
|
||||||
// Collect types from the previous module into typehash.
|
// Collect types from the previous module into typehash.
|
||||||
collect:
|
collect:
|
||||||
for _, tl := range prev.typelinks {
|
for _, tl := range prev.typelinks {
|
||||||
@ -473,10 +470,10 @@ func typelinksinit() {
|
|||||||
typehash[t.hash] = append(tlist, t)
|
typehash[t.hash] = append(tlist, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if md.typemap == nil {
|
||||||
// If any of this module's typelinks match a type from a
|
// If any of this module's typelinks match a type from a
|
||||||
// prior module, prefer that prior type by adding the offset
|
// prior module, prefer that prior type by adding the offset
|
||||||
// to this module's typemap.
|
// to this module's typemap.
|
||||||
md := modules[len(modules)-1]
|
|
||||||
md.typemap = make(map[typeOff]*_type, len(md.typelinks))
|
md.typemap = make(map[typeOff]*_type, len(md.typelinks))
|
||||||
for _, tl := range md.typelinks {
|
for _, tl := range md.typelinks {
|
||||||
t := (*_type)(unsafe.Pointer(md.types + uintptr(tl)))
|
t := (*_type)(unsafe.Pointer(md.types + uintptr(tl)))
|
||||||
@ -488,8 +485,10 @@ func typelinksinit() {
|
|||||||
}
|
}
|
||||||
md.typemap[typeOff(tl)] = t
|
md.typemap[typeOff(tl)] = t
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prev, modules = md, modules[:len(modules)-1]
|
prev = md
|
||||||
|
md = md.next
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user