mirror of
https://github.com/golang/go
synced 2024-11-06 12:36:22 -07:00
[dev.link] cmd/link: port xcoff to new loader syntax
Change-Id: I074dd726640f2bcf7aa50b5e10e0b3a278489cd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/216038 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
76d0977745
commit
8896a6b8aa
@ -1898,7 +1898,7 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
|
|||||||
Errorf(nil, "%v", err)
|
Errorf(nil, "%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctxt.Textp = append(ctxt.Textp, textp...)
|
ctxt.Textp2 = append(ctxt.Textp2, textp...)
|
||||||
}
|
}
|
||||||
return ldhostobj(ldxcoff, ctxt.HeadType, f, pkg, length, pn, file)
|
return ldhostobj(ldxcoff, ctxt.HeadType, f, pkg, length, pn, file)
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (ctxt *Link) loaderSupport() bool {
|
func (ctxt *Link) loaderSupport() bool {
|
||||||
return ctxt.IsELF || ctxt.HeadType == objabi.Hdarwin
|
return ctxt.IsELF || ctxt.HeadType == objabi.Hdarwin || ctxt.HeadType == objabi.Haix
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main is the main entry point for the linker code.
|
// Main is the main entry point for the linker code.
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
// ldSection is an XCOFF section with its symbols.
|
// ldSection is an XCOFF section with its symbols.
|
||||||
type ldSection struct {
|
type ldSection struct {
|
||||||
xcoff.Section
|
xcoff.Section
|
||||||
sym *sym.Symbol
|
sym loader.Sym
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(brainman): maybe just add ReadAt method to bio.Reader instead of creating xcoffBiobuf
|
// TODO(brainman): maybe just add ReadAt method to bio.Reader instead of creating xcoffBiobuf
|
||||||
@ -41,8 +41,8 @@ func (f *xcoffBiobuf) ReadAt(p []byte, off int64) (int, error) {
|
|||||||
|
|
||||||
// loads the Xcoff file pn from f.
|
// loads the Xcoff file pn from f.
|
||||||
// Symbols are written into loader, and a slice of the text symbols is returned.
|
// Symbols are written into loader, and a slice of the text symbols is returned.
|
||||||
func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []*sym.Symbol, err error) {
|
func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Reader, pkg string, length int64, pn string) (textp []loader.Sym, err error) {
|
||||||
errorf := func(str string, args ...interface{}) ([]*sym.Symbol, error) {
|
errorf := func(str string, args ...interface{}) ([]loader.Sym, error) {
|
||||||
return nil, fmt.Errorf("loadxcoff: %v: %v", pn, fmt.Sprintf(str, args...))
|
return nil, fmt.Errorf("loadxcoff: %v: %v", pn, fmt.Sprintf(str, args...))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,29 +62,30 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
|||||||
lds := new(ldSection)
|
lds := new(ldSection)
|
||||||
lds.Section = *sect
|
lds.Section = *sect
|
||||||
name := fmt.Sprintf("%s(%s)", pkg, lds.Name)
|
name := fmt.Sprintf("%s(%s)", pkg, lds.Name)
|
||||||
s := l.LookupOrCreate(name, localSymVersion)
|
symbol := l.LookupOrCreateSym(name, localSymVersion)
|
||||||
|
s, _ := l.MakeSymbolUpdater(symbol)
|
||||||
|
|
||||||
switch lds.Type {
|
switch lds.Type {
|
||||||
default:
|
default:
|
||||||
return errorf("unrecognized section type 0x%x", lds.Type)
|
return errorf("unrecognized section type 0x%x", lds.Type)
|
||||||
case xcoff.STYP_TEXT:
|
case xcoff.STYP_TEXT:
|
||||||
s.Type = sym.STEXT
|
s.SetType(sym.STEXT)
|
||||||
case xcoff.STYP_DATA:
|
case xcoff.STYP_DATA:
|
||||||
s.Type = sym.SNOPTRDATA
|
s.SetType(sym.SNOPTRDATA)
|
||||||
case xcoff.STYP_BSS:
|
case xcoff.STYP_BSS:
|
||||||
s.Type = sym.SNOPTRBSS
|
s.SetType(sym.SNOPTRBSS)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Size = int64(lds.Size)
|
s.SetSize(int64(lds.Size))
|
||||||
if s.Type != sym.SNOPTRBSS {
|
if s.Type() != sym.SNOPTRBSS {
|
||||||
data, err := lds.Section.Data()
|
data, err := lds.Section.Data()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.P = data
|
s.SetData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
lds.sym = s
|
lds.sym = symbol
|
||||||
ldSections = append(ldSections, lds)
|
ldSections = append(ldSections, lds)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,14 +101,14 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
s := l.LookupOrCreate(sx.Name, 0)
|
s := l.LookupOrCreateSym(sx.Name, 0)
|
||||||
|
|
||||||
// Text symbol
|
// Text symbol
|
||||||
if s.Type == sym.STEXT {
|
if l.SymType(s) == sym.STEXT {
|
||||||
if s.Attr.OnList() {
|
if l.AttrOnList(s) {
|
||||||
return errorf("symbol %s listed multiple times", s.Name)
|
return errorf("symbol %s listed multiple times", l.SymName(s))
|
||||||
}
|
}
|
||||||
s.Attr |= sym.AttrOnList
|
l.SetAttrOnList(s, true)
|
||||||
textp = append(textp, s)
|
textp = append(textp, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,11 +119,11 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
|||||||
if sect.Type != xcoff.STYP_TEXT && sect.Type != xcoff.STYP_DATA {
|
if sect.Type != xcoff.STYP_TEXT && sect.Type != xcoff.STYP_DATA {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rs := make([]sym.Reloc, sect.Nreloc)
|
rs := make([]loader.Reloc, sect.Nreloc)
|
||||||
for i, rx := range sect.Relocs {
|
for i, rx := range sect.Relocs {
|
||||||
r := &rs[i]
|
r := &rs[i]
|
||||||
|
|
||||||
r.Sym = l.LookupOrCreate(rx.Symbol.Name, 0)
|
r.Sym = l.LookupOrCreateSym(rx.Symbol.Name, 0)
|
||||||
if uint64(int32(rx.VirtualAddress)) != rx.VirtualAddress {
|
if uint64(int32(rx.VirtualAddress)) != rx.VirtualAddress {
|
||||||
return errorf("virtual address of a relocation is too big: 0x%x", rx.VirtualAddress)
|
return errorf("virtual address of a relocation is too big: 0x%x", rx.VirtualAddress)
|
||||||
}
|
}
|
||||||
@ -136,20 +137,19 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
|
|||||||
if rx.Length != 64 {
|
if rx.Length != 64 {
|
||||||
return errorf("section %s: relocation R_POS has length different from 64: %d", sect.Name, rx.Length)
|
return errorf("section %s: relocation R_POS has length different from 64: %d", sect.Name, rx.Length)
|
||||||
}
|
}
|
||||||
r.Siz = 8
|
r.Size = 8
|
||||||
r.Type = objabi.R_CONST
|
r.Type = objabi.R_CONST
|
||||||
r.Add = int64(rx.Symbol.Value)
|
r.Add = int64(rx.Symbol.Value)
|
||||||
|
|
||||||
case xcoff.R_RBR:
|
case xcoff.R_RBR:
|
||||||
r.Siz = 4
|
r.Size = 4
|
||||||
r.Type = objabi.R_CALLPOWER
|
r.Type = objabi.R_CALLPOWER
|
||||||
r.Add = 0 //
|
r.Add = 0 //
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s := sect.sym
|
bld, _ := l.MakeSymbolUpdater(sect.sym)
|
||||||
s.R = rs
|
bld.SetRelocs(rs[:sect.Nreloc])
|
||||||
s.R = s.R[:sect.Nreloc]
|
|
||||||
}
|
}
|
||||||
return textp, nil
|
return textp, nil
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user