Skip to content

Commit b338f6b

Browse files
Zxillygopherbot
authored andcommitted
cmd/link: fix outdated output mmap check
Outbuf.View used to perform a mmap check by default and return an error if the check failed, this behavior has been changed so that now the View never returns any error, so the usage needs to be modified accordingly. Change-Id: I76ffcda5476847f6fed59856a5a5161734f47562 GitHub-Last-Rev: 6449f29 GitHub-Pull-Request: #73730 Reviewed-on: https://go-review.googlesource.com/c/go/+/673095 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 8105ea5 commit b338f6b

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

src/cmd/link/internal/ld/asmb.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,7 @@ func relocSectFn(ctxt *Link, relocSect func(*Link, *OutBuf, *sym.Section, []load
195195
fn = func(ctxt *Link, sect *sym.Section, syms []loader.Sym) {
196196
wg.Add(1)
197197
sem <- 1
198-
out, err := ctxt.Out.View(sect.Reloff)
199-
if err != nil {
200-
panic(err)
201-
}
198+
out := ctxt.Out.View(sect.Reloff)
202199
go func() {
203200
relocSect(ctxt, out, sect, syms)
204201
wg.Done()

src/cmd/link/internal/ld/data.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ func writeBlocks(ctxt *Link, out *OutBuf, sem chan int, ldr *loader.Loader, syms
10631063
}
10641064

10651065
// Start the block output operator.
1066-
if o, err := out.View(uint64(out.Offset() + written)); err == nil {
1066+
if ctxt.Out.isMmapped() {
1067+
o := out.View(uint64(out.Offset() + written))
10671068
sem <- 1
10681069
wg.Add(1)
10691070
go func(o *OutBuf, ldr *loader.Loader, syms []loader.Sym, addr, size int64, pad []byte) {
@@ -1142,15 +1143,16 @@ type writeFn func(*Link, *OutBuf, int64, int64)
11421143

11431144
// writeParallel handles scheduling parallel execution of data write functions.
11441145
func writeParallel(wg *sync.WaitGroup, fn writeFn, ctxt *Link, seek, vaddr, length uint64) {
1145-
if out, err := ctxt.Out.View(seek); err != nil {
1146-
ctxt.Out.SeekSet(int64(seek))
1147-
fn(ctxt, ctxt.Out, int64(vaddr), int64(length))
1148-
} else {
1146+
if ctxt.Out.isMmapped() {
1147+
out := ctxt.Out.View(seek)
11491148
wg.Add(1)
11501149
go func() {
11511150
defer wg.Done()
11521151
fn(ctxt, out, int64(vaddr), int64(length))
11531152
}()
1153+
} else {
1154+
ctxt.Out.SeekSet(int64(seek))
1155+
fn(ctxt, ctxt.Out, int64(vaddr), int64(length))
11541156
}
11551157
}
11561158

src/cmd/link/internal/ld/outbuf.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,15 @@ func NewOutBuf(arch *sys.Arch) *OutBuf {
9292
}
9393
}
9494

95-
var viewError = errors.New("output not mmapped")
96-
97-
func (out *OutBuf) View(start uint64) (*OutBuf, error) {
95+
func (out *OutBuf) View(start uint64) *OutBuf {
9896
return &OutBuf{
9997
arch: out.arch,
10098
name: out.name,
10199
buf: out.buf,
102100
heap: out.heap,
103101
off: int64(start),
104102
isView: true,
105-
}, nil
103+
}
106104
}
107105

108106
var viewCloseError = errors.New("cannot Close OutBuf from View")

0 commit comments

Comments
 (0)