mirror of
https://github.com/golang/go
synced 2024-11-06 22:36:15 -07:00
[dev.link] cmd/link: remove old objs from host obj loaders
Change-Id: I9ee853e37090ea015aba817d9aeb2f4cc9ff5a1b Reviewed-on: https://go-review.googlesource.com/c/go/+/206539 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
8cdb769b08
commit
aacffb6576
@ -1692,7 +1692,6 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
||||
|
||||
magic := uint32(c1)<<24 | uint32(c2)<<16 | uint32(c3)<<8 | uint32(c4)
|
||||
if magic == 0x7f454c46 { // \x7F E L F
|
||||
if *flagNewobj {
|
||||
ldelf := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, flags, err := loadelf.Load(ctxt.loader, ctxt.Arch, ctxt.Syms, f, pkg, length, pn, ehdr.flags)
|
||||
if err != nil {
|
||||
@ -1703,22 +1702,9 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldelf, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
} else {
|
||||
ldelf := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, flags, err := loadelf.LoadOld(ctxt.Arch, ctxt.Syms, f, pkg, length, pn, ehdr.flags)
|
||||
if err != nil {
|
||||
Errorf(nil, "%v", err)
|
||||
return
|
||||
}
|
||||
ehdr.flags = flags
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldelf, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
}
|
||||
}
|
||||
|
||||
if magic&^1 == 0xfeedface || magic&^0x01000000 == 0xcefaedfe {
|
||||
if *flagNewobj {
|
||||
ldmacho := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, err := loadmacho.Load(ctxt.loader, ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
|
||||
if err != nil {
|
||||
@ -1728,21 +1714,9 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldmacho, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
} else {
|
||||
ldmacho := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, err := loadmacho.LoadOld(ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
|
||||
if err != nil {
|
||||
Errorf(nil, "%v", err)
|
||||
return
|
||||
}
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldmacho, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
}
|
||||
}
|
||||
|
||||
if c1 == 0x4c && c2 == 0x01 || c1 == 0x64 && c2 == 0x86 {
|
||||
if *flagNewobj {
|
||||
ldpe := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, rsrc, err := loadpe.Load(ctxt.loader, ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
|
||||
if err != nil {
|
||||
@ -1755,24 +1729,9 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldpe, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
} else {
|
||||
ldpe := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, rsrc, err := loadpe.LoadOld(ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
|
||||
if err != nil {
|
||||
Errorf(nil, "%v", err)
|
||||
return
|
||||
}
|
||||
if rsrc != nil {
|
||||
setpersrc(ctxt, rsrc)
|
||||
}
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldpe, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
}
|
||||
}
|
||||
|
||||
if c1 == 0x01 && (c2 == 0xD7 || c2 == 0xF7) {
|
||||
if *flagNewobj {
|
||||
ldxcoff := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, err := loadxcoff.Load(ctxt.loader, ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
|
||||
if err != nil {
|
||||
@ -1782,17 +1741,6 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldxcoff, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
} else {
|
||||
ldxcoff := func(ctxt *Link, f *bio.Reader, pkg string, length int64, pn string) {
|
||||
textp, err := loadxcoff.LoadOld(ctxt.Arch, ctxt.Syms, f, pkg, length, pn)
|
||||
if err != nil {
|
||||
Errorf(nil, "%v", err)
|
||||
return
|
||||
}
|
||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
||||
}
|
||||
return ldhostobj(ldxcoff, ctxt.HeadType, f, pkg, length, pn, file)
|
||||
}
|
||||
}
|
||||
|
||||
/* check the header */
|
||||
|
@ -452,20 +452,7 @@ func parseArmAttributes(e binary.ByteOrder, data []byte) (found bool, ehdrFlags
|
||||
return found, ehdrFlags, nil
|
||||
}
|
||||
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length int64, pn string, flags uint32) ([]*sym.Symbol, uint32, error) {
|
||||
newSym := func(name string, version int) *sym.Symbol {
|
||||
return l.LookupOrCreate(name, version, syms)
|
||||
}
|
||||
return load(arch, syms.IncVersion(), newSym, newSym, f, pkg, length, pn, flags)
|
||||
}
|
||||
|
||||
func LoadOld(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length int64, pn string, flags uint32) ([]*sym.Symbol, uint32, error) {
|
||||
return load(arch, syms.IncVersion(), syms.Newsym, syms.Lookup, f, pkg, length, pn, flags)
|
||||
}
|
||||
|
||||
type lookupFunc func(string, int) *sym.Symbol
|
||||
|
||||
// load loads the ELF file pn from f.
|
||||
// Load loads the ELF file pn from f.
|
||||
// Symbols are written into syms, and a slice of the text symbols is returned.
|
||||
//
|
||||
// On ARM systems, Load will attempt to determine what ELF header flags to
|
||||
@ -473,7 +460,11 @@ type lookupFunc func(string, int) *sym.Symbol
|
||||
// parameter initEhdrFlags contains the current header flags for the output
|
||||
// object, and the returned ehdrFlags contains what this Load function computes.
|
||||
// TODO: find a better place for this logic.
|
||||
func load(arch *sys.Arch, localSymVersion int, newSym, lookup lookupFunc, f *bio.Reader, pkg string, length int64, pn string, initEhdrFlags uint32) (textp []*sym.Symbol, ehdrFlags uint32, err error) {
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length int64, pn string, initEhdrFlags uint32) (textp []*sym.Symbol, ehdrFlags uint32, err error) {
|
||||
localSymVersion := syms.IncVersion()
|
||||
lookup := func(name string, version int) *sym.Symbol {
|
||||
return l.LookupOrCreate(name, version, syms)
|
||||
}
|
||||
errorf := func(str string, args ...interface{}) ([]*sym.Symbol, uint32, error) {
|
||||
return nil, 0, fmt.Errorf("loadelf: %s: %v", pn, fmt.Sprintf(str, args...))
|
||||
}
|
||||
@ -767,7 +758,7 @@ func load(arch *sys.Arch, localSymVersion int, newSym, lookup lookupFunc, f *bio
|
||||
|
||||
for i := 1; i < elfobj.nsymtab; i++ {
|
||||
var elfsym ElfSym
|
||||
if err := readelfsym(newSym, lookup, arch, elfobj, i, &elfsym, 1, localSymVersion); err != nil {
|
||||
if err := readelfsym(lookup, arch, elfobj, i, &elfsym, 1, localSymVersion); err != nil {
|
||||
return errorf("%s: malformed elf file: %v", pn, err)
|
||||
}
|
||||
symbols[i] = elfsym.sym
|
||||
@ -938,7 +929,7 @@ func load(arch *sys.Arch, localSymVersion int, newSym, lookup lookupFunc, f *bio
|
||||
rp.Sym = nil
|
||||
} else {
|
||||
var elfsym ElfSym
|
||||
if err := readelfsym(newSym, lookup, arch, elfobj, int(info>>32), &elfsym, 0, 0); err != nil {
|
||||
if err := readelfsym(lookup, arch, elfobj, int(info>>32), &elfsym, 0, 0); err != nil {
|
||||
return errorf("malformed elf file: %v", err)
|
||||
}
|
||||
elfsym.sym = symbols[info>>32]
|
||||
@ -1015,7 +1006,7 @@ func elfmap(elfobj *ElfObj, sect *ElfSect) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func readelfsym(newSym, lookup lookupFunc, arch *sys.Arch, elfobj *ElfObj, i int, elfsym *ElfSym, needSym int, localSymVersion int) (err error) {
|
||||
func readelfsym(lookup func(string, int) *sym.Symbol, arch *sys.Arch, elfobj *ElfObj, i int, elfsym *ElfSym, needSym int, localSymVersion int) (err error) {
|
||||
if i >= elfobj.nsymtab || i < 0 {
|
||||
err = fmt.Errorf("invalid elf symbol index")
|
||||
return err
|
||||
@ -1101,7 +1092,7 @@ func readelfsym(newSym, lookup lookupFunc, arch *sys.Arch, elfobj *ElfObj, i int
|
||||
// local names and hidden global names are unique
|
||||
// and should only be referenced by their index, not name, so we
|
||||
// don't bother to add them into the hash table
|
||||
s = newSym(elfsym.name, localSymVersion)
|
||||
s = lookup(elfsym.name, localSymVersion)
|
||||
|
||||
s.Attr |= sym.AttrVisibilityHidden
|
||||
}
|
||||
|
@ -421,20 +421,10 @@ func macholoadsym(m *ldMachoObj, symtab *ldMachoSymtab) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length int64, pn string) ([]*sym.Symbol, error) {
|
||||
newSym := func(name string, version int) *sym.Symbol {
|
||||
return l.LookupOrCreate(name, version, syms)
|
||||
}
|
||||
return load(arch, syms.IncVersion(), newSym, f, pkg, length, pn)
|
||||
}
|
||||
|
||||
func LoadOld(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
return load(arch, syms.IncVersion(), syms.Lookup, f, pkg, length, pn)
|
||||
}
|
||||
|
||||
// load the Mach-O file pn from f.
|
||||
// Load the Mach-O file pn from f.
|
||||
// Symbols are written into syms, and a slice of the text symbols is returned.
|
||||
func load(arch *sys.Arch, localSymVersion int, lookup func(string, int) *sym.Symbol, f *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
localSymVersion := syms.IncVersion()
|
||||
errorf := func(str string, args ...interface{}) ([]*sym.Symbol, error) {
|
||||
return nil, fmt.Errorf("loadmacho: %v: %v", pn, fmt.Sprintf(str, args...))
|
||||
}
|
||||
@ -570,7 +560,7 @@ func load(arch *sys.Arch, localSymVersion int, lookup func(string, int) *sym.Sym
|
||||
continue
|
||||
}
|
||||
name := fmt.Sprintf("%s(%s/%s)", pkg, sect.segname, sect.name)
|
||||
s := lookup(name, localSymVersion)
|
||||
s := l.LookupOrCreate(name, localSymVersion, syms)
|
||||
if s.Type != 0 {
|
||||
return errorf("duplicate %s/%s", sect.segname, sect.name)
|
||||
}
|
||||
@ -619,7 +609,7 @@ func load(arch *sys.Arch, localSymVersion int, lookup func(string, int) *sym.Sym
|
||||
if machsym.type_&N_EXT == 0 {
|
||||
v = localSymVersion
|
||||
}
|
||||
s := lookup(name, v)
|
||||
s := l.LookupOrCreate(name, v, syms)
|
||||
if machsym.type_&N_EXT == 0 {
|
||||
s.Attr |= sym.AttrDuplicateOK
|
||||
}
|
||||
|
@ -145,21 +145,14 @@ func (f *peBiobuf) ReadAt(p []byte, off int64) (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Load loads the PE file pn from input.
|
||||
// Symbols are written into syms, and a slice of the text symbols is returned.
|
||||
// If an .rsrc section is found, its symbol is returned as rsrc.
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, rsrc *sym.Symbol, err error) {
|
||||
lookup := func(name string, version int) *sym.Symbol {
|
||||
return l.LookupOrCreate(name, version, syms)
|
||||
}
|
||||
return load(arch, lookup, syms.IncVersion(), input, pkg, length, pn)
|
||||
}
|
||||
|
||||
func LoadOld(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, rsrc *sym.Symbol, err error) {
|
||||
return load(arch, syms.Lookup, syms.IncVersion(), input, pkg, length, pn)
|
||||
}
|
||||
|
||||
// load loads the PE file pn from input.
|
||||
// Symbols are written into syms, and a slice of the text symbols is returned.
|
||||
// If an .rsrc section is found, its symbol is returned as rsrc.
|
||||
func load(arch *sys.Arch, lookup func(string, int) *sym.Symbol, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, rsrc *sym.Symbol, err error) {
|
||||
localSymVersion := syms.IncVersion()
|
||||
sectsyms := make(map[*pe.Section]*sym.Symbol)
|
||||
sectdata := make(map[*pe.Section][]byte)
|
||||
|
||||
|
@ -39,22 +39,10 @@ func (f *xcoffBiobuf) ReadAt(p []byte, off int64) (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Load loads xcoff files with the indexed object files.
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
lookup := func(name string, version int) *sym.Symbol {
|
||||
return l.LookupOrCreate(name, version, syms)
|
||||
}
|
||||
return load(arch, lookup, syms.IncVersion(), input, pkg, length, pn)
|
||||
}
|
||||
|
||||
// LoadOld uses the old version of object loading.
|
||||
func LoadOld(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
return load(arch, syms.Lookup, syms.IncVersion(), input, pkg, length, pn)
|
||||
}
|
||||
|
||||
// loads the Xcoff file pn from f.
|
||||
// Symbols are written into syms, and a slice of the text symbols is returned.
|
||||
func load(arch *sys.Arch, lookup func(string, int) *sym.Symbol, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
func Load(l *loader.Loader, arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
||||
localSymVersion := syms.IncVersion()
|
||||
errorf := func(str string, args ...interface{}) ([]*sym.Symbol, error) {
|
||||
return nil, fmt.Errorf("loadxcoff: %v: %v", pn, fmt.Sprintf(str, args...))
|
||||
}
|
||||
@ -75,7 +63,7 @@ func load(arch *sys.Arch, lookup func(string, int) *sym.Symbol, localSymVersion
|
||||
lds := new(ldSection)
|
||||
lds.Section = *sect
|
||||
name := fmt.Sprintf("%s(%s)", pkg, lds.Name)
|
||||
s := lookup(name, localSymVersion)
|
||||
s := l.LookupOrCreate(name, localSymVersion, syms)
|
||||
|
||||
switch lds.Type {
|
||||
default:
|
||||
@ -113,7 +101,7 @@ func load(arch *sys.Arch, lookup func(string, int) *sym.Symbol, localSymVersion
|
||||
continue
|
||||
}
|
||||
|
||||
s := lookup(sx.Name, 0)
|
||||
s := l.LookupOrCreate(sx.Name, 0, syms)
|
||||
|
||||
// Text symbol
|
||||
if s.Type == sym.STEXT {
|
||||
@ -135,7 +123,7 @@ func load(arch *sys.Arch, lookup func(string, int) *sym.Symbol, localSymVersion
|
||||
for i, rx := range sect.Relocs {
|
||||
r := &rs[i]
|
||||
|
||||
r.Sym = lookup(rx.Symbol.Name, 0)
|
||||
r.Sym = l.LookupOrCreate(rx.Symbol.Name, 0, syms)
|
||||
if uint64(int32(rx.VirtualAddress)) != rx.VirtualAddress {
|
||||
return errorf("virtual address of a relocation is too big: 0x%x", rx.VirtualAddress)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user