Skip to content

runtime: vdso __kernel_clock_gettime not called on linux/arm64 #62309

Closed
@wkozaczuk

Description

@wkozaczuk

What version of Go are you using (go version)?

go version go1.17.7 linux/arm64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/home/wkozaczuk/.cache/go-build"
GOENV="/home/wkozaczuk/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/wkozaczuk/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/wkozaczuk/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/wkozaczuk/go/1.17.7/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/wkozaczuk/go/1.17.7/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.17.7"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2816176477=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Ran a simple httpserver:

package main

import (
	"io"
	"net/http"
	"runtime"
        "fmt"
	"os"
)

func hello(w http.ResponseWriter, r *http.Request) {
	hostname, err := os.Hostname()
        if( err == nil ) {
		io.WriteString(w, "Hello world from " + runtime.Version() + " at " + hostname)
        }
}

func main() {
	fmt.Printf("Go version: %s, listening on port 8000 ...\n", runtime.Version());
	http.HandleFunc("/", hello)
	http.ListenAndServe(":8000", nil)
}

What did you expect to see?

I expected Golang runtime to use VDSO calls instead of the clock_gettime syscalls.

What did you see instead?

I instead see the clock_gettime syscalls being made:

strace -F ./apps/golang-pie-httpserver/httpserver.so 2>&1 | grep clock_gettime
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=348917386}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=349885347}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=349931433}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=349964351}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=349996311}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350031937}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350066939}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350101107}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350136192}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350171319}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350206446}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350241239}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350276115}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350310700}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350344785}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350538794}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350574963}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=350804307}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=1359948, tv_nsec=356139845}) = 0
[pid 67110] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67110] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=356757665}) = 0
[pid 67110] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67110] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=356851711}) = 0
[pid 67110] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67110] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=357587954}) = 0
[pid 67111] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67111] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=357776754}) = 0
[pid 67111] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67111] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=357917177}) = 0
[pid 67111] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67111] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=358231983}) = 0
[pid 67111] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67111] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=358445535}) = 0
[pid 67111] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>
[pid 67111] <... clock_gettime resumed>{tv_sec=1359948, tv_nsec=358829344}) = 0
[pid 67112] clock_gettime(CLOCK_MONOTONIC,  <unfinished ...>

I believe there is a simple bug in vdso_linux_arm64.go where it uses wrong hash values (of __vdso_clock_gettime) instead of __kernel_clock_gettime.

The correct values should be 0xb0cd725, 0xdfa941fd

like in this code snippet:

var vdsoSymbolKeys = []vdsoSymbolKey{
//	{"__kernel_clock_gettime", 0xd35ec75, 0x6e43a318, &vdsoClockgettimeSym}, WRONG
	{"__kernel_clock_gettime", 0xb0cd725, 0xdfa941fd, &vdsoClockgettimeSym},
}

For comparison look at

{"__kernel_clock_gettime", 0xb0cd725, 0xdfa941fd, &vdsoClockgettimeSym},

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Linuxarch-arm64compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions