1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:24:42 -07:00

cmd/compile/internal/base: use runtime.KeepAlive in MapFile

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>
This commit is contained in:
Tobias Klauser 2022-08-31 19:05:55 +02:00 committed by Gopher Robot
parent 54c7bc9cff
commit 274528eca1

View File

@ -10,6 +10,7 @@ package base
import ( import (
"os" "os"
"reflect" "reflect"
"runtime"
"syscall" "syscall"
"unsafe" "unsafe"
) )
@ -27,7 +28,7 @@ func MapFile(f *os.File, offset, length int64) (string, error) {
length += x length += x
buf, err := syscall.Mmap(int(f.Fd()), offset, int(length), syscall.PROT_READ, syscall.MAP_SHARED) buf, err := syscall.Mmap(int(f.Fd()), offset, int(length), syscall.PROT_READ, syscall.MAP_SHARED)
keepAlive(f) runtime.KeepAlive(f)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -43,7 +44,3 @@ func MapFile(f *os.File, offset, length int64) (string, error) {
return res, nil 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{}) {}