Commit c80338ac authored by David Crawshaw's avatar David Crawshaw

cmd/link: remove ctxt from objfile reader

Preparation for moving the object file reader to its own package.

For #22095

Change-Id: I31fe4a10a2c465f8ea4bf548f40918807e4ec6b5
Reviewed-on: https://go-review.googlesource.com/67314
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 52abe50c
...@@ -1425,7 +1425,8 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn string, fil ...@@ -1425,7 +1425,8 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn string, fil
ldpkg(ctxt, f, pkg, import1-import0-2, pn, whence) // -2 for !\n ldpkg(ctxt, f, pkg, import1-import0-2, pn, whence) // -2 for !\n
f.Seek(import1, 0) f.Seek(import1, 0)
LoadObjFile(ctxt, f, lib, eof-f.Offset(), pn) LoadObjFile(ctxt.Arch, ctxt.Syms, f, lib, eof-f.Offset(), pn)
lib.addImports(ctxt, pn)
return nil return nil
} }
......
...@@ -206,21 +206,33 @@ func (l *Link) Logf(format string, args ...interface{}) { ...@@ -206,21 +206,33 @@ func (l *Link) Logf(format string, args ...interface{}) {
} }
type Library struct { type Library struct {
Objref string Objref string
Srcref string Srcref string
File string File string
Pkg string Pkg string
Shlib string Shlib string
hash string hash string
imports []*Library importStrings []string
textp []*Symbol // text symbols defined in this library imports []*Library
dupTextSyms []*Symbol // dupok text symbols defined in this library textp []*Symbol // text symbols defined in this library
dupTextSyms []*Symbol // dupok text symbols defined in this library
} }
func (l Library) String() string { func (l Library) String() string {
return l.Pkg return l.Pkg
} }
func (l *Library) addImports(ctxt *Link, pn string) {
pkg := objabi.PathToPrefix(l.Pkg)
for _, importStr := range l.importStrings {
lib := addlib(ctxt, pkg, pn, importStr)
if lib != nil {
l.imports = append(l.imports, lib)
}
}
l.importStrings = nil
}
type FuncInfo struct { type FuncInfo struct {
Args int32 Args int32
Locals int32 Locals int32
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"cmd/internal/bio" "cmd/internal/bio"
"cmd/internal/dwarf" "cmd/internal/dwarf"
"cmd/internal/objabi" "cmd/internal/objabi"
"cmd/internal/sys"
"crypto/sha1" "crypto/sha1"
"encoding/base64" "encoding/base64"
"io" "io"
...@@ -30,7 +31,8 @@ var emptyPkg = []byte(`"".`) ...@@ -30,7 +31,8 @@ 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 arch *sys.Arch
syms *Symbols
lib *Library lib *Library
pn string pn string
dupSym *Symbol dupSym *Symbol
...@@ -50,16 +52,16 @@ type objReader struct { ...@@ -50,16 +52,16 @@ type objReader struct {
file []*Symbol file []*Symbol
} }
func LoadObjFile(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn string) { func LoadObjFile(arch *sys.Arch, syms *Symbols, f *bio.Reader, lib *Library, length int64, pn string) {
start := f.Offset() start := f.Offset()
r := &objReader{ r := &objReader{
rd: f.Reader, rd: f.Reader,
lib: lib, lib: lib,
ctxt: ctxt, arch: arch,
syms: syms,
pn: pn, pn: pn,
dupSym: &Symbol{Name: ".dup"}, dupSym: &Symbol{Name: ".dup"},
localSymVersion: ctxt.Syms.IncVersion(), localSymVersion: syms.IncVersion(),
} }
r.loadObjFile() r.loadObjFile()
if f.Offset() != start+length { if f.Offset() != start+length {
...@@ -68,8 +70,6 @@ func LoadObjFile(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn strin ...@@ -68,8 +70,6 @@ func LoadObjFile(ctxt *Link, f *bio.Reader, lib *Library, length int64, pn strin
} }
func (r *objReader) loadObjFile() { func (r *objReader) loadObjFile() {
pkg := objabi.PathToPrefix(r.lib.Pkg)
// Magic header // Magic header
var buf [8]uint8 var buf [8]uint8
r.readFull(buf[:]) r.readFull(buf[:])
...@@ -89,10 +89,7 @@ func (r *objReader) loadObjFile() { ...@@ -89,10 +89,7 @@ func (r *objReader) loadObjFile() {
if lib == "" { if lib == "" {
break break
} }
l := addlib(r.ctxt, pkg, r.pn, lib) r.lib.importStrings = append(r.lib.importStrings, lib)
if l != nil {
r.lib.imports = append(r.lib.imports, l)
}
} }
// Symbol references // Symbol references
...@@ -386,7 +383,7 @@ func (r *objReader) readRef() { ...@@ -386,7 +383,7 @@ func (r *objReader) readRef() {
if v == 1 { if v == 1 {
v = r.localSymVersion v = r.localSymVersion
} }
s := r.ctxt.Syms.Lookup(name, v) s := r.syms.Lookup(name, v)
r.refs = append(r.refs, s) r.refs = append(r.refs, s)
if s == nil || v != 0 { if s == nil || v != 0 {
...@@ -404,9 +401,9 @@ func (r *objReader) readRef() { ...@@ -404,9 +401,9 @@ func (r *objReader) readRef() {
if uint64(uint32(x)) != x { if uint64(uint32(x)) != x {
log.Panicf("$-symbol %s too large: %d", s.Name, x) log.Panicf("$-symbol %s too large: %d", s.Name, x)
} }
s.AddUint32(r.ctxt.Arch, uint32(x)) s.AddUint32(r.arch, uint32(x))
case "$f64.", "$i64.": case "$f64.", "$i64.":
s.AddUint64(r.ctxt.Arch, x) s.AddUint64(r.arch, x)
default: default:
log.Panicf("unrecognized $-symbol: %s", s.Name) log.Panicf("unrecognized $-symbol: %s", s.Name)
} }
......
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