mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: remove the second result of MakeSymbolUpdater
With unique global indices, MakeSymbolUpdater will not change the symbol's index. So no need to return a new index. Change-Id: I5b4fd6a0167cc74476880bbf4382c524ecde7721 Reviewed-on: https://go-review.googlesource.com/c/go/+/219227 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jeremy Faller <jeremy@golang.org> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
5a8b1509dd
commit
112a7cb82c
8 changed files with 70 additions and 72 deletions
|
|
@ -202,7 +202,7 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
||||||
l.SetSymExtname(s, remote)
|
l.SetSymExtname(s, remote)
|
||||||
l.SetSymDynimpvers(s, q)
|
l.SetSymDynimpvers(s, q)
|
||||||
if st != sym.SHOSTOBJ {
|
if st != sym.SHOSTOBJ {
|
||||||
su, _ := l.MakeSymbolUpdater(s)
|
su := l.MakeSymbolUpdater(s)
|
||||||
su.SetType(sym.SDYNIMPORT)
|
su.SetType(sym.SDYNIMPORT)
|
||||||
} else {
|
} else {
|
||||||
hostObjSyms[s] = struct{}{}
|
hostObjSyms[s] = struct{}{}
|
||||||
|
|
@ -218,7 +218,8 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
||||||
}
|
}
|
||||||
local := f[1]
|
local := f[1]
|
||||||
|
|
||||||
su, s := l.MakeSymbolUpdater(lookup(local, 0))
|
s := lookup(local, 0)
|
||||||
|
su := l.MakeSymbolUpdater(s)
|
||||||
su.SetType(sym.SHOSTOBJ)
|
su.SetType(sym.SHOSTOBJ)
|
||||||
su.SetSize(0)
|
su.SetSize(0)
|
||||||
hostObjSyms[s] = struct{}{}
|
hostObjSyms[s] = struct{}{}
|
||||||
|
|
@ -260,7 +261,7 @@ func setCgoAttr(ctxt *Link, lookup func(string, int) loader.Sym, file string, pk
|
||||||
l.SetSymDynimpvers(s, "")
|
l.SetSymDynimpvers(s, "")
|
||||||
l.SetSymExtname(s, "")
|
l.SetSymExtname(s, "")
|
||||||
var su *loader.SymbolBuilder
|
var su *loader.SymbolBuilder
|
||||||
su, s = l.MakeSymbolUpdater(s)
|
su = l.MakeSymbolUpdater(s)
|
||||||
su.SetType(0)
|
su.SetType(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -567,7 +567,7 @@ func (ctxt *Link) loadcgodirectives() {
|
||||||
// cgo_import_static and cgo_import_dynamic,
|
// cgo_import_static and cgo_import_dynamic,
|
||||||
// then we want to make it cgo_import_dynamic
|
// then we want to make it cgo_import_dynamic
|
||||||
// now.
|
// now.
|
||||||
su, _ := l.MakeSymbolUpdater(symIdx)
|
su := l.MakeSymbolUpdater(symIdx)
|
||||||
if l.SymExtname(symIdx) != "" && l.SymDynimplib(symIdx) != "" && !(l.AttrCgoExportStatic(symIdx) || l.AttrCgoExportDynamic(symIdx)) {
|
if l.SymExtname(symIdx) != "" && l.SymDynimplib(symIdx) != "" && !(l.AttrCgoExportStatic(symIdx) || l.AttrCgoExportDynamic(symIdx)) {
|
||||||
su.SetType(sym.SDYNIMPORT)
|
su.SetType(sym.SDYNIMPORT)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -584,12 +584,12 @@ func (ctxt *Link) linksetup() {
|
||||||
switch ctxt.BuildMode {
|
switch ctxt.BuildMode {
|
||||||
case BuildModeCShared, BuildModePlugin:
|
case BuildModeCShared, BuildModePlugin:
|
||||||
symIdx := ctxt.loader.LookupOrCreateSym("runtime.islibrary", 0)
|
symIdx := ctxt.loader.LookupOrCreateSym("runtime.islibrary", 0)
|
||||||
sb, _ := ctxt.loader.MakeSymbolUpdater(symIdx)
|
sb := ctxt.loader.MakeSymbolUpdater(symIdx)
|
||||||
sb.SetType(sym.SNOPTRDATA)
|
sb.SetType(sym.SNOPTRDATA)
|
||||||
sb.AddUint8(1)
|
sb.AddUint8(1)
|
||||||
case BuildModeCArchive:
|
case BuildModeCArchive:
|
||||||
symIdx := ctxt.loader.LookupOrCreateSym("runtime.isarchive", 0)
|
symIdx := ctxt.loader.LookupOrCreateSym("runtime.isarchive", 0)
|
||||||
sb, _ := ctxt.loader.MakeSymbolUpdater(symIdx)
|
sb := ctxt.loader.MakeSymbolUpdater(symIdx)
|
||||||
sb.SetType(sym.SNOPTRDATA)
|
sb.SetType(sym.SNOPTRDATA)
|
||||||
sb.AddUint8(1)
|
sb.AddUint8(1)
|
||||||
}
|
}
|
||||||
|
|
@ -621,7 +621,7 @@ func (ctxt *Link) linksetup() {
|
||||||
|
|
||||||
if ctxt.LinkMode == LinkExternal && ctxt.Arch.Family == sys.PPC64 && objabi.GOOS != "aix" {
|
if ctxt.LinkMode == LinkExternal && ctxt.Arch.Family == sys.PPC64 && objabi.GOOS != "aix" {
|
||||||
toc := ctxt.loader.LookupOrCreateSym(".TOC.", 0)
|
toc := ctxt.loader.LookupOrCreateSym(".TOC.", 0)
|
||||||
sb, _ := ctxt.loader.MakeSymbolUpdater(toc)
|
sb := ctxt.loader.MakeSymbolUpdater(toc)
|
||||||
sb.SetType(sym.SDYNIMPORT)
|
sb.SetType(sym.SDYNIMPORT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -629,8 +629,8 @@ func (ctxt *Link) linksetup() {
|
||||||
// section. We don't actually use the section on android, so don't
|
// section. We don't actually use the section on android, so don't
|
||||||
// generate it.
|
// generate it.
|
||||||
if objabi.GOOS != "android" {
|
if objabi.GOOS != "android" {
|
||||||
symIdx := ctxt.loader.LookupOrCreateSym("runtime.tlsg", 0)
|
tlsg := ctxt.loader.LookupOrCreateSym("runtime.tlsg", 0)
|
||||||
sb, tlsg := ctxt.loader.MakeSymbolUpdater(symIdx)
|
sb := ctxt.loader.MakeSymbolUpdater(tlsg)
|
||||||
|
|
||||||
// runtime.tlsg is used for external linking on platforms that do not define
|
// runtime.tlsg is used for external linking on platforms that do not define
|
||||||
// a variable to hold g in assembly (currently only intel).
|
// a variable to hold g in assembly (currently only intel).
|
||||||
|
|
@ -647,12 +647,12 @@ func (ctxt *Link) linksetup() {
|
||||||
var moduledata loader.Sym
|
var moduledata loader.Sym
|
||||||
var mdsb *loader.SymbolBuilder
|
var mdsb *loader.SymbolBuilder
|
||||||
if ctxt.BuildMode == BuildModePlugin {
|
if ctxt.BuildMode == BuildModePlugin {
|
||||||
pmd := ctxt.loader.LookupOrCreateSym("local.pluginmoduledata", 0)
|
moduledata = ctxt.loader.LookupOrCreateSym("local.pluginmoduledata", 0)
|
||||||
mdsb, moduledata = ctxt.loader.MakeSymbolUpdater(pmd)
|
mdsb = ctxt.loader.MakeSymbolUpdater(moduledata)
|
||||||
ctxt.loader.SetAttrLocal(moduledata, true)
|
ctxt.loader.SetAttrLocal(moduledata, true)
|
||||||
} else {
|
} else {
|
||||||
fmd := ctxt.loader.LookupOrCreateSym("runtime.firstmoduledata", 0)
|
moduledata = ctxt.loader.LookupOrCreateSym("runtime.firstmoduledata", 0)
|
||||||
mdsb, moduledata = ctxt.loader.MakeSymbolUpdater(fmd)
|
mdsb = ctxt.loader.MakeSymbolUpdater(moduledata)
|
||||||
}
|
}
|
||||||
if mdsb.Type() != 0 && mdsb.Type() != sym.SDYNIMPORT {
|
if mdsb.Type() != 0 && mdsb.Type() != sym.SDYNIMPORT {
|
||||||
// If the module (toolchain-speak for "executable or shared
|
// If the module (toolchain-speak for "executable or shared
|
||||||
|
|
@ -666,7 +666,7 @@ func (ctxt *Link) linksetup() {
|
||||||
// recording the value of GOARM.
|
// recording the value of GOARM.
|
||||||
if ctxt.Arch.Family == sys.ARM {
|
if ctxt.Arch.Family == sys.ARM {
|
||||||
goarm := ctxt.loader.LookupOrCreateSym("runtime.goarm", 0)
|
goarm := ctxt.loader.LookupOrCreateSym("runtime.goarm", 0)
|
||||||
sb, _ := ctxt.loader.MakeSymbolUpdater(goarm)
|
sb := ctxt.loader.MakeSymbolUpdater(goarm)
|
||||||
sb.SetType(sym.SDATA)
|
sb.SetType(sym.SDATA)
|
||||||
sb.SetSize(0)
|
sb.SetSize(0)
|
||||||
sb.AddUint8(uint8(objabi.GOARM))
|
sb.AddUint8(uint8(objabi.GOARM))
|
||||||
|
|
@ -674,7 +674,7 @@ func (ctxt *Link) linksetup() {
|
||||||
|
|
||||||
if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) {
|
if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) {
|
||||||
fpe := ctxt.loader.LookupOrCreateSym("runtime.framepointer_enabled", 0)
|
fpe := ctxt.loader.LookupOrCreateSym("runtime.framepointer_enabled", 0)
|
||||||
sb, _ := ctxt.loader.MakeSymbolUpdater(fpe)
|
sb := ctxt.loader.MakeSymbolUpdater(fpe)
|
||||||
sb.SetType(sym.SNOPTRDATA)
|
sb.SetType(sym.SNOPTRDATA)
|
||||||
sb.SetSize(0)
|
sb.SetSize(0)
|
||||||
sb.AddUint8(1)
|
sb.AddUint8(1)
|
||||||
|
|
@ -682,8 +682,8 @@ func (ctxt *Link) linksetup() {
|
||||||
} else {
|
} else {
|
||||||
// If OTOH the module does not contain the runtime package,
|
// If OTOH the module does not contain the runtime package,
|
||||||
// create a local symbol for the moduledata.
|
// create a local symbol for the moduledata.
|
||||||
lmd := ctxt.loader.LookupOrCreateSym("local.moduledata", 0)
|
moduledata = ctxt.loader.LookupOrCreateSym("local.moduledata", 0)
|
||||||
mdsb, moduledata = ctxt.loader.MakeSymbolUpdater(lmd)
|
mdsb = ctxt.loader.MakeSymbolUpdater(moduledata)
|
||||||
ctxt.loader.SetAttrLocal(moduledata, true)
|
ctxt.loader.SetAttrLocal(moduledata, true)
|
||||||
}
|
}
|
||||||
// In all cases way we mark the moduledata as noptrdata to hide it from
|
// In all cases way we mark the moduledata as noptrdata to hide it from
|
||||||
|
|
@ -704,8 +704,8 @@ func (ctxt *Link) linksetup() {
|
||||||
|
|
||||||
if ctxt.Arch == sys.Arch386 && ctxt.HeadType != objabi.Hwindows {
|
if ctxt.Arch == sys.Arch386 && ctxt.HeadType != objabi.Hwindows {
|
||||||
if (ctxt.BuildMode == BuildModeCArchive && ctxt.IsELF) || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
|
if (ctxt.BuildMode == BuildModeCArchive && ctxt.IsELF) || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
|
||||||
symIdx := ctxt.loader.LookupOrCreateSym("_GLOBAL_OFFSET_TABLE_", 0)
|
got := ctxt.loader.LookupOrCreateSym("_GLOBAL_OFFSET_TABLE_", 0)
|
||||||
sb, got := ctxt.loader.MakeSymbolUpdater(symIdx)
|
sb := ctxt.loader.MakeSymbolUpdater(got)
|
||||||
sb.SetType(sym.SDYNIMPORT)
|
sb.SetType(sym.SDYNIMPORT)
|
||||||
ctxt.loader.SetAttrReachable(got, true)
|
ctxt.loader.SetAttrReachable(got, true)
|
||||||
}
|
}
|
||||||
|
|
@ -1970,16 +1970,16 @@ func ldshlibsyms(ctxt *Link, shlib string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
l := ctxt.loader
|
l := ctxt.loader
|
||||||
symIdx := l.LookupOrCreateSym(elfsym.Name, ver)
|
s := l.LookupOrCreateSym(elfsym.Name, ver)
|
||||||
|
|
||||||
// Because loadlib above loads all .a files before loading
|
// Because loadlib above loads all .a files before loading
|
||||||
// any shared libraries, any non-dynimport symbols we find
|
// any shared libraries, any non-dynimport symbols we find
|
||||||
// that duplicate symbols already loaded should be ignored
|
// that duplicate symbols already loaded should be ignored
|
||||||
// (the symbols from the .a files "win").
|
// (the symbols from the .a files "win").
|
||||||
if l.SymType(symIdx) != 0 && l.SymType(symIdx) != sym.SDYNIMPORT {
|
if l.SymType(s) != 0 && l.SymType(s) != sym.SDYNIMPORT {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
su, s := l.MakeSymbolUpdater(symIdx)
|
su := l.MakeSymbolUpdater(s)
|
||||||
su.SetType(sym.SDYNIMPORT)
|
su.SetType(sym.SDYNIMPORT)
|
||||||
l.SetSymElfType(s, elf.ST_TYPE(elfsym.Info))
|
l.SetSymElfType(s, elf.ST_TYPE(elfsym.Info))
|
||||||
su.SetSize(int64(elfsym.Size))
|
su.SetSize(int64(elfsym.Size))
|
||||||
|
|
@ -2019,7 +2019,7 @@ func ldshlibsyms(ctxt *Link, shlib string) {
|
||||||
if l.SymType(alias) != 0 {
|
if l.SymType(alias) != 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
su, _ := l.MakeSymbolUpdater(alias)
|
su := l.MakeSymbolUpdater(alias)
|
||||||
su.SetType(sym.SABIALIAS)
|
su.SetType(sym.SABIALIAS)
|
||||||
su.AddReloc(loader.Reloc{Sym: s})
|
su.AddReloc(loader.Reloc{Sym: s})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -721,7 +721,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
}
|
}
|
||||||
sectsymNames[name] = true
|
sectsymNames[name] = true
|
||||||
|
|
||||||
sb, _ := l.MakeSymbolUpdater(lookup(name, localSymVersion))
|
sb := l.MakeSymbolUpdater(lookup(name, localSymVersion))
|
||||||
|
|
||||||
switch int(sect.flags) & (ElfSectFlagAlloc | ElfSectFlagWrite | ElfSectFlagExec) {
|
switch int(sect.flags) & (ElfSectFlagAlloc | ElfSectFlagWrite | ElfSectFlagExec) {
|
||||||
default:
|
default:
|
||||||
|
|
@ -768,15 +768,13 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if elfsym.shndx == ElfSymShnCommon || elfsym.type_ == ElfSymTypeCommon {
|
if elfsym.shndx == ElfSymShnCommon || elfsym.type_ == ElfSymTypeCommon {
|
||||||
sb, ns := l.MakeSymbolUpdater(elfsym.sym)
|
sb := l.MakeSymbolUpdater(elfsym.sym)
|
||||||
if uint64(sb.Size()) < elfsym.size {
|
if uint64(sb.Size()) < elfsym.size {
|
||||||
sb.SetSize(int64(elfsym.size))
|
sb.SetSize(int64(elfsym.size))
|
||||||
}
|
}
|
||||||
if sb.Type() == 0 || sb.Type() == sym.SXREF {
|
if sb.Type() == 0 || sb.Type() == sym.SXREF {
|
||||||
sb.SetType(sym.SNOPTRBSS)
|
sb.SetType(sym.SNOPTRBSS)
|
||||||
}
|
}
|
||||||
symbols[i] = ns
|
|
||||||
elfsym.sym = ns
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -822,8 +820,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
l.SymName(s), l.SymName(l.OuterSym(s)), l.SymName(sect.sym))
|
l.SymName(s), l.SymName(l.OuterSym(s)), l.SymName(sect.sym))
|
||||||
}
|
}
|
||||||
|
|
||||||
sectsb, _ := l.MakeSymbolUpdater(sect.sym)
|
sectsb := l.MakeSymbolUpdater(sect.sym)
|
||||||
sb, _ := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
|
|
||||||
sb.SetType(sectsb.Type())
|
sb.SetType(sectsb.Type())
|
||||||
sectsb.PrependSub(s)
|
sectsb.PrependSub(s)
|
||||||
|
|
@ -856,8 +854,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
if s == 0 {
|
if s == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sb, _ := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
s = sb.Sym()
|
|
||||||
if l.SubSym(s) != 0 {
|
if l.SubSym(s) != 0 {
|
||||||
sb.SortSub()
|
sb.SortSub()
|
||||||
}
|
}
|
||||||
|
|
@ -992,7 +989,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
sort.Sort(loader.RelocByOff(r[:n]))
|
sort.Sort(loader.RelocByOff(r[:n]))
|
||||||
// just in case
|
// just in case
|
||||||
|
|
||||||
sb, _ := l.MakeSymbolUpdater(sect.sym)
|
sb := l.MakeSymbolUpdater(sect.sym)
|
||||||
r = r[:n]
|
r = r[:n]
|
||||||
sb.SetRelocs(r)
|
sb.SetRelocs(r)
|
||||||
}
|
}
|
||||||
|
|
@ -1090,7 +1087,7 @@ func readelfsym(newSym, lookup func(string, int) loader.Sym, l *loader.Loader, a
|
||||||
// comment #5 for details.
|
// comment #5 for details.
|
||||||
if s != 0 && elfsym.other == 2 {
|
if s != 0 && elfsym.other == 2 {
|
||||||
if !l.IsExternal(s) {
|
if !l.IsExternal(s) {
|
||||||
_, s = l.MakeSymbolUpdater(s)
|
l.MakeSymbolUpdater(s)
|
||||||
}
|
}
|
||||||
l.SetAttrDuplicateOK(s, true)
|
l.SetAttrDuplicateOK(s, true)
|
||||||
l.SetAttrVisibilityHidden(s, true)
|
l.SetAttrVisibilityHidden(s, true)
|
||||||
|
|
@ -1147,7 +1144,7 @@ func readelfsym(newSym, lookup func(string, int) loader.Sym, l *loader.Loader, a
|
||||||
// TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
|
// TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
|
||||||
// sense and should be removed when someone has thought about it properly.
|
// sense and should be removed when someone has thought about it properly.
|
||||||
if s != 0 && l.SymType(s) == 0 && !l.AttrVisibilityHidden(s) && elfsym.type_ != ElfSymTypeSection {
|
if s != 0 && l.SymType(s) == 0 && !l.AttrVisibilityHidden(s) && elfsym.type_ != ElfSymTypeSection {
|
||||||
sb, _ := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.SetType(sym.SXREF)
|
sb.SetType(sym.SXREF)
|
||||||
}
|
}
|
||||||
elfsym.sym = s
|
elfsym.sym = s
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,9 @@ func TestAddMaterializedSymbol(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab symbol builder pointers
|
// Grab symbol builder pointers
|
||||||
sb1, es1 := ldr.MakeSymbolUpdater(es1)
|
sb1 := ldr.MakeSymbolUpdater(es1)
|
||||||
sb2, es2 := ldr.MakeSymbolUpdater(es2)
|
sb2 := ldr.MakeSymbolUpdater(es2)
|
||||||
sb3, es3 := ldr.MakeSymbolUpdater(es3)
|
sb3 := ldr.MakeSymbolUpdater(es3)
|
||||||
|
|
||||||
// Suppose we create some more symbols, which triggers a grow.
|
// Suppose we create some more symbols, which triggers a grow.
|
||||||
// Make sure the symbol builder's payload pointer is valid,
|
// Make sure the symbol builder's payload pointer is valid,
|
||||||
|
|
@ -116,8 +116,8 @@ func TestAddMaterializedSymbol(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sb1, es1 = ldr.MakeSymbolUpdater(es1)
|
sb1 = ldr.MakeSymbolUpdater(es1)
|
||||||
sb2, es2 = ldr.MakeSymbolUpdater(es2)
|
sb2 = ldr.MakeSymbolUpdater(es2)
|
||||||
|
|
||||||
// Get/set a few other attributes
|
// Get/set a few other attributes
|
||||||
if ldr.AttrVisibilityHidden(es3) {
|
if ldr.AttrVisibilityHidden(es3) {
|
||||||
|
|
@ -248,9 +248,9 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "AddUint8",
|
which: "AddUint8",
|
||||||
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.AddUint8('a')
|
sb.AddUint8('a')
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{'a'},
|
expData: []byte{'a'},
|
||||||
expKind: sym.SDATA,
|
expKind: sym.SDATA,
|
||||||
|
|
@ -258,9 +258,9 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "AddUintXX",
|
which: "AddUintXX",
|
||||||
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.AddUintXX(arch, 25185, 2)
|
sb.AddUintXX(arch, 25185, 2)
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{'a', 'b'},
|
expData: []byte{'a', 'b'},
|
||||||
expKind: sym.SDATA,
|
expKind: sym.SDATA,
|
||||||
|
|
@ -268,11 +268,11 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "SetUint8",
|
which: "SetUint8",
|
||||||
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.AddUint8('a')
|
sb.AddUint8('a')
|
||||||
sb.AddUint8('b')
|
sb.AddUint8('b')
|
||||||
sb.SetUint8(arch, 1, 'c')
|
sb.SetUint8(arch, 1, 'c')
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{'a', 'c'},
|
expData: []byte{'a', 'c'},
|
||||||
expKind: sym.SDATA,
|
expKind: sym.SDATA,
|
||||||
|
|
@ -280,9 +280,9 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "AddString",
|
which: "AddString",
|
||||||
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, _ Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.Addstring("hello")
|
sb.Addstring("hello")
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{'h', 'e', 'l', 'l', 'o', 0},
|
expData: []byte{'h', 'e', 'l', 'l', 'o', 0},
|
||||||
expKind: sym.SNOPTRDATA,
|
expKind: sym.SNOPTRDATA,
|
||||||
|
|
@ -290,9 +290,9 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "AddAddrPlus",
|
which: "AddAddrPlus",
|
||||||
addDataFunc: func(l *Loader, s Sym, s2 Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, s2 Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.AddAddrPlus(arch, s2, 3)
|
sb.AddAddrPlus(arch, s2, 3)
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{0, 0, 0, 0, 0, 0, 0, 0},
|
expData: []byte{0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
expKind: sym.SDATA,
|
expKind: sym.SDATA,
|
||||||
|
|
@ -301,9 +301,9 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "AddAddrPlus4",
|
which: "AddAddrPlus4",
|
||||||
addDataFunc: func(l *Loader, s Sym, s2 Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, s2 Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.AddAddrPlus4(arch, s2, 3)
|
sb.AddAddrPlus4(arch, s2, 3)
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{0, 0, 0, 0},
|
expData: []byte{0, 0, 0, 0},
|
||||||
expKind: sym.SDATA,
|
expKind: sym.SDATA,
|
||||||
|
|
@ -312,9 +312,9 @@ func TestAddDataMethods(t *testing.T) {
|
||||||
{
|
{
|
||||||
which: "AddCURelativeAddrPlus",
|
which: "AddCURelativeAddrPlus",
|
||||||
addDataFunc: func(l *Loader, s Sym, s2 Sym) Sym {
|
addDataFunc: func(l *Loader, s Sym, s2 Sym) Sym {
|
||||||
sb, ns := l.MakeSymbolUpdater(s)
|
sb := l.MakeSymbolUpdater(s)
|
||||||
sb.AddCURelativeAddrPlus(arch, s2, 7)
|
sb.AddCURelativeAddrPlus(arch, s2, 7)
|
||||||
return ns
|
return s
|
||||||
},
|
},
|
||||||
expData: []byte{0, 0, 0, 0, 0, 0, 0, 0},
|
expData: []byte{0, 0, 0, 0, 0, 0, 0, 0},
|
||||||
expKind: sym.SDATA,
|
expKind: sym.SDATA,
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,8 @@ func (l *Loader) MakeSymbolBuilder(name string) *SymbolBuilder {
|
||||||
// symbol 'symIdx'. If 'symIdx' is not an external symbol, then create
|
// symbol 'symIdx'. If 'symIdx' is not an external symbol, then create
|
||||||
// a clone of it (copy name, properties, etc) fix things up so that
|
// a clone of it (copy name, properties, etc) fix things up so that
|
||||||
// the lookup tables and caches point to the new version, not the old
|
// the lookup tables and caches point to the new version, not the old
|
||||||
// version. Returns a SymbolBuilder and a Sym (which may be different
|
// version.
|
||||||
// from the original if we had to clone).
|
func (l *Loader) MakeSymbolUpdater(symIdx Sym) *SymbolBuilder {
|
||||||
func (l *Loader) MakeSymbolUpdater(symIdx Sym) (*SymbolBuilder, Sym) {
|
|
||||||
if symIdx == 0 {
|
if symIdx == 0 {
|
||||||
panic("can't update the null symbol")
|
panic("can't update the null symbol")
|
||||||
}
|
}
|
||||||
|
|
@ -53,7 +52,7 @@ func (l *Loader) MakeSymbolUpdater(symIdx Sym) (*SymbolBuilder, Sym) {
|
||||||
// Construct updater and return.
|
// Construct updater and return.
|
||||||
sb := &SymbolBuilder{l: l, symIdx: symIdx}
|
sb := &SymbolBuilder{l: l, symIdx: symIdx}
|
||||||
sb.extSymPayload = l.getPayload(symIdx)
|
sb.extSymPayload = l.getPayload(symIdx)
|
||||||
return sb, symIdx
|
return sb
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters for properties of the symbol we're working on.
|
// Getters for properties of the symbol we're working on.
|
||||||
|
|
|
||||||
|
|
@ -559,7 +559,8 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
name := fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
||||||
bld, s := l.MakeSymbolUpdater(l.LookupOrCreateSym(name, localSymVersion))
|
s := l.LookupOrCreateSym(name, localSymVersion)
|
||||||
|
bld := l.MakeSymbolUpdater(s)
|
||||||
if bld.Type() != 0 {
|
if bld.Type() != 0 {
|
||||||
return errorf("duplicate %s/%s", sect.segname, sect.name)
|
return errorf("duplicate %s/%s", sect.segname, sect.name)
|
||||||
}
|
}
|
||||||
|
|
@ -624,7 +625,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
}
|
}
|
||||||
|
|
||||||
sect := &c.seg.sect[machsym.sectnum-1]
|
sect := &c.seg.sect[machsym.sectnum-1]
|
||||||
bld, bldSym := l.MakeSymbolUpdater(s)
|
bld := l.MakeSymbolUpdater(s)
|
||||||
outer := sect.sym
|
outer := sect.sym
|
||||||
if outer == 0 {
|
if outer == 0 {
|
||||||
continue // ignore reference to invalid section
|
continue // ignore reference to invalid section
|
||||||
|
|
@ -638,7 +639,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
}
|
}
|
||||||
|
|
||||||
bld.SetType(l.SymType(outer))
|
bld.SetType(l.SymType(outer))
|
||||||
l.PrependSub(outer, bldSym)
|
l.PrependSub(outer, s)
|
||||||
|
|
||||||
bld.SetValue(int64(machsym.value - sect.addr))
|
bld.SetValue(int64(machsym.value - sect.addr))
|
||||||
if !l.AttrCgoExportDynamic(s) {
|
if !l.AttrCgoExportDynamic(s) {
|
||||||
|
|
@ -650,26 +651,24 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
}
|
}
|
||||||
bld.SetExternal(true)
|
bld.SetExternal(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
machsym.sym = bldSym
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort outer lists by address, adding to textp.
|
// Sort outer lists by address, adding to textp.
|
||||||
// This keeps textp in increasing address order.
|
// This keeps textp in increasing address order.
|
||||||
for i := 0; uint32(i) < c.seg.nsect; i++ {
|
for i := 0; uint32(i) < c.seg.nsect; i++ {
|
||||||
sect := &c.seg.sect[i]
|
sect := &c.seg.sect[i]
|
||||||
sectSym := sect.sym
|
s := sect.sym
|
||||||
if sectSym == 0 {
|
if s == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
bld, s := l.MakeSymbolUpdater(sectSym)
|
bld := l.MakeSymbolUpdater(s)
|
||||||
if bld.SubSym() != 0 {
|
if bld.SubSym() != 0 {
|
||||||
|
|
||||||
bld.SortSub()
|
bld.SortSub()
|
||||||
|
|
||||||
// assign sizes, now that we know symbols in sorted order.
|
// assign sizes, now that we know symbols in sorted order.
|
||||||
for s1 := bld.Sub(); s1 != 0; s1 = l.SubSym(s1) {
|
for s1 := bld.Sub(); s1 != 0; s1 = l.SubSym(s1) {
|
||||||
s1Bld, _ := l.MakeSymbolUpdater(s1)
|
s1Bld := l.MakeSymbolUpdater(s1)
|
||||||
if sub := l.SubSym(s1); sub != 0 {
|
if sub := l.SubSym(s1); sub != 0 {
|
||||||
s1Bld.SetSize(l.SymValue(sub) - l.SymValue(s1))
|
s1Bld.SetSize(l.SymValue(sub) - l.SymValue(s1))
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -866,7 +865,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(loader.RelocByOff(r[:rpi]))
|
sort.Sort(loader.RelocByOff(r[:rpi]))
|
||||||
sb, _ := l.MakeSymbolUpdater(sect.sym)
|
sb := l.MakeSymbolUpdater(sect.sym)
|
||||||
sb.SetRelocs(r[:rpi])
|
sb.SetRelocs(r[:rpi])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ func makeUpdater(l *loader.Loader, bld *loader.SymbolBuilder, s loader.Sym) *loa
|
||||||
if bld != nil {
|
if bld != nil {
|
||||||
return bld
|
return bld
|
||||||
}
|
}
|
||||||
bld, _ = l.MakeSymbolUpdater(s)
|
bld = l.MakeSymbolUpdater(s)
|
||||||
return bld
|
return bld
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -160,7 +160,9 @@ func makeUpdater(l *loader.Loader, bld *loader.SymbolBuilder, s loader.Sym) *loa
|
||||||
// If an .rsrc section is found, its symbol is returned as rsrc.
|
// If an .rsrc section is found, its symbol is returned as rsrc.
|
||||||
func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []loader.Sym, rsrc loader.Sym, err error) {
|
func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []loader.Sym, rsrc loader.Sym, err error) {
|
||||||
lookup := func(name string, version int) (*loader.SymbolBuilder, loader.Sym) {
|
lookup := func(name string, version int) (*loader.SymbolBuilder, loader.Sym) {
|
||||||
return l.MakeSymbolUpdater(l.LookupOrCreateSym(name, version))
|
s := l.LookupOrCreateSym(name, version)
|
||||||
|
sb := l.MakeSymbolUpdater(s)
|
||||||
|
return sb, s
|
||||||
}
|
}
|
||||||
sectsyms := make(map[*pe.Section]loader.Sym)
|
sectsyms := make(map[*pe.Section]loader.Sym)
|
||||||
sectdata := make(map[*pe.Section][]byte)
|
sectdata := make(map[*pe.Section][]byte)
|
||||||
|
|
@ -328,7 +330,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
||||||
|
|
||||||
sort.Sort(loader.RelocByOff(rs[:rsect.NumberOfRelocations]))
|
sort.Sort(loader.RelocByOff(rs[:rsect.NumberOfRelocations]))
|
||||||
|
|
||||||
bld, _ := l.MakeSymbolUpdater(sectsyms[rsect])
|
bld := l.MakeSymbolUpdater(sectsyms[rsect])
|
||||||
bld.SetRelocs(rs[:rsect.NumberOfRelocations])
|
bld.SetRelocs(rs[:rsect.NumberOfRelocations])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
||||||
lds.Section = *sect
|
lds.Section = *sect
|
||||||
name := fmt.Sprintf("%s(%s)", pkg, lds.Name)
|
name := fmt.Sprintf("%s(%s)", pkg, lds.Name)
|
||||||
symbol := l.LookupOrCreateSym(name, localSymVersion)
|
symbol := l.LookupOrCreateSym(name, localSymVersion)
|
||||||
s, _ := l.MakeSymbolUpdater(symbol)
|
s := l.MakeSymbolUpdater(symbol)
|
||||||
|
|
||||||
switch lds.Type {
|
switch lds.Type {
|
||||||
default:
|
default:
|
||||||
|
|
@ -148,7 +148,7 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bld, _ := l.MakeSymbolUpdater(sect.sym)
|
bld := l.MakeSymbolUpdater(sect.sym)
|
||||||
bld.SetRelocs(rs[:sect.Nreloc])
|
bld.SetRelocs(rs[:sect.Nreloc])
|
||||||
}
|
}
|
||||||
return textp, nil
|
return textp, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue