Closed drew-richardson closed 2 years ago
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.
I have the same issue on darwin arm64.
@WorkerYifei you have the same kind of problem, ok, but could you provide more information about your context?
To help, it's important to provide more and new information when you comment on an issue.
@ldez Sorry for the late reply.
- Are you using the Docker image, an official binary, a custom binary?
I'm using the 1.45.2-darwin-arm64
official binary on my Mac mini M1.
- which version of Go are you using?
go1.17.7
- what is your configuration?
N/A
- can you provide a reproducible example?
I think it's not related to my code. I can't even run the version
command.
- have you tried with the go-critic binary?
I'm not familiar with go-critic
,but I think it works fine on my mac. See the snapshot below:
I hope it helps.
By the way, It works good on my Mac with Intel chip when environment and configuration not changed.
I'm seeing the same issue with Go 1.17.6 and golangci-lint 1.45.2 and 1.45.0 on M1 MBP
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.22()
github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x494
make: *** [lint] Error 2
Works fine if I downgrade to 1.44.2
We are facing same issue but on CircleCI with Linux based Dockerfile. I played around and downgrading to 1.45.0 seem to help. Copying here the setup step from CircleCI, maybe it helps:
Build-agent version 1.0.117314-02cfb3b4 (2022-03-29T08:17:31+0000)
System information:
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: xfs
Cgroup Driver: cgroupfs
Cgroup Version: 1
Kernel Version: 5.13.0-1017-aws
Operating System: Ubuntu 20.04.4 LTS
OSType: linux
Architecture: x86_64
Starting container cimg/go:1.18
...
Having same problem here, look at this pipeline:
https://github.com/coincode-live/prototype/runs/5831984242?check_suite_focus=true
@mortezaalizadeh form your logs:
Operating System Ubuntu 20.04.4 LTS Requested golangci-lint 'v1.44', using 'v1.44.2', calculation took 205ms Installing golangci-lint v1.44.2...
This issue is about 1.45.x on Darwin arm64.
Your problem is related to something else, it's a problem with go-critic in some conditions https://github.com/go-critic/go-critic/issues/1218
Any update? (not quite same as #2374)
On arm (m1) with golang 1.17.9 1.44.2 works, 1.45.2 doesn't:
$ docker build -f Dockerfile.lint_bug .
[+] Building 13.7s (7/7) FINISHED
=> [internal] load build definition from Dockerfile.lint_bug 0.0s
=> => transferring dockerfile: 411B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/golang:1.17.9 2.3s
=> [auth] library/golang:pull token for registry-1.docker.io 0.0s
=> CACHED [1/3] FROM docker.io/library/golang:1.17.9@sha256:c1bf2101f7e1e0b08ce8f792735a81cd71b9d81cbcdceef2382140694f1ffbaf 0.0s
=> [2/3] RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2 6.0s
=> ERROR [3/3] RUN golangci-lint version 5.3s
------
> [3/3] RUN golangci-lint version:
#7 5.277 panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
#7 5.277
#7 5.277 goroutine 1 [running]:
#7 5.277 github.com/go-critic/go-critic/checkers.init.22()
#7 5.277 github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x488
------
executor failed running [/bin/sh -c golangci-lint version]: exit code: 2
With this Dockerfile:
FROM golang:1.17.9
# golangci-lint
# See https://github.com/golangci/golangci-lint/issues/2374
# Use 1.44.2 which works on arm while 1.45.2 doesn't... somehow
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
RUN golangci-lint version
Could you try with the binary of go-critic?
What do you mean? (or how?)
I'm using the https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh which is a binary release of everything bundled together I believe?
if I install from source it does work
go1.17.9 install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
~/go/bin/golangci-lint version
golangci-lint has version v1.45.2 built from (unknown, mod sum: "h1:9I3PzkvscJkFAQpTQi5Ga0V4qWdJERajX1UZ7QqkW+I=") on (unknown)
but I'm trying to follow "don't install from source" from https://golangci-lint.run/usage/install/#local-installation (though this is really not local but to create a build image)
The problem seems related to go-critic (see your logs), then can you try with the go-critic binary? https://github.com/go-critic/go-critic/releases/tag/v0.6.3
The problem seems related to go-critic (see your logs), then can you try with the go-critic binary? https://github.com/go-critic/go-critic/releases/tag/v0.6.3
I am not familiar with golangci internals but doing this
FROM golang:1.17.9
RUN go install github.com/go-critic/go-critic/cmd/gocritic@v0.6.3
RUN gocritic version
# golangci-lint
# See https://github.com/golangci/golangci-lint/issues/2673
# Use 1.44.2 which works on arm while 1.45.2 doesn't... somehow
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
RUN golangci-lint version
doesn't help; it still uses 0.6.2
note that anyone can reproduce this even without arm machine, did you try?
docker buildx build --platform linux/arm64 -f Dockerfile.lint_bug .
I'm asking you to run the go-critic binary in your container.
@ldemailly I read again your comments, and you are using go1.17 to compile (go get
) golangci-lint, this will never work.
I explained that in https://github.com/golangci/golangci-lint/issues/2649#issue-1170906525
I will flag your comment as off-topic.
Again, I'm not compiling golangci-lint; I'm using the binary install script per instructions (also to answer you other question, gocritic alone is working fine)
How is it off topic to flag that the install script doesn't work with arm?
also your link is about running a 1.17 build along 1.18 and 1.18 support. I'm only using 1.17.9, no 1.18 involved
Again, I'm not compiling golangci-lint; I'm using the binary install script per instructions
Sorry, it's late for me, I misread.
Can you run the go-critic binary in your container?
go-critic seems to have a problem since v0.6.2, the binaries are missing. So can you compile go-critic (v0.6.2) with go1.18 with your arch, and try it.
$ docker run --platform linux/arm64 -ti -v `pwd`:/build golang:1.17.9 /bin/bash
root@d4548d5f6d6c:/go# cd /build/
root@d4548d5f6d6c:/build# go install github.com/go-critic/go-critic/cmd/gocritic@v0.6.3
go: downloading github.com/go-critic/go-critic v0.6.3
go: downloading github.com/go-toolsmith/pkgload v1.0.2-0.20220101231613-e814995d17c5
go: downloading golang.org/x/tools v0.1.9-0.20211228192929-ee1ca4ffc4da
go: downloading github.com/go-toolsmith/astfmt v1.0.0
go: downloading github.com/go-toolsmith/astcast v1.0.0
go: downloading github.com/go-toolsmith/astcopy v1.0.0
go: downloading github.com/go-toolsmith/astequal v1.0.1
go: downloading github.com/go-toolsmith/astp v1.0.0
go: downloading github.com/go-toolsmith/strparse v1.0.0
go: downloading github.com/go-toolsmith/typep v1.0.2
go: downloading github.com/quasilyte/go-ruleguard v0.3.16-0.20220213074421-6aa060fab41a
go: downloading github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95
go: downloading github.com/quasilyte/gogrep v0.0.0-20220120141003-628d8b3623b5
go: downloading github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567
go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
go: downloading golang.org/x/mod v0.5.1
go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
root@d4548d5f6d6c:/build# gocritic check ./fnet
./fnet/network.go:469:9: elseif: can replace 'else {if cond {}}' with 'else if cond {}'
./fnet/network.go:210:2: ifElseChain: rewrite if-else to switch statement
./fnet/network.go:508:2: ifElseChain: rewrite if-else to switch statement
root@d4548d5f6d6c:/build# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2
golangci/golangci-lint info checking GitHub for tag 'v1.45.2'
golangci/golangci-lint info found version: 1.45.2 for v1.45.2/linux/arm64
golangci/golangci-lint info installed /go/bin/golangci-lint
root@d4548d5f6d6c:/build# golangci-lint version
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.22()
github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x488
So gocritic by itself is fine, and I don't want to switch to 1.18 yet
You have to compile go-critic with go1.18, because golangci-lint is compiled with go1.18.
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
works fine btw, it's just the binary distribution which isn't working
if you mean to say that golangci-lint 1.45. binaries are not supported / meant to work with go1.17. probably the installer should say so and not install a binary that doesn't work (or consider using 1.17.9 to build it? or dual build with 1.17 for 1.17 users and 1.18 for 1.18 users and detect the go version in ?)
or at least mention it in install docs and the release notes? ("go1.18 support" isn't the same as "only >= 1.18 supported in binary releases" (on arm - it's odd it's only a problem on arm though))
maybe it's a bug of golang to not be backward compatible or arm only bug?
if you mean to say that golangci-lint 1.45. binaries are not supported / meant to work with go1.17.
I'm able to use golangci-lint 1.45.* binaries with go1.17 on linux/amd64 without any problem.
My recommendation: use our official Docker image, and set 1.17 in your configuration:
run:
go: '1.17'
https://golangci-lint.run/usage/configuration/#run-configuration
I'm able to use golangci-lint 1.45.* binaries with go1.17 on linux/amd64 without any problem.
try linux/arm64
and you'll get the error above ("on arm", "--platform linux/arm64", ...)
for clarity and others stepping on this problem maybe rename this Issue as
"go1.17 linux/arm64, binary distribution (install.sh) of golangci-lint >= 1.45 fails with panic can't load fmt"
repro (as above, see docker file and command line or: [edit: that's not a very good example as it also fails with 1.44.2 because no go is installed] - so only see Dockerfile above]
$ docker run --platform linux/arm64 -ti ubuntu:focal /bin/bash
root@f3af5e9bc2ca:/# apt-get update && apt-get install curl
[...]
root@f3af5e9bc2ca:/# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s
golangci/golangci-lint info checking GitHub for latest tag
golangci/golangci-lint info found version: 1.45.2 for v1.45.2/linux/arm64
golangci/golangci-lint info installed ./bin/golangci-lint
root@f3af5e9bc2ca:/# bin/golangci-lint
panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.22()
github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x488
Can you try to compile go-critic on arm64 with go1.18, and run the resulting binary with go1.17?
FROM golang:1.18.1 as build
RUN go install github.com/go-critic/go-critic/cmd/gocritic@v0.6.3
FROM golang:1.17.9
COPY --from=build /go/bin/gocritic /usr/bin/gocritic
RUN gocritic version
COPY . test
WORKDIR test
RUN gocritic check ./...
works fine so it's not go-critic...
but replacing with
FROM golang:1.18.1 as build
RUN go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
RUN golangci-lint version
FROM golang:1.17.9
COPY --from=build /go/bin/golangci-lint /usr/bin/golangci-lint
RUN golangci-lint version
also works so it's not go 1.18 issue either it seems it's just that binary for arm is build wrong somehow? (how was it built?)
I noticed the non working one was statically linked, so tried
FROM golang:1.18.0 as build
WORKDIR /build
RUN git clone https://github.com/golangci/golangci-lint
WORKDIR /build/golangci-lint
RUN git checkout v1.45.2
RUN CGO_ENABLED=0 go build -a -ldflags="-s" ./cmd/golangci-lint
RUN ./golangci-lint version
FROM golang:1.17.9
COPY --from=build /build/golangci-lint/golangci-lint /usr/bin/golangci-lint-ok
RUN golangci-lint-ok version
but that still works fine only the downloaded binary version seems wrong - how is it built? maybe just needs a rebuild?
Same sizes
root@411df4293551:/go# ls -l /usr/bin/gola*
-rwxr-xr-x 1 root root 22020096 Apr 18 00:29 /usr/bin/golangci-lint-ok
root@411df4293551:/go# ls -l /go/bin/golangci-lint
-rwxr-xr-x 1 root root 22020096 Apr 18 00:29 /go/bin/golangci-lint
Same type:
root@5166303f68ff:/go# file /usr/bin/golangci-lint-ok
/usr/bin/golangci-lint-ok: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=OQBaBGSZtjVeeTZPsGNG/RgzR11pjJ_DMcmU9nmJb/tyjYyVrudHH6uw1lUoax/hUc2RAsRdGPW-FthTam6, stripped
root@5166303f68ff:/go# file /go/bin/golangci-lint
/go/bin/golangci-lint: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, Go BuildID=Fnqw9MbpEiPUd8Sqqxyf/hHoGkr7qVg18UvZu1M4J/gvFh7P10kiILuf5xFYDn/NurFFBAcKC9Z_e2GkmVF, stripped
ping? maybe just a matter of rebuilding with latest gopackager?
We will not rebuild, we consider the binaries as immutables for security reasons. So we will see with the next release. I don't have ETA.
thanks, I did mean bump the patch level, not change released artifacts
Still broken for me on golangci-lint 1.46.2, with go 1.17.9. Go 1.18.2 works fine.
i have the same question in 1.18, as follow:
$ golangci-lint run -v --config config.yaml report
INFO [linters context/goanalysis] analysis skipped: errors in package: [/Users/bytedance/Documents/GoCode/ScmKx/report/report.go:5:2: could not import bytes (/Users/bytedance/Documents/GoSDK/go1.18/src/bytes/buffer.go:10:2: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool)))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:6:2: could not import encoding/json (/Users/bytedance/Documents/GoSDK/go1.18/src/encoding/json/decode.go:11:2: could not import encoding (-: could not load export data: cannot import "encoding" (unknown iexport format version 2), export data is newer version - update tool)) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:7:2: could not import io/ioutil (/Users/bytedance/Documents/GoSDK/go1.18/src/io/ioutil/ioutil.go:14:2: could not import io (/Users/bytedance/Documents/GoSDK/go1.18/src/io/io.go:16:2: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool))))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:8:2: could not import log (/Users/bytedance/Documents/GoSDK/go1.18/src/log/log.go:18:2: could not import fmt (/Users/bytedance/Documents/GoSDK/go1.18/src/fmt/errors.go:7:8: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool))))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:9:2: could not import net/http (/Users/bytedance/Documents/GoSDK/go1.18/src/net/http/client.go:13:2: could not import context (/Users/bytedance/Documents/GoSDK/go1.18/src/context/context.go:51:2: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool))))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:10:2: could not import os (/Users/bytedance/Documents/GoSDK/go1.18/src/os/dir.go:8:2: could not import io/fs (/Users/bytedance/Documents/GoSDK/go1.18/src/io/fs/fs.go:11:2: could not import internal/oserror (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/oserror/errors.go:10:8: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool)))))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:11:2: could not import strconv (/Users/bytedance/Documents/GoSDK/go1.18/src/strconv/atof.go:13:8: could not import math (/Users/bytedance/Documents/GoSDK/go1.18/src/math/exp_amd64.go:9:8: could not import internal/cpu (-: could not load export data: cannot import "internal/cpu" (unknown iexport format version 2), export data is newer version - update tool))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:12:2: could not import time (/Users/bytedance/Documents/GoSDK/go1.18/src/time/format.go:7:8: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool)))) /Users/bytedance/Documents/GoCode/ScmKx/report/report.go:14:2: could not import code.byted.org/pdi-qa/ScmKx/util/git (/Users/bytedance/Documents/GoCode/ScmKx/util/git/file.go:4:2: could not import errors (/Users/bytedance/Documents/GoSDK/go1.18/src/errors/wrap.go:8:2: could not import internal/reflectlite (/Users/bytedance/Documents/GoSDK/go1.18/src/internal/reflectlite/swapper.go:8:2: could not import internal/goarch (-: could not load export data: cannot import "internal/goarch" (unknown iexport format version 2), export data is newer version - update tool))))]
how deal this?
I had to work around a similar problem today, solution documented in https://github.com/golangci/golangci-lint-action/issues/442#issuecomment-1203786890.
tl;dr build golangci-lint
from source using the target Go version
I've found some success in explicitly setting the GOROOT
value. While go env GOROOT
reports /usr/local/go
already, setting this explicitly in my Dockerfile
(or otherwise for execution of golangci-lint
) this allows golangci-lint
to run.
Small example case to reproduce this (on an M1 arm64 host):
FROM golang:1.17.8-alpine
RUN apk add --no-cache \
curl
ENV GOLANGCI_LINT_VERSION=v1.45.2
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
RUN golangci-lint version
ENTRYPOINT ["golangci-lint"]
Gives:
... snip ...
=> ERROR [4/4] RUN golangci-lint version 6.1s
------
> [4/4] RUN golangci-lint version:
#7 5.908 panic: load embedded ruleguard rules: rules/rules.go:13: can't load fmt
#7 5.908
#7 5.908 goroutine 1 [running]:
#7 5.908 github.com/go-critic/go-critic/checkers.init.22()
#7 5.908 github.com/go-critic/go-critic@v0.6.2/checkers/embedded_rules.go:46 +0x488
------
executor failed running [/bin/sh -c golangci-lint version]: exit code: 2
However by adding ENV GOROOT /usr/local/go
before invoking golangci-lint
, the issue is gone:
FROM golang:1.17.8-alpine
RUN apk add --no-cache \
curl
ENV GOLANGCI_LINT_VERSION=v1.45.2
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
ENV GOROOT /usr/local/go
RUN golangci-lint version
ENTRYPOINT ["golangci-lint"]
... snip ...
=> CACHED [3/4] RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.45.2 0.0s
=> [4/4] RUN golangci-lint version 3.6s
=> exporting to image 0.1s
=> => exporting layers 0.1s
=> => writing image sha256:aaeb4c94c1585ece8b542cdd9a13252f4dd31d4222c443c9b66e4a11cc120fd1
... snip ...
Checking the version
directly, it reports golangci-lint has version 1.45.2 built from 8bdc4d3f on 2022-03-24T11:51:26Z
closed in favor of #3107
Welcome
Description of the problem
golangci-lint version 1.45.0 on linux arm64/aarch64 with go1.17.8 fails with this error
golangci-lint version 1.45.0 works just fine on amd64 with go1.17.8, as well as arm64 with go1.18
Here's the whole process
Version of golangci-lint
Configuration file
Go environment
Verbose output of running
Code example or link to a public repository