[dev.link] cmd/link: remove AddExtSym

They used to be different at some point, but now AddExtSym and
LookupOrCreateSym are identical. Remove one.

Change-Id: I299444d987e32a7f43915b3c1bbcc5ae906e9b6a
Reviewed-on: https://go-review.googlesource.com/c/go/+/223977
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-03-16 15:04:00 -04:00
parent 61a0b0d624
commit 626c89bfa3
3 changed files with 26 additions and 43 deletions

View file

@ -186,7 +186,7 @@ var gdbscript string
var dwarfp2 []loader.Sym var dwarfp2 []loader.Sym
func (d *dwctxt2) writeabbrev() loader.Sym { func (d *dwctxt2) writeabbrev() loader.Sym {
abrvs := d.ldr.AddExtSym(".debug_abbrev", 0) abrvs := d.ldr.LookupOrCreateSym(".debug_abbrev", 0)
u := d.ldr.MakeSymbolUpdater(abrvs) u := d.ldr.MakeSymbolUpdater(abrvs)
u.SetType(sym.SDWARFSECT) u.SetType(sym.SDWARFSECT)
u.AddBytes(dwarf.GetAbbrev()) u.AddBytes(dwarf.GetAbbrev())
@ -1372,7 +1372,7 @@ func appendPCDeltaCFA(arch *sys.Arch, b []byte, deltapc, cfa int64) []byte {
} }
func (d *dwctxt2) writeframes(syms []loader.Sym) []loader.Sym { func (d *dwctxt2) writeframes(syms []loader.Sym) []loader.Sym {
fs := d.ldr.AddExtSym(".debug_frame", 0) fs := d.ldr.LookupOrCreateSym(".debug_frame", 0)
fsd := dwSym(fs) fsd := dwSym(fs)
fsu := d.ldr.MakeSymbolUpdater(fs) fsu := d.ldr.MakeSymbolUpdater(fs)
fsu.SetType(sym.SDWARFSECT) fsu.SetType(sym.SDWARFSECT)
@ -1540,7 +1540,7 @@ func appendSyms(syms []loader.Sym, src []sym.LoaderSym) []loader.Sym {
func (d *dwctxt2) writeinfo(syms []loader.Sym, units []*sym.CompilationUnit, abbrevsym loader.Sym, pubNames, pubTypes *pubWriter2) []loader.Sym { func (d *dwctxt2) writeinfo(syms []loader.Sym, units []*sym.CompilationUnit, abbrevsym loader.Sym, pubNames, pubTypes *pubWriter2) []loader.Sym {
infosec := d.ldr.AddExtSym(".debug_info", 0) infosec := d.ldr.LookupOrCreateSym(".debug_info", 0)
disu := d.ldr.MakeSymbolUpdater(infosec) disu := d.ldr.MakeSymbolUpdater(infosec)
disu.SetType(sym.SDWARFINFO) disu.SetType(sym.SDWARFINFO)
d.ldr.SetAttrReachable(infosec, true) d.ldr.SetAttrReachable(infosec, true)
@ -1641,7 +1641,7 @@ type pubWriter2 struct {
} }
func newPubWriter2(d *dwctxt2, sname string) *pubWriter2 { func newPubWriter2(d *dwctxt2, sname string) *pubWriter2 {
s := d.ldr.AddExtSym(sname, 0) s := d.ldr.LookupOrCreateSym(sname, 0)
u := d.ldr.MakeSymbolUpdater(s) u := d.ldr.MakeSymbolUpdater(s)
u.SetType(sym.SDWARFSECT) u.SetType(sym.SDWARFSECT)
return &pubWriter2{d: d, s: s, su: u, sname: sname} return &pubWriter2{d: d, s: s, su: u, sname: sname}
@ -1714,7 +1714,7 @@ func (d *dwctxt2) writegdbscript(syms []loader.Sym) []loader.Sym {
} }
if gdbscript != "" { if gdbscript != "" {
gs := d.ldr.AddExtSym(".debug_gdb_scripts", 0) gs := d.ldr.LookupOrCreateSym(".debug_gdb_scripts", 0)
u := d.ldr.MakeSymbolUpdater(gs) u := d.ldr.MakeSymbolUpdater(gs)
u.SetType(sym.SDWARFSECT) u.SetType(sym.SDWARFSECT)
@ -2065,13 +2065,13 @@ func (d *dwctxt2) dwarfGenerateDebugSyms() {
sort.Sort(compilationUnitByStartPC(d.linkctxt.compUnits)) sort.Sort(compilationUnitByStartPC(d.linkctxt.compUnits))
// Create .debug_line and .debug_ranges section symbols // Create .debug_line and .debug_ranges section symbols
debugLine := d.ldr.AddExtSym(".debug_line", 0) debugLine := d.ldr.LookupOrCreateSym(".debug_line", 0)
dlu := d.ldr.MakeSymbolUpdater(debugLine) dlu := d.ldr.MakeSymbolUpdater(debugLine)
dlu.SetType(sym.SDWARFSECT) dlu.SetType(sym.SDWARFSECT)
d.ldr.SetAttrReachable(debugLine, true) d.ldr.SetAttrReachable(debugLine, true)
syms = append(syms, debugLine) syms = append(syms, debugLine)
debugRanges := d.ldr.AddExtSym(".debug_ranges", 0) debugRanges := d.ldr.LookupOrCreateSym(".debug_ranges", 0)
dru := d.ldr.MakeSymbolUpdater(debugRanges) dru := d.ldr.MakeSymbolUpdater(debugRanges)
dru.SetType(sym.SDWARFRANGE) dru.SetType(sym.SDWARFRANGE)
d.ldr.SetAttrReachable(debugRanges, true) d.ldr.SetAttrReachable(debugRanges, true)
@ -2141,7 +2141,7 @@ func (d *dwctxt2) collectlocs(syms []loader.Sym, units []*sym.CompilationUnit) [
// Don't emit .debug_loc if it's empty -- it makes the ARM linker mad. // Don't emit .debug_loc if it's empty -- it makes the ARM linker mad.
if !empty { if !empty {
locsym := d.ldr.AddExtSym(".debug_loc", 0) locsym := d.ldr.LookupOrCreateSym(".debug_loc", 0)
u := d.ldr.MakeSymbolUpdater(locsym) u := d.ldr.MakeSymbolUpdater(locsym)
u.SetType(sym.SDWARFLOC) u.SetType(sym.SDWARFLOC)
d.ldr.SetAttrReachable(locsym, true) d.ldr.SetAttrReachable(locsym, true)

View file

@ -333,7 +333,7 @@ func (l *Loader) addObj(pkg string, r *oReader) Sym {
// If the symbol already exist, it returns the index of that symbol. // If the symbol already exist, it returns the index of that symbol.
func (l *Loader) AddSym(name string, ver int, r *oReader, li int, kind int, dupok bool, typ sym.SymKind) (Sym, bool) { func (l *Loader) AddSym(name string, ver int, r *oReader, li int, kind int, dupok bool, typ sym.SymKind) (Sym, bool) {
if l.extStart != 0 { if l.extStart != 0 {
panic("AddSym called after AddExtSym is called") panic("AddSym called after external symbol is created")
} }
i := Sym(len(l.objSyms)) i := Sym(len(l.objSyms))
addToGlobal := func() { addToGlobal := func() {
@ -412,23 +412,6 @@ func (l *Loader) newExtSym(name string, ver int) Sym {
return i return i
} }
// Add an external symbol (without index). Return the index of newly added
// symbol, or 0 if not added.
func (l *Loader) AddExtSym(name string, ver int) Sym {
i := l.Lookup(name, ver)
if i != 0 {
return i
}
i = l.newExtSym(name, ver)
static := ver >= sym.SymVerStatic || ver < 0
if static {
l.extStaticSyms[nameVer{name, ver}] = i
} else {
l.symsByName[ver][name] = i
}
return i
}
// LookupOrCreateSym looks up the symbol with the specified name/version, // LookupOrCreateSym looks up the symbol with the specified name/version,
// returning its Sym index if found. If the lookup fails, a new external // returning its Sym index if found. If the lookup fails, a new external
// Sym will be created, entered into the lookup tables, and returned. // Sym will be created, entered into the lookup tables, and returned.
@ -1726,7 +1709,7 @@ func loadObjRefs(l *Loader, r *oReader, syms *sym.Symbols) {
osym.Read(r.Reader, r.SymOff(ndef+i)) osym.Read(r.Reader, r.SymOff(ndef+i))
name := strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1) name := strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1)
v := abiToVer(osym.ABI, r.version) v := abiToVer(osym.ABI, r.version)
r.syms[ndef+i] = l.AddExtSym(name, v) r.syms[ndef+i] = l.LookupOrCreateSym(name, v)
} }
} }

View file

@ -39,17 +39,17 @@ func TestAddMaterializedSymbol(t *testing.T) {
ts3 := addDummyObjSym(t, ldr, or, "type.string") ts3 := addDummyObjSym(t, ldr, or, "type.string")
// Create some external symbols. // Create some external symbols.
es1 := ldr.AddExtSym("extnew1", 0) es1 := ldr.LookupOrCreateSym("extnew1", 0)
if es1 == 0 { if es1 == 0 {
t.Fatalf("AddExtSym failed for extnew1") t.Fatalf("LookupOrCreateSym failed for extnew1")
} }
es1x := ldr.AddExtSym("extnew1", 0) es1x := ldr.LookupOrCreateSym("extnew1", 0)
if es1x != es1 { if es1x != es1 {
t.Fatalf("AddExtSym lookup: expected %d got %d for second lookup", es1, es1x) t.Fatalf("LookupOrCreateSym lookup: expected %d got %d for second lookup", es1, es1x)
} }
es2 := ldr.AddExtSym("go.info.type.uint8", 0) es2 := ldr.LookupOrCreateSym("go.info.type.uint8", 0)
if es2 == 0 { if es2 == 0 {
t.Fatalf("AddExtSym failed for go.info.type.uint8") t.Fatalf("LookupOrCreateSym failed for go.info.type.uint8")
} }
// Create a nameless symbol // Create a nameless symbol
es3 := ldr.CreateExtSym("") es3 := ldr.CreateExtSym("")
@ -99,7 +99,7 @@ func TestAddMaterializedSymbol(t *testing.T) {
// Test expansion of attr bitmaps // Test expansion of attr bitmaps
for idx := 0; idx < 36; idx++ { for idx := 0; idx < 36; idx++ {
es := ldr.AddExtSym(fmt.Sprintf("zext%d", idx), 0) es := ldr.LookupOrCreateSym(fmt.Sprintf("zext%d", idx), 0)
if ldr.AttrOnList(es) { if ldr.AttrOnList(es) {
t.Errorf("expected OnList after creation") t.Errorf("expected OnList after creation")
} }
@ -235,7 +235,7 @@ func TestAddDataMethods(t *testing.T) {
// Populate loader with some symbols. // Populate loader with some symbols.
addDummyObjSym(t, ldr, or, "type.uint8") addDummyObjSym(t, ldr, or, "type.uint8")
ldr.AddExtSym("hello", 0) ldr.LookupOrCreateSym("hello", 0)
arch := sys.ArchAMD64 arch := sys.ArchAMD64
var testpoints = []struct { var testpoints = []struct {
@ -325,9 +325,9 @@ func TestAddDataMethods(t *testing.T) {
var pmi Sym var pmi Sym
for k, tp := range testpoints { for k, tp := range testpoints {
name := fmt.Sprintf("new%d", k+1) name := fmt.Sprintf("new%d", k+1)
mi := ldr.AddExtSym(name, 0) mi := ldr.LookupOrCreateSym(name, 0)
if mi == 0 { if mi == 0 {
t.Fatalf("AddExtSym failed for '" + name + "'") t.Fatalf("LookupOrCreateSym failed for '" + name + "'")
} }
mi = tp.addDataFunc(ldr, mi, pmi) mi = tp.addDataFunc(ldr, mi, pmi)
if ldr.SymType(mi) != tp.expKind { if ldr.SymType(mi) != tp.expKind {
@ -359,12 +359,12 @@ func TestOuterSub(t *testing.T) {
// Populate loader with some symbols. // Populate loader with some symbols.
addDummyObjSym(t, ldr, or, "type.uint8") addDummyObjSym(t, ldr, or, "type.uint8")
es1 := ldr.AddExtSym("outer", 0) es1 := ldr.LookupOrCreateSym("outer", 0)
es2 := ldr.AddExtSym("sub1", 0) es2 := ldr.LookupOrCreateSym("sub1", 0)
es3 := ldr.AddExtSym("sub2", 0) es3 := ldr.LookupOrCreateSym("sub2", 0)
es4 := ldr.AddExtSym("sub3", 0) es4 := ldr.LookupOrCreateSym("sub3", 0)
es5 := ldr.AddExtSym("sub4", 0) es5 := ldr.LookupOrCreateSym("sub4", 0)
es6 := ldr.AddExtSym("sub5", 0) es6 := ldr.LookupOrCreateSym("sub5", 0)
// Should not have an outer sym initially // Should not have an outer sym initially
if ldr.OuterSym(es1) != 0 { if ldr.OuterSym(es1) != 0 {