]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: remove global datap, moved to *Link
authorJeremy Faller <jeremy@golang.org>
Mon, 9 Mar 2020 15:08:04 +0000 (11:08 -0400)
committerJeremy Faller <jeremy@golang.org>
Tue, 24 Mar 2020 16:01:15 +0000 (16:01 +0000)
This change moves datap from global space into the link context. Rather
than having it exist in context, we could have it returned from dodata,
and pass it as a parameter, but it is used in awkward places in the
Arch functions. Easiest for now is just keeping it in the context, until
we more formally move it to slices of loader.Sym.

This is a largely non-functional change.

Change-Id: Ica93bd857c39913ad470a61c63bc8d21704d6308
Reviewed-on: https://go-review.googlesource.com/c/go/+/222664
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/elf.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/ld/macho.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/ld/xcoff.go

index 603630c6bc9f95e850851e8334d9f6c5962bc16d..5682997b791e8209025002100bda6edfb6424f77 100644 (file)
@@ -586,7 +586,7 @@ func (ctxt *Link) reloc() {
                wg.Done()
        }()
        go func() {
-               for _, s := range datap {
+               for _, s := range ctxt.datap {
                        relocsym(target, reporter, lookup, syms, s)
                }
                wg.Done()
@@ -844,14 +844,14 @@ func writeDatblkToOutBuf(ctxt *Link, out *OutBuf, addr int64, size int64) {
                ctxt.Logf("datblk [%#x,%#x) at offset %#x\n", addr, addr+size, ctxt.Out.Offset())
        }
 
-       blk(out, datap, addr, size, zeros[:])
+       blk(out, ctxt.datap, addr, size, zeros[:])
 
        /* again for printing */
        if !*flagA {
                return
        }
 
-       syms := datap
+       syms := ctxt.datap
        for i, sym := range syms {
                if sym.Value >= addr {
                        syms = syms[i:]
@@ -1277,10 +1277,6 @@ func makeRelroForSharedLib(target *Link, data *[sym.SXREF][]*sym.Symbol) {
        }
 }
 
-// datap is a collection of reachable data symbols in address order.
-// Generated by dodata.
-var datap []*sym.Symbol
-
 func (ctxt *Link) dodata() {
        // Give zeros sized symbols space if necessary.
        fixZeroSizedSymbols(ctxt)
@@ -1798,7 +1794,7 @@ func (ctxt *Link) dodata() {
        }
 
        for symn := sym.SELFRXSECT; symn < sym.SXREF; symn++ {
-               datap = append(datap, data[symn]...)
+               ctxt.datap = append(ctxt.datap, data[symn]...)
        }
 
        dwarfGenerateDebugSyms(ctxt)
@@ -2344,7 +2340,7 @@ func (ctxt *Link) address() []*sym.Segment {
                }
        }
 
-       for _, s := range datap {
+       for _, s := range ctxt.datap {
                if s.Sect != nil {
                        s.Value += int64(s.Sect.Vaddr)
                }
index 078b0a55db283e0d31890e9157ac4c722266ef6d..28802f1bd8c10e29bef9a740f468f0c04ae0f365 100644 (file)
@@ -1415,18 +1415,18 @@ func Elfemitreloc(ctxt *Link) {
                if sect.Name == ".text" {
                        elfrelocsect(ctxt, sect, ctxt.Textp)
                } else {
-                       elfrelocsect(ctxt, sect, datap)
+                       elfrelocsect(ctxt, sect, ctxt.datap)
                }
        }
 
        for _, sect := range Segrodata.Sections {
-               elfrelocsect(ctxt, sect, datap)
+               elfrelocsect(ctxt, sect, ctxt.datap)
        }
        for _, sect := range Segrelrodata.Sections {
-               elfrelocsect(ctxt, sect, datap)
+               elfrelocsect(ctxt, sect, ctxt.datap)
        }
        for _, sect := range Segdata.Sections {
-               elfrelocsect(ctxt, sect, datap)
+               elfrelocsect(ctxt, sect, ctxt.datap)
        }
        for _, sect := range Segdwarf.Sections {
                elfrelocsect(ctxt, sect, dwarfp)
index 1537bc662bc57d84c99f369965b07f8bd9406ba2..833ec25a5803da465f56d0354fddce2226a17be0 100644 (file)
@@ -2605,7 +2605,7 @@ func (ctxt *Link) undef() {
        for _, s := range ctxt.Textp {
                undefsym(ctxt, s)
        }
-       for _, s := range datap {
+       for _, s := range ctxt.datap {
                undefsym(ctxt, s)
        }
        if nerrors > 0 {
index e867857a182af0232a055832697c8657db0bcaaa..2777904ccab0b7f4cf8f1a2e9a5c9ca9666d4d69 100644 (file)
@@ -91,6 +91,8 @@ type Link struct {
 
        cgo_export_static  map[string]bool
        cgo_export_dynamic map[string]bool
+
+       datap []*sym.Symbol
 }
 
 type cgodata struct {
index 3f45cc029abf8c63be756aa2a5b1bd60a7a0991e..0f36cd0cbe618a51df0f55d54c248d736f3edd79 100644 (file)
@@ -1060,10 +1060,10 @@ func Machoemitreloc(ctxt *Link) {
 
        machorelocsect(ctxt, Segtext.Sections[0], ctxt.Textp)
        for _, sect := range Segtext.Sections[1:] {
-               machorelocsect(ctxt, sect, datap)
+               machorelocsect(ctxt, sect, ctxt.datap)
        }
        for _, sect := range Segdata.Sections {
-               machorelocsect(ctxt, sect, datap)
+               machorelocsect(ctxt, sect, ctxt.datap)
        }
        for _, sect := range Segdwarf.Sections {
                machorelocsect(ctxt, sect, dwarfp)
index fdfb9962e524d11a8fa6c2b995b44ec37ea49f66..81fae7507278dd571d6f01703e20591560a0228d 100644 (file)
@@ -543,8 +543,8 @@ func (f *peFile) emitRelocations(ctxt *Link) {
                syms   []*sym.Symbol
        }{
                {f.textSect, &Segtext, ctxt.Textp},
-               {f.rdataSect, &Segrodata, datap},
-               {f.dataSect, &Segdata, datap},
+               {f.rdataSect, &Segrodata, ctxt.datap},
+               {f.dataSect, &Segdata, ctxt.datap},
        }
        for _, s := range sects {
                s.peSect.emitRelocations(ctxt.Out, func() int {
@@ -1434,7 +1434,7 @@ func addPEBaseReloc(ctxt *Link) {
        for _, s := range ctxt.Textp {
                addPEBaseRelocSym(ctxt, s, &rt)
        }
-       for _, s := range datap {
+       for _, s := range ctxt.datap {
                addPEBaseRelocSym(ctxt, s, &rt)
        }
 
index 55a404cfb0071dbc10943cbd8f24d0872ad1d475..74889b3833bf99102127a44e5f760ec9b2bb4f89 100644 (file)
@@ -1630,7 +1630,7 @@ func (f *xcoffFile) emitRelocations(ctxt *Link, fileoff int64) {
                                if sect.Name == ".text" {
                                        n += relocsect(sect, ctxt.Textp, 0)
                                } else {
-                                       n += relocsect(sect, datap, 0)
+                                       n += relocsect(sect, ctxt.datap, 0)
                                }
                        }
                }