Skip to content

cmd/compile: "runtime: bad pointer in frame" in riscv64 with complier optimizations #51101

Closed
@piggynl

Description

@piggynl

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

$ go version
go version go1.17.6 linux/riscv64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="riscv64"
GOBIN=""
GOCACHE="/home/piggy/.cache/go-build"
GOENV="/home/piggy/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="riscv64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/piggy/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/piggy/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_riscv64"
GOVCS=""
GOVERSION="go1.17.6"
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-build2469834381=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Reproduce: (you should have Node.js and Yarn pre-installed)

$ uname -m
riscv64

$ # build esbuild
$ git clone https://github.com/evanw/esbuild.git
$ cd esbuild
$ CGO_ENABLED=0 go build ./cmd/esbuild -o esbuild
$ cd ..

$ # get input files for esbuild
$ git clone https://github.com/tridactyl/tridactyl.git
$ cd tridactyl
$ yarn upgrade esbuild@^0.14.21 # make yarn happy (esbuild added support for riscv64 in 0.14.21)
$ yarn install
$ ../esbuild/esbuild --bundle src/background.ts --outfile=/dev/null 2>&1 | tee buildlog.txt

What did you expect to see?

esbuild works as intended, like in amd64.

What did you see instead?

runtime: bad pointer in frame github.com/evanw/esbuild/internal/js_parser.(*parser).visitBinding at 0x3f9cc244b8: 0xc0
fatal error: invalid pointer found on stack

runtime stack:
runtime.throw({0x4c9114, 0x1e})
        runtime/panic.go:1198 +0x60 fp=0x3f9c185830 sp=0x3f9c185808 pc=0x4c6a8
runtime.adjustpointers(0x3f9cc24470, 0x3f9c185910, 0x3f9c185d10, {0x752c80, 0x77ae00})
        runtime/stack.go:617 +0x224 fp=0x3f9c185878 sp=0x3f9c185830 pc=0x69204
runtime.adjustframe(0x3f9c185c28, 0x3f9c185d10)
        runtime/stack.go:659 +0xf8 fp=0x3f9c185948 sp=0x3f9c185878 pc=0x69300
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x3f9c99cea0, 0x0, 0x0, 0x7fffffff, 0x4e2f50, 0x3f9c185d10, 0x0)
        runtime/traceback.go:350 +0x7e4 fp=0x3f9c185c80 sp=0x3f9c185948 pc=0x76604
runtime.copystack(0x3f9c99cea0, 0x10000)
        runtime/stack.go:918 +0x230 fp=0x3f9c185e30 sp=0x3f9c185c80 pc=0x69a28
runtime.newstack()
        runtime/stack.go:1097 +0x4b8 fp=0x3f9c185fd0 sp=0x3f9c185e30 pc=0x69fc0
runtime.morestack()
        runtime/asm_riscv64.s:202 +0x70 fp=0x3f9c185fd8 sp=0x3f9c185fd0 pc=0x80a68

goroutine 128 [copystack]:
runtime.growslice(0x478360, {0x3f9c9d8210, 0x2, 0x2}, 0x3)
        runtime/slice.go:162 +0x10 fp=0x3f9cc243a0 sp=0x3f9cc243a0 pc=0x676a8
github.com/evanw/esbuild/internal/js_parser.(*parser).recordDeclaredSymbol(...)
        github.com/evanw/esbuild/internal/js_parser/js_parser.go:8448
github.com/evanw/esbuild/internal/js_parser.(*parser).visitBinding(0x3f9c9f8800, {{0x564e00, 0x3f9c90d160}, {0x559}}, {0x3f9cc0e6a0})
        github.com/evanw/esbuild/internal/js_parser/js_parser.go:8463 +0x148 fp=0x3f9cc245f8 sp=0x3f9cc243a0 pc=0x2c57a8
github.com/evanw/esbuild/internal/js_parser.(*parser).visitArgs(0x3f9c9f8800, {0x3f9c912ff0, 0x1, 0x1}, {{0x3f9c90fb48, 0x1, 0x1}, 0x0, 0x0})
        github.com/evanw/esbuild/internal/js_parser/js_parser.go:10527 +0x238 fp=0x3f9cc247a0 sp=0x3f9cc245f8 pc=0x2d9970
... some frames omitted ...
github.com/evanw/esbuild/internal/bundler.parseFile({{0x5725c8, 0x3f9c00e380}, {0x3f9c0b6930, 0x3f9c00a180, 0x3f9c00a198, 0x3f9c01e1e0, 0x3}, {0x56ca80, 0x3f9c06b500}, 0x3f9c050360, ...})
        github.com/evanw/esbuild/internal/bundler/bundler.go:185 +0xce0 fp=0x3f9cc2bbe8 sp=0x3f9cc29910 pc=0x38d188
runtime.goexit()
        runtime/asm_riscv64.s:507 +0x4 fp=0x3f9cc2bbe8 sp=0x3f9cc2bbe8 pc=0x82904
created by github.com/evanw/esbuild/internal/bundler.(*scanner).maybeParseFile
        github.com/evanw/esbuild/internal/bundler/bundler.go:1189 +0x838

... and stack traces of other goroutines

The full output: http://fars.ee/4nkQ


I've tested the build options below. It seems the bug is caused by the optimizer?

Build Options Result
(default) esbuild crashes
-gcflags=all="-N" esbuild works fine
-gcflags=all="-l" esbuild works fine
-gcflags=all="-N -l" esbuild works fine

Also, I'm working on a minimal reproduce.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.arch-riscvIssues solely affecting the riscv64 architecture.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions