Skip to content

Commit

Permalink
cmd/compile/internal/base: use runtime.KeepAlive in MapFile
Browse files Browse the repository at this point in the history
Go 1.17 will be used instead of Go 1.4 as minimum required version for
bootstrap, so runtime.KeepAlive introduced in Go 1.7 can be used in
cmd/compile.

For #44505

Change-Id: I96bd6619c4476e36ee1d93ca049da622a3a78f97
Reviewed-on: https://go-review.googlesource.com/c/go/+/427114
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
  • Loading branch information
tklauser authored and gopherbot committed Sep 2, 2022
1 parent 54c7bc9 commit 274528e
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/cmd/compile/internal/base/mapfile_mmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package base
import (
"os"
"reflect"
"runtime"
"syscall"
"unsafe"
)
Expand All @@ -27,7 +28,7 @@ func MapFile(f *os.File, offset, length int64) (string, error) {
length += x

buf, err := syscall.Mmap(int(f.Fd()), offset, int(length), syscall.PROT_READ, syscall.MAP_SHARED)
keepAlive(f)
runtime.KeepAlive(f)
if err != nil {
return "", err
}
Expand All @@ -43,7 +44,3 @@ func MapFile(f *os.File, offset, length int64) (string, error) {

return res, nil
}

// keepAlive is a reimplementation of runtime.KeepAlive, which wasn't
// added until Go 1.7, whereas we need to compile with Go 1.4.
var keepAlive = func(interface{}) {}

0 comments on commit 274528e

Please sign in to comment.