diff options
author | Cherry Mui <cherryyz@google.com> | 2021-05-11 22:40:41 -0400 |
---|---|---|
committer | Cherry Mui <cherryyz@google.com> | 2021-05-12 15:05:12 +0000 |
commit | e03383a2e233fc89958cff31642dff917d649378 (patch) | |
tree | 5e0af2d2b54a62738fed0bf9ec3f5acb570080b2 /src | |
parent | af0f8c149e8a4b237910fc7b41739bedc546473c (diff) | |
download | go-e03383a2e233fc89958cff31642dff917d649378.tar.gz go-e03383a2e233fc89958cff31642dff917d649378.zip |
cmd/link: check mmap error
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 <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/link/internal/ld/asmb.go | 5 | ||||
-rw-r--r-- | src/cmd/link/internal/ld/main.go | 2 | ||||
-rw-r--r-- | src/cmd/link/internal/ld/outbuf.go | 2 |
3 files changed, 6 insertions, 3 deletions
diff --git a/src/cmd/link/internal/ld/asmb.go b/src/cmd/link/internal/ld/asmb.go index 37546695556..d6ecb2895ba 100644 --- a/src/cmd/link/internal/ld/asmb.go +++ b/src/cmd/link/internal/ld/asmb.go @@ -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 diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go index adb39d06076..cba0e3d81fe 100644 --- a/src/cmd/link/internal/ld/main.go +++ b/src/cmd/link/internal/ld/main.go @@ -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 diff --git a/src/cmd/link/internal/ld/outbuf.go b/src/cmd/link/internal/ld/outbuf.go index 530836ef7cf..9d5e8854fea 100644 --- a/src/cmd/link/internal/ld/outbuf.go +++ b/src/cmd/link/internal/ld/outbuf.go @@ -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 |