Skip to content

Commit

Permalink
cmd/link: check mmap error
Browse files Browse the repository at this point in the history
We already check mmap errors on some code paths, but we missed
one. Add error check there.

Change-Id: Ic0e9cb0eb03c805de40802cfc5d5500e3e065d99
Reviewed-on: https://go-review.googlesource.com/c/go/+/319290
Trust: Cherry Mui <[email protected]>
Run-TryBot: Cherry Mui <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
  • Loading branch information
cherrymui committed May 12, 2021
1 parent af0f8c1 commit e03383a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/cmd/link/internal/ld/asmb.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ func sizeExtRelocs(ctxt *Link, relsize uint32) {
}
}
filesz := ctxt.Out.Offset() + sz
ctxt.Out.Mmap(uint64(filesz))
err := ctxt.Out.Mmap(uint64(filesz))
if err != nil {
Exitf("mapping output file failed: %v", err)
}
}

// relocSectFn wraps the function writing relocations of a section
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func Main(arch *sys.Arch, theArch Arch) {
// Don't mmap if we're building for Wasm. Wasm file
// layout is very different so filesize is meaningless.
if err := ctxt.Out.Mmap(filesize); err != nil {
panic(err)
Exitf("mapping output file failed: %v", err)
}
}
// asmb will redirect symbols to the output file mmap, and relocations
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ld/outbuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (out *OutBuf) copyHeap() bool {
total := uint64(bufLen + heapLen)
if heapLen != 0 {
if err := out.Mmap(total); err != nil { // Mmap will copy out.heap over to out.buf
panic(err)
Exitf("mapping output file failed: %v", err)
}
}
return true
Expand Down

0 comments on commit e03383a

Please sign in to comment.