mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.link] cmd/link: remove Gotype and File fields from sym.Symbol
Remove the 'Gotype' field from sym.Symbol, as it is now no longer
used. Store the loader.Sym for a symbol as a field in sym.Symbol
("SymIdx"). Then remove sym.Symbol 'File' field, and replace the field
accesses in question with calls into the loader instead.
Change-Id: I01c5504425006b8d3fe77fac2b69a86e198c7a5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/230304
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
0612e78f0f
commit
43a85a39bf
5 changed files with 18 additions and 45 deletions
|
|
@ -2911,6 +2911,13 @@ func (ctxt *Link) loadlibfull(symGroupType []sym.SymKind) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func symPkg(ctxt *Link, s *sym.Symbol) string {
|
||||||
|
if s == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return ctxt.loader.SymPkg(loader.Sym(s.SymIdx))
|
||||||
|
}
|
||||||
|
|
||||||
func (ctxt *Link) dumpsyms() {
|
func (ctxt *Link) dumpsyms() {
|
||||||
for _, s := range ctxt.loader.Syms {
|
for _, s := range ctxt.loader.Syms {
|
||||||
if s == nil {
|
if s == nil {
|
||||||
|
|
|
||||||
|
|
@ -783,19 +783,19 @@ func (f *xcoffFile) writeSymbolFunc(ctxt *Link, x *sym.Symbol) []xcoffSym {
|
||||||
// Trampoline don't have a FILE so there are considered
|
// Trampoline don't have a FILE so there are considered
|
||||||
// in the current file.
|
// in the current file.
|
||||||
// Same goes for runtime.text.X symbols.
|
// Same goes for runtime.text.X symbols.
|
||||||
} else if x.File == "" { // Undefined global symbol
|
} else if symPkg(ctxt, x) == "" { // Undefined global symbol
|
||||||
// If this happens, the algorithm must be redone.
|
// If this happens, the algorithm must be redone.
|
||||||
if currSymSrcFile.name != "" {
|
if currSymSrcFile.name != "" {
|
||||||
Exitf("undefined global symbol found inside another file")
|
Exitf("undefined global symbol found inside another file")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Current file has changed. New C_FILE, C_DWARF, etc must be generated.
|
// Current file has changed. New C_FILE, C_DWARF, etc must be generated.
|
||||||
if currSymSrcFile.name != x.File {
|
if currSymSrcFile.name != symPkg(ctxt, x) {
|
||||||
if ctxt.LinkMode == LinkInternal {
|
if ctxt.LinkMode == LinkInternal {
|
||||||
// update previous file values
|
// update previous file values
|
||||||
xfile.updatePreviousFile(ctxt, false)
|
xfile.updatePreviousFile(ctxt, false)
|
||||||
currSymSrcFile.name = x.File
|
currSymSrcFile.name = symPkg(ctxt, x)
|
||||||
f.writeSymbolNewFile(ctxt, x.File, uint64(x.Value), xfile.getXCOFFscnum(x.Sect))
|
f.writeSymbolNewFile(ctxt, symPkg(ctxt, x), uint64(x.Value), xfile.getXCOFFscnum(x.Sect))
|
||||||
} else {
|
} else {
|
||||||
// With external linking, ld will crash if there is several
|
// With external linking, ld will crash if there is several
|
||||||
// .FILE and DWARF debugging enable, somewhere during
|
// .FILE and DWARF debugging enable, somewhere during
|
||||||
|
|
@ -805,7 +805,7 @@ func (f *xcoffFile) writeSymbolFunc(ctxt *Link, x *sym.Symbol) []xcoffSym {
|
||||||
// TODO(aix); remove once ld has been fixed or the triggering
|
// TODO(aix); remove once ld has been fixed or the triggering
|
||||||
// relocation has been found and fixed.
|
// relocation has been found and fixed.
|
||||||
if currSymSrcFile.name == "" {
|
if currSymSrcFile.name == "" {
|
||||||
currSymSrcFile.name = x.File
|
currSymSrcFile.name = symPkg(ctxt, x)
|
||||||
f.writeSymbolNewFile(ctxt, "go_functions", uint64(x.Value), xfile.getXCOFFscnum(x.Sect))
|
f.writeSymbolNewFile(ctxt, "go_functions", uint64(x.Value), xfile.getXCOFFscnum(x.Sect))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -866,7 +866,7 @@ func putaixsym(ctxt *Link, x *sym.Symbol, str string, t SymbolType, addr int64)
|
||||||
return
|
return
|
||||||
|
|
||||||
case TextSym:
|
case TextSym:
|
||||||
if x.File != "" || strings.Contains(x.Name, "-tramp") || strings.HasPrefix(x.Name, "runtime.text.") {
|
if symPkg(ctxt, x) != "" || strings.Contains(x.Name, "-tramp") || strings.HasPrefix(x.Name, "runtime.text.") {
|
||||||
// Function within a file
|
// Function within a file
|
||||||
syms = xfile.writeSymbolFunc(ctxt, x)
|
syms = xfile.writeSymbolFunc(ctxt, x)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1992,14 +1992,6 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols) {
|
||||||
s.Version = int16(pp.ver)
|
s.Version = int16(pp.ver)
|
||||||
s.Type = pp.kind
|
s.Type = pp.kind
|
||||||
s.Size = pp.size
|
s.Size = pp.size
|
||||||
if pp.gotype != 0 {
|
|
||||||
s.Gotype = l.Syms[pp.gotype]
|
|
||||||
}
|
|
||||||
if f, ok := l.symPkg[i]; ok {
|
|
||||||
s.File = f
|
|
||||||
} else if pp.objidx != 0 {
|
|
||||||
s.File = l.objs[pp.objidx].r.unit.Lib.Pkg
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy relocations
|
// Copy relocations
|
||||||
batch := l.relocBatch
|
batch := l.relocBatch
|
||||||
|
|
@ -2161,22 +2153,7 @@ func (l *Loader) PropagateLoaderChangesToSymbols(toconvert []Sym, anonVerReplace
|
||||||
relfix = true
|
relfix = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// For 'new' symbols, copy other content (such as Gotype,
|
// For 'new' symbols, copy other content.
|
||||||
// sym file, relocations, etc).
|
|
||||||
if isnew {
|
|
||||||
if gt := l.SymGoType(cand); gt != 0 {
|
|
||||||
s.Gotype = l.Syms[gt]
|
|
||||||
}
|
|
||||||
if f, ok := l.symPkg[cand]; ok {
|
|
||||||
s.File = f
|
|
||||||
} else {
|
|
||||||
r, _ := l.toLocal(cand)
|
|
||||||
if r != nil && r != l.extReader {
|
|
||||||
s.File = l.SymPkg(cand)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if relfix {
|
if relfix {
|
||||||
relocfixup = append(relocfixup, cand)
|
relocfixup = append(relocfixup, cand)
|
||||||
}
|
}
|
||||||
|
|
@ -2276,6 +2253,7 @@ func (l *Loader) installSym(i Sym, s *sym.Symbol) {
|
||||||
panic("sym already present in installSym")
|
panic("sym already present in installSym")
|
||||||
}
|
}
|
||||||
l.Syms[i] = s
|
l.Syms[i] = s
|
||||||
|
s.SymIdx = sym.LoaderSym(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// addNewSym adds a new sym.Symbol to the i-th index in the list of symbols.
|
// addNewSym adds a new sym.Symbol to the i-th index in the list of symbols.
|
||||||
|
|
@ -2554,11 +2532,6 @@ func (l *Loader) CreateStaticSym(name string) Sym {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadObjFull(l *Loader, r *oReader) {
|
func loadObjFull(l *Loader, r *oReader) {
|
||||||
resolveSymRef := func(s goobj2.SymRef) *sym.Symbol {
|
|
||||||
i := l.resolve(r, s)
|
|
||||||
return l.Syms[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, n := 0, r.NSym()+r.NNonpkgdef(); i < n; i++ {
|
for i, n := 0, r.NSym()+r.NNonpkgdef(); i < n; i++ {
|
||||||
// A symbol may be a dup or overwritten. In this case, its
|
// A symbol may be a dup or overwritten. In this case, its
|
||||||
// content will actually be provided by a different object
|
// content will actually be provided by a different object
|
||||||
|
|
@ -2595,12 +2568,7 @@ func loadObjFull(l *Loader, r *oReader) {
|
||||||
for j := range auxs {
|
for j := range auxs {
|
||||||
a := &auxs[j]
|
a := &auxs[j]
|
||||||
switch a.Type() {
|
switch a.Type() {
|
||||||
case goobj2.AuxGotype:
|
case goobj2.AuxFuncInfo, goobj2.AuxFuncdata, goobj2.AuxGotype:
|
||||||
typ := resolveSymRef(a.Sym())
|
|
||||||
if typ != nil {
|
|
||||||
s.Gotype = typ
|
|
||||||
}
|
|
||||||
case goobj2.AuxFuncInfo, goobj2.AuxFuncdata:
|
|
||||||
// already handled
|
// already handled
|
||||||
case goobj2.AuxDwarfInfo, goobj2.AuxDwarfLoc, goobj2.AuxDwarfRanges, goobj2.AuxDwarfLines:
|
case goobj2.AuxDwarfInfo, goobj2.AuxDwarfLoc, goobj2.AuxDwarfRanges, goobj2.AuxDwarfLines:
|
||||||
// ignored for now
|
// ignored for now
|
||||||
|
|
@ -2609,7 +2577,6 @@ func loadObjFull(l *Loader, r *oReader) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.File = r.pkgprefix[:len(r.pkgprefix)-1]
|
|
||||||
if s.Size < int64(size) {
|
if s.Size < int64(size) {
|
||||||
s.Size = int64(size)
|
s.Size = int64(size)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
|
||||||
_32bit uintptr // size on 32bit platforms
|
_32bit uintptr // size on 32bit platforms
|
||||||
_64bit uintptr // size on 64bit platforms
|
_64bit uintptr // size on 64bit platforms
|
||||||
}{
|
}{
|
||||||
{Symbol{}, 104, 168},
|
{Symbol{}, 96, 152},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,7 @@ type Symbol struct {
|
||||||
Size int64
|
Size int64
|
||||||
Sub *Symbol
|
Sub *Symbol
|
||||||
Outer *Symbol
|
Outer *Symbol
|
||||||
Gotype *Symbol
|
SymIdx LoaderSym
|
||||||
File string // actually package!
|
|
||||||
auxinfo *AuxSymbol
|
auxinfo *AuxSymbol
|
||||||
Sect *Section
|
Sect *Section
|
||||||
Unit *CompilationUnit
|
Unit *CompilationUnit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue