Commit 049eee68 authored by Russ Cox's avatar Russ Cox

cmd/internal/obj: use map for symbol table

Change-Id: I105c1e7730c1e7ccf36297b9cbf96dc0a4868013
Reviewed-on: https://go-review.googlesource.com/7621Reviewed-by: default avatarRob Pike <r@golang.org>
parent 8e2a57e6
...@@ -115,7 +115,6 @@ type LSym struct { ...@@ -115,7 +115,6 @@ type LSym struct {
Locals int32 Locals int32
Value int64 Value int64
Size int64 Size int64
Hash *LSym
Allsym *LSym Allsym *LSym
Next *LSym Next *LSym
Sub *LSym Sub *LSym
...@@ -181,7 +180,7 @@ type Link struct { ...@@ -181,7 +180,7 @@ type Link struct {
Goroot string Goroot string
Goroot_final string Goroot_final string
Enforce_data_order int32 Enforce_data_order int32
Hash [LINKHASH]*LSym Hash map[SymVer]*LSym
Allsym *LSym Allsym *LSym
Nsymbol int32 Nsymbol int32
Hist *Hist Hist *Hist
...@@ -226,6 +225,11 @@ type Link struct { ...@@ -226,6 +225,11 @@ type Link struct {
Filesyms *LSym Filesyms *LSym
} }
type SymVer struct {
Name string
Version int
}
type Plist struct { type Plist struct {
Name *LSym Name *LSym
Firstpc *Prog Firstpc *Prog
...@@ -539,10 +543,6 @@ const ( ...@@ -539,10 +543,6 @@ const (
A_PARAM A_PARAM
) )
const (
LINKHASH = 100003
)
// Pcdata iterator. // Pcdata iterator.
// for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) } // for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
......
...@@ -126,6 +126,7 @@ func Linknew(arch *LinkArch) *Link { ...@@ -126,6 +126,7 @@ func Linknew(arch *LinkArch) *Link {
linksetexp() linksetexp()
ctxt := new(Link) ctxt := new(Link)
ctxt.Hash = make(map[SymVer]*LSym)
ctxt.Arch = arch ctxt.Arch = arch
ctxt.Version = HistVersion ctxt.Version = HistVersion
ctxt.Goroot = Getgoroot() ctxt.Goroot = Getgoroot()
...@@ -241,26 +242,14 @@ func linknewsym(ctxt *Link, symb string, v int) *LSym { ...@@ -241,26 +242,14 @@ func linknewsym(ctxt *Link, symb string, v int) *LSym {
} }
func _lookup(ctxt *Link, symb string, v int, creat int) *LSym { func _lookup(ctxt *Link, symb string, v int, creat int) *LSym {
h := uint32(v) s := ctxt.Hash[SymVer{symb, v}]
for i := 0; i < len(symb); i++ { if s != nil || creat == 0 {
c := int(symb[i]) return s
h = h + h + h + uint32(c)
}
h &= 0xffffff
h %= LINKHASH
for s := ctxt.Hash[h]; s != nil; s = s.Hash {
if int(s.Version) == v && s.Name == symb {
return s
}
}
if creat == 0 {
return nil
} }
s := linknewsym(ctxt, symb, v) s = linknewsym(ctxt, symb, v)
s.Extname = s.Name s.Extname = s.Name
s.Hash = ctxt.Hash[h] ctxt.Hash[SymVer{symb, v}] = s
ctxt.Hash[h] = s
return s return s
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment