golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.07k stars 17.68k forks source link

gollvm: reference to undefined identifier 'syscall.RUSAGE_SELF', while build grpc related package #41382

Closed advancedwebdeveloper closed 4 years ago

advancedwebdeveloper commented 4 years ago

Hi. I was building internals of linkerd and caught a bug, during the build phase, for a protobuf/grpc related package.

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

$ go version

go version go1.15rc2 gollvm LLVM 12.0.0git linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env

> GO111MODULE="" > GOARCH="amd64" > GOBIN="" > GOCACHE="/home/oceanfish81/.cache/go-build" > GOENV="/home/oceanfish81/.config/go/env" > GOEXE="" > GOFLAGS="" > GOHOSTARCH="amd64" > GOHOSTOS="linux" > GOINSECURE="" > GOMODCACHE="/home/oceanfish81/go/pkg/mod" > GONOPROXY="" > GONOSUMDB="" > GOOS="linux" > GOPATH="/home/oceanfish81/go" > GOPRIVATE="" > GOPROXY="https://proxy.golang.org,direct" > GOROOT="/usr/local" > GOSUMDB="sum.golang.org" > GOTMPDIR="" > GOTOOLDIR="/usr/local/tools" > GCCGO="/usr/local/bin/llvm-goc" > AR="ar" > CC="/usr/bin/clang" > CXX="/usr/bin/clang++" > CGO_ENABLED="1" > GOMOD="/home/oceanfish81/linkerd2/go.mod" > CGO_CFLAGS="-g -O2" > CGO_CPPFLAGS="" > CGO_CXXFLAGS="-g -O2" > CGO_FFLAGS="-g -O2" > CGO_LDFLAGS="-g -O2" > PKG_CONFIG="pkg-config" > GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build000799681=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

What did you do?

~/linkerd2/pkg/tap$ go build

What did you expect to see?

Required sources should be pulled and all packages should be compiled, using llvm-goc, as expected.

What did you see instead?

go: downloading github.com/sirupsen/logrus v1.6.0 go: downloading k8s.io/apimachinery v0.17.4 go: downloading k8s.io/client-go v0.17.4 go: downloading github.com/servicemeshinterface/smi-sdk-go v0.3.0 go: downloading k8s.io/kube-aggregator v0.17.4 go: downloading github.com/prometheus/client_golang v1.2.1 go: downloading k8s.io/api v0.17.4 go: downloading github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 go: downloading github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 go: downloading k8s.io/apiextensions-apiserver v0.17.4 go: downloading github.com/prometheus/procfs v0.0.5 go: downloading github.com/prometheus/common v0.7.0 go: downloading github.com/Azure/go-autorest/autorest v0.9.0 go: downloading k8s.io/utils v0.0.0-20191114184206-e782cd3c129f go: downloading github.com/gogo/protobuf v1.3.0 go: downloading github.com/googleapis/gnostic v0.3.1 go: downloading github.com/Azure/go-autorest/tracing v0.5.0 go: downloading github.com/Azure/go-autorest/logger v0.1.0 go: downloading github.com/gophercloud/gophercloud v0.1.0 go: downloading github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96 go: downloading github.com/Azure/go-autorest/autorest/adal v0.5.0 go: downloading k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a go: downloading github.com/Azure/go-autorest/autorest/date v0.1.0 go: downloading github.com/evanphx/json-patch v4.5.0+incompatible go: downloading github.com/cespare/xxhash v1.1.0 go: downloading github.com/cespare/xxhash/v2 v2.1.0 go: downloading github.com/dgrijalva/jwt-go v3.2.0+incompatible go: downloading github.com/json-iterator/go v1.1.8 go: downloading github.com/pkg/errors v0.9.1

google.golang.org/grpc/internal/syscall

../../../go/pkg/mod/google.golang.org/grpc@v1.29.1/internal/syscall/syscall_linux.go:50:28: error: reference to undefined identifier 'syscall.RUSAGE_SELF'

It seems that an error is related to func GetRusage() (rusage *Rusage) .

Ivan

ianlancetaylor commented 4 years ago

CC @thanm @cherrymui

In gccgo syscall.RUSAGE_SELF is defined in the sysinfo.go file created by mksysinfo.sh. Not sure what is happening for GoLLVM.

thanm commented 4 years ago

I can't reproduce this -- works ok for me.

As Ian mentions, syscall.RUSAGE_SELF is auto-generated as part of the build. If you examine your gollvm build area, you should see it here:

$ cd <build_area_root>
$ fgrep RUSAGE_SELF tools/gollvm/libgo/sysinfo.go
const _RUSAGE_SELF = 0
const RUSAGE_SELF = _RUSAGE_SELF
$

If not, it sounds as though something went haywire with your build.

advancedwebdeveloper commented 4 years ago

@thanm , I will check that tomorrow. Thanks for the tip

advancedwebdeveloper commented 4 years ago

I can't reproduce this -- works ok for me.

As Ian mentions, syscall.RUSAGE_SELF is auto-generated as part of the build. If you examine your gollvm build area, you should see it here:

$ cd <build_area_root>
$ fgrep RUSAGE_SELF tools/gollvm/libgo/sysinfo.go
const _RUSAGE_SELF = 0
const RUSAGE_SELF = _RUSAGE_SELF
$

If not, it sounds as though something went haywire with your build.

@thanm , some related files are generated/built (see attachments) - but I don't see _RUSAGE_SELF inside sysinfo.go. But I do see it inside sysinfo.macros.txt .

@thanm, @cherrymui : what should I check/investigate, during gollvm's rebuild process, to find out why it's not auto-generating properly ?

gollvm_build.zip

Ivan

advancedwebdeveloper commented 4 years ago

I was able to compile by adding

const _RUSAGE_SELF = 0 const RUSAGE_SELF = _RUSAGE_SELF

to the source file, under a local package visibility. That's a bypass - so the original cause/problem persists.

Ivan

thanm commented 4 years ago

Thanks for posting the zip file with build artifacts. I can see the problem now; I'll send a patch shortly to address this.

gopherbot commented 4 years ago

Change https://golang.org/cl/254941 mentions this issue: libgo: additional type/const reference in sysinfo.c

advancedwebdeveloper commented 4 years ago

Thanks for posting the zip file with build artifacts. I can see the problem now; I'll send a patch shortly to address this.

Finally. Looking forward to test it/rebuild llvm

thanm commented 4 years ago

This should be fixed now at head. Please reopen if not.