]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: check mmap error
authorCherry Mui <cherryyz@google.com>
Wed, 12 May 2021 02:40:41 +0000 (22:40 -0400)
committerCherry Mui <cherryyz@google.com>
Wed, 12 May 2021 15:05:12 +0000 (15:05 +0000)
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>
src/cmd/link/internal/ld/asmb.go
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/ld/outbuf.go

index 375466955568689d4b1e8a48ffcae28f0c011742..d6ecb2895bad329671fa6c7aa3f640115b0af36f 100644 (file)
@@ -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
index adb39d06076b87d83734480d8ec3b638efd195be..cba0e3d81feaea6fafcba964c200b50d96e6d714 100644 (file)
@@ -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
index 530836ef7cf292fb7849089be5d501cfb574d3e6..9d5e8854fea65418c75c30717f865f80cfbd03bc 100644 (file)
@@ -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