]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: port xcoff to new loader syntax
authorJeremy Faller <jeremy@golang.org>
Thu, 23 Jan 2020 19:41:34 +0000 (14:41 -0500)
committerJeremy Faller <jeremy@golang.org>
Tue, 28 Jan 2020 18:26:28 +0000 (18:26 +0000)
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>
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/loadxcoff/ldxcoff.go

index 45c3a53d33b31324b20629905c380a2671851ae4..1652724a44c0350d636d2dc218dc33bed4bd9330 100644 (file)
@@ -1898,7 +1898,7 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
                                Errorf(nil, "%v", err)
                                return
                        }
-                       ctxt.Textp = append(ctxt.Textp, textp...)
+                       ctxt.Textp2 = append(ctxt.Textp2, textp...)
                }
                return ldhostobj(ldxcoff, ctxt.HeadType, f, pkg, length, pn, file)
        }
index 2dd495ecbffab2674739580c8efb6463d083662f..9b362ca8b89fadff0935315391d0f3ab5e39319d 100644 (file)
@@ -98,7 +98,7 @@ var (
 )
 
 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.
index e684432a6e17f371c2522163d4281627b9a0692a..cd2af5b6b3bcf66b8e46fc90d8a154c90d976e64 100644 (file)
@@ -19,7 +19,7 @@ import (
 // ldSection is an XCOFF section with its symbols.
 type ldSection struct {
        xcoff.Section
-       sym *sym.Symbol
+       sym loader.Sym
 }
 
 // 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.
 // 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) {
-       errorf := func(str string, args ...interface{}) ([]*sym.Symbol, 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{}) ([]loader.Sym, error) {
                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.Section = *sect
                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 {
                default:
                        return errorf("unrecognized section type 0x%x", lds.Type)
                case xcoff.STYP_TEXT:
-                       s.Type = sym.STEXT
+                       s.SetType(sym.STEXT)
                case xcoff.STYP_DATA:
-                       s.Type = sym.SNOPTRDATA
+                       s.SetType(sym.SNOPTRDATA)
                case xcoff.STYP_BSS:
-                       s.Type = sym.SNOPTRBSS
+                       s.SetType(sym.SNOPTRBSS)
                }
 
-               s.Size = int64(lds.Size)
-               if s.Type != sym.SNOPTRBSS {
+               s.SetSize(int64(lds.Size))
+               if s.Type() != sym.SNOPTRBSS {
                        data, err := lds.Section.Data()
                        if err != nil {
                                return nil, err
                        }
-                       s.P = data
+                       s.SetData(data)
                }
 
-               lds.sym = s
+               lds.sym = symbol
                ldSections = append(ldSections, lds)
        }
 
@@ -100,14 +101,14 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read
                        continue
                }
 
-               s := l.LookupOrCreate(sx.Name, 0)
+               s := l.LookupOrCreateSym(sx.Name, 0)
 
                // Text symbol
-               if s.Type == sym.STEXT {
-                       if s.Attr.OnList() {
-                               return errorf("symbol %s listed multiple times", s.Name)
+               if l.SymType(s) == sym.STEXT {
+                       if l.AttrOnList(s) {
+                               return errorf("symbol %s listed multiple times", l.SymName(s))
                        }
-                       s.Attr |= sym.AttrOnList
+                       l.SetAttrOnList(s, true)
                        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 {
                        continue
                }
-               rs := make([]sym.Reloc, sect.Nreloc)
+               rs := make([]loader.Reloc, sect.Nreloc)
                for i, rx := range sect.Relocs {
                        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 {
                                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 {
                                        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.Add = int64(rx.Symbol.Value)
 
                        case xcoff.R_RBR:
-                               r.Siz = 4
+                               r.Size = 4
                                r.Type = objabi.R_CALLPOWER
                                r.Add = 0 //
 
                        }
                }
-               s := sect.sym
-               s.R = rs
-               s.R = s.R[:sect.Nreloc]
+               bld, _ := l.MakeSymbolUpdater(sect.sym)
+               bld.SetRelocs(rs[:sect.Nreloc])
        }
        return textp, nil