mirror of
https://github.com/golang/go
synced 2024-11-18 15:54:42 -07:00
cmd/link: kill off Symbols.Version
Change-Id: Iee8f773355870f2333637a093e51c5fd36e5a6e5 Reviewed-on: https://go-review.googlesource.com/29349 Run-TryBot: Michael Hudson-Doyle <michael.hudson@canonical.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
6383709272
commit
b6324ef5ff
@ -445,7 +445,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
ctxt.Logf("%5.2f ldelf %s\n", obj.Cputime(), pn)
|
ctxt.Logf("%5.2f ldelf %s\n", obj.Cputime(), pn)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.Syms.IncVersion()
|
localSymVersion := ctxt.Syms.IncVersion()
|
||||||
base := f.Offset()
|
base := f.Offset()
|
||||||
|
|
||||||
var add uint64
|
var add uint64
|
||||||
@ -702,7 +702,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
||||||
s = ctxt.Syms.Lookup(name, ctxt.Syms.Version)
|
s = ctxt.Syms.Lookup(name, localSymVersion)
|
||||||
|
|
||||||
switch int(sect.flags) & (ElfSectFlagAlloc | ElfSectFlagWrite | ElfSectFlagExec) {
|
switch int(sect.flags) & (ElfSectFlagAlloc | ElfSectFlagWrite | ElfSectFlagExec) {
|
||||||
default:
|
default:
|
||||||
@ -741,7 +741,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
symbols = make([]*Symbol, elfobj.nsymtab)
|
symbols = make([]*Symbol, elfobj.nsymtab)
|
||||||
|
|
||||||
for i := 1; i < elfobj.nsymtab; i++ {
|
for i := 1; i < elfobj.nsymtab; i++ {
|
||||||
if err = readelfsym(ctxt, elfobj, i, &sym, 1); err != nil {
|
if err = readelfsym(ctxt, elfobj, i, &sym, 1, localSymVersion); err != nil {
|
||||||
goto bad
|
goto bad
|
||||||
}
|
}
|
||||||
symbols[i] = sym.sym
|
symbols[i] = sym.sym
|
||||||
@ -903,7 +903,7 @@ func ldelf(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
if info>>32 == 0 { // absolute relocation, don't bother reading the null symbol
|
if info>>32 == 0 { // absolute relocation, don't bother reading the null symbol
|
||||||
rp.Sym = nil
|
rp.Sym = nil
|
||||||
} else {
|
} else {
|
||||||
if err = readelfsym(ctxt, elfobj, int(info>>32), &sym, 0); err != nil {
|
if err = readelfsym(ctxt, elfobj, int(info>>32), &sym, 0, 0); err != nil {
|
||||||
goto bad
|
goto bad
|
||||||
}
|
}
|
||||||
sym.sym = symbols[info>>32]
|
sym.sym = symbols[info>>32]
|
||||||
@ -983,7 +983,7 @@ func elfmap(elfobj *ElfObj, sect *ElfSect) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (err error) {
|
func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int, localSymVersion int) (err error) {
|
||||||
if i >= elfobj.nsymtab || i < 0 {
|
if i >= elfobj.nsymtab || i < 0 {
|
||||||
err = fmt.Errorf("invalid elf symbol index")
|
err = fmt.Errorf("invalid elf symbol index")
|
||||||
return err
|
return err
|
||||||
@ -1059,7 +1059,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (er
|
|||||||
// We need to be able to look this up,
|
// We need to be able to look this up,
|
||||||
// so put it in the hash table.
|
// so put it in the hash table.
|
||||||
if needSym != 0 {
|
if needSym != 0 {
|
||||||
s = ctxt.Syms.Lookup(sym.name, ctxt.Syms.Version)
|
s = ctxt.Syms.Lookup(sym.name, localSymVersion)
|
||||||
s.Type |= obj.SHIDDEN
|
s.Type |= obj.SHIDDEN
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1070,7 +1070,7 @@ func readelfsym(ctxt *Link, elfobj *ElfObj, i int, sym *ElfSym, needSym int) (er
|
|||||||
// local names and hidden global names are unique
|
// local names and hidden global names are unique
|
||||||
// and should only be referenced by their index, not name, so we
|
// and should only be referenced by their index, not name, so we
|
||||||
// don't bother to add them into the hash table
|
// don't bother to add them into the hash table
|
||||||
s = ctxt.Syms.newsym(sym.name, ctxt.Syms.Version)
|
s = ctxt.Syms.newsym(sym.name, localSymVersion)
|
||||||
|
|
||||||
s.Type |= obj.SHIDDEN
|
s.Type |= obj.SHIDDEN
|
||||||
}
|
}
|
||||||
|
@ -444,7 +444,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
var rp *Reloc
|
var rp *Reloc
|
||||||
var name string
|
var name string
|
||||||
|
|
||||||
ctxt.Syms.IncVersion()
|
localSymVersion := ctxt.Syms.IncVersion()
|
||||||
base := f.Offset()
|
base := f.Offset()
|
||||||
if _, err := io.ReadFull(f, hdr[:]); err != nil {
|
if _, err := io.ReadFull(f, hdr[:]); err != nil {
|
||||||
goto bad
|
goto bad
|
||||||
@ -587,7 +587,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
name = fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
name = fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
||||||
s = ctxt.Syms.Lookup(name, ctxt.Syms.Version)
|
s = ctxt.Syms.Lookup(name, localSymVersion)
|
||||||
if s.Type != 0 {
|
if s.Type != 0 {
|
||||||
err = fmt.Errorf("duplicate %s/%s", sect.segname, sect.name)
|
err = fmt.Errorf("duplicate %s/%s", sect.segname, sect.name)
|
||||||
goto bad
|
goto bad
|
||||||
@ -634,7 +634,7 @@ func ldmacho(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
}
|
}
|
||||||
v := 0
|
v := 0
|
||||||
if sym.type_&N_EXT == 0 {
|
if sym.type_&N_EXT == 0 {
|
||||||
v = ctxt.Syms.Version
|
v = localSymVersion
|
||||||
}
|
}
|
||||||
s = ctxt.Syms.Lookup(name, v)
|
s = ctxt.Syms.Lookup(name, v)
|
||||||
if sym.type_&N_EXT == 0 {
|
if sym.type_&N_EXT == 0 {
|
||||||
|
@ -136,7 +136,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sect *PeSect
|
var sect *PeSect
|
||||||
ctxt.Syms.IncVersion()
|
localSymVersion := ctxt.Syms.IncVersion()
|
||||||
base := f.Offset()
|
base := f.Offset()
|
||||||
|
|
||||||
peobj := new(PeObj)
|
peobj := new(PeObj)
|
||||||
@ -246,7 +246,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
name = fmt.Sprintf("%s(%s)", pkg, sect.name)
|
||||||
s = ctxt.Syms.Lookup(name, ctxt.Syms.Version)
|
s = ctxt.Syms.Lookup(name, localSymVersion)
|
||||||
|
|
||||||
switch sect.sh.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
|
switch sect.sh.Characteristics & (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE) {
|
||||||
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
|
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ: //.rdata
|
||||||
@ -300,7 +300,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
rva := Le32(symbuf[0:])
|
rva := Le32(symbuf[0:])
|
||||||
symindex := Le32(symbuf[4:])
|
symindex := Le32(symbuf[4:])
|
||||||
type_ := Le16(symbuf[8:])
|
type_ := Le16(symbuf[8:])
|
||||||
if err = readpesym(ctxt, peobj, int(symindex), &sym); err != nil {
|
if err = readpesym(ctxt, peobj, int(symindex), &sym, localSymVersion); err != nil {
|
||||||
goto bad
|
goto bad
|
||||||
}
|
}
|
||||||
if sym.sym == nil {
|
if sym.sym == nil {
|
||||||
@ -371,7 +371,7 @@ func ldpe(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = readpesym(ctxt, peobj, i, &sym); err != nil {
|
if err = readpesym(ctxt, peobj, i, &sym, localSymVersion); err != nil {
|
||||||
goto bad
|
goto bad
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ func issect(s *PeSym) bool {
|
|||||||
return s.sclass == IMAGE_SYM_CLASS_STATIC && s.type_ == 0 && s.name[0] == '.'
|
return s.sclass == IMAGE_SYM_CLASS_STATIC && s.type_ == 0 && s.name[0] == '.'
|
||||||
}
|
}
|
||||||
|
|
||||||
func readpesym(ctxt *Link, peobj *PeObj, i int, y **PeSym) (err error) {
|
func readpesym(ctxt *Link, peobj *PeObj, i int, y **PeSym, localSymVersion int) (err error) {
|
||||||
if uint(i) >= peobj.npesym || i < 0 {
|
if uint(i) >= peobj.npesym || i < 0 {
|
||||||
err = fmt.Errorf("invalid pe symbol index")
|
err = fmt.Errorf("invalid pe symbol index")
|
||||||
return err
|
return err
|
||||||
@ -514,7 +514,7 @@ func readpesym(ctxt *Link, peobj *PeObj, i int, y **PeSym) (err error) {
|
|||||||
s = ctxt.Syms.Lookup(name, 0)
|
s = ctxt.Syms.Lookup(name, 0)
|
||||||
|
|
||||||
case IMAGE_SYM_CLASS_NULL, IMAGE_SYM_CLASS_STATIC, IMAGE_SYM_CLASS_LABEL:
|
case IMAGE_SYM_CLASS_NULL, IMAGE_SYM_CLASS_STATIC, IMAGE_SYM_CLASS_LABEL:
|
||||||
s = ctxt.Syms.Lookup(name, ctxt.Syms.Version)
|
s = ctxt.Syms.Lookup(name, localSymVersion)
|
||||||
s.Attr |= AttrDuplicateOK
|
s.Attr |= AttrDuplicateOK
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -130,16 +130,17 @@ var emptyPkg = []byte(`"".`)
|
|||||||
|
|
||||||
// objReader reads Go object files.
|
// objReader reads Go object files.
|
||||||
type objReader struct {
|
type objReader struct {
|
||||||
rd *bufio.Reader
|
rd *bufio.Reader
|
||||||
ctxt *Link
|
ctxt *Link
|
||||||
pkg string
|
pkg string
|
||||||
pn string
|
pn string
|
||||||
// List of symbol references for the file being read.
|
dupSym *Symbol
|
||||||
dupSym *Symbol
|
localSymVersion int
|
||||||
|
|
||||||
// rdBuf is used by readString and readSymName as scratch for reading strings.
|
// rdBuf is used by readString and readSymName as scratch for reading strings.
|
||||||
rdBuf []byte
|
rdBuf []byte
|
||||||
|
|
||||||
|
// List of symbol references for the file being read.
|
||||||
refs []*Symbol
|
refs []*Symbol
|
||||||
data []byte
|
data []byte
|
||||||
reloc []Reloc
|
reloc []Reloc
|
||||||
@ -153,11 +154,12 @@ type objReader struct {
|
|||||||
func LoadObjFile(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
func LoadObjFile(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||||
start := f.Offset()
|
start := f.Offset()
|
||||||
r := &objReader{
|
r := &objReader{
|
||||||
rd: f.Reader,
|
rd: f.Reader,
|
||||||
pkg: pkg,
|
pkg: pkg,
|
||||||
ctxt: ctxt,
|
ctxt: ctxt,
|
||||||
pn: pn,
|
pn: pn,
|
||||||
dupSym: &Symbol{Name: ".dup"},
|
dupSym: &Symbol{Name: ".dup"},
|
||||||
|
localSymVersion: ctxt.Syms.IncVersion(),
|
||||||
}
|
}
|
||||||
r.loadObjFile()
|
r.loadObjFile()
|
||||||
if f.Offset() != start+length {
|
if f.Offset() != start+length {
|
||||||
@ -166,8 +168,6 @@ func LoadObjFile(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *objReader) loadObjFile() {
|
func (r *objReader) loadObjFile() {
|
||||||
// Increment context version, versions are used to differentiate static files in different packages
|
|
||||||
r.ctxt.Syms.IncVersion()
|
|
||||||
|
|
||||||
// Magic header
|
// Magic header
|
||||||
var buf [8]uint8
|
var buf [8]uint8
|
||||||
@ -452,7 +452,7 @@ func (r *objReader) readRef() {
|
|||||||
log.Fatalf("invalid symbol version %d", v)
|
log.Fatalf("invalid symbol version %d", v)
|
||||||
}
|
}
|
||||||
if v == 1 {
|
if v == 1 {
|
||||||
v = r.ctxt.Syms.Version
|
v = r.localSymVersion
|
||||||
}
|
}
|
||||||
s := r.ctxt.Syms.Lookup(name, v)
|
s := r.ctxt.Syms.Lookup(name, v)
|
||||||
r.refs = append(r.refs, s)
|
r.refs = append(r.refs, s)
|
||||||
|
@ -37,8 +37,6 @@ type Symbols struct {
|
|||||||
hash []map[string]*Symbol
|
hash []map[string]*Symbol
|
||||||
|
|
||||||
Allsym []*Symbol
|
Allsym []*Symbol
|
||||||
|
|
||||||
Version int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (syms *Symbols) newsym(name string, v int) *Symbol {
|
func (syms *Symbols) newsym(name string, v int) *Symbol {
|
||||||
@ -80,11 +78,7 @@ func (syms *Symbols) ROLookup(name string, v int) *Symbol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a new version (i.e. symbol namespace).
|
// Allocate a new version (i.e. symbol namespace).
|
||||||
//
|
func (syms *Symbols) IncVersion() int {
|
||||||
// TODO(mwhudson): This would feel more natural if it returned the new
|
|
||||||
// version (or if we dropped Symbols.Version entirely and just
|
|
||||||
// returned len(syms.hash))
|
|
||||||
func (syms *Symbols) IncVersion() {
|
|
||||||
syms.Version++
|
|
||||||
syms.hash = append(syms.hash, make(map[string]*Symbol))
|
syms.hash = append(syms.hash, make(map[string]*Symbol))
|
||||||
|
return len(syms.hash) - 1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user