Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: unable to compile a program on arm64 with 1.8 that compiles/runs fine on 1.7.5 #19137

Closed
jolan opened this issue Feb 17, 2017 · 17 comments

Comments

Projects
None yet
6 participants
@jolan
Copy link

commented Feb 17, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8 linux/arm64

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

GOARCH="arm64"
GOBIN=""
GOEXE=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jolan/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_arm64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build063485784=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

git clone https://github.com/decred/dcrd $GOPATH/src/github.com/decred/dcrd
cd $GOPATH/src/github.com/decred/dcrd
glide install
go install $(glide nv)

What did you expect to see?

No compile errors (works with go 1.7.5)

What did you see instead?

$ go install $(glide nv)
# github.com/decred/dcrd/blockchain/chaingen
blockchain/chaingen/generator.go:1861: offset out of range: 974
01460 (/home/jolan/go/src/github.com/decred/dcrd/blockchain/chaingen/generator.go:1595) MOVW    R2, ""..autotmp_529-146(SP)
# github.com/decred/dcrd
./version.go:74: offset out of range: 4302
16640 (/home/jolan/go/src/github.com/decred/dcrd/mining.go:2133)        MOVW   R1, ""..autotmp_2903-434(SP)

@josharian josharian changed the title unable to compile a program on arm64 with 1.8 that compiles/runs fine on 1.7.5 cmd/compile: unable to compile a program on arm64 with 1.8 that compiles/runs fine on 1.7.5 Feb 17, 2017

@josharian

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

@josharian josharian added this to the Go1.8.1 milestone Feb 17, 2017

@karalabe

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

This error is happening on our systems too: https://travis-ci.org/ethereum/go-ethereum/jobs/202566418#L2526

Note, previously we used Go 1.8 RC3 and that worked flawlessly.

@karalabe

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

Here's a repro for Ethereum on Ubuntu. It needs ARM64 C compilers so it may be a bit more involved, but figured a proper bug report should have the repro nontheless.

First up if you don't have the C compilers, install them:

$ sudo apt-get update
$ sudo apt-get install gcc-5-aarch64-linux-gnu g++-5-aarch64-linux-gnu libc6-dev-arm64-cross

The you can check out the source and watch it fail:

$ git clone https://github.com/ethereum/go-ethereum $GOPATH/src/github.com/ethereum/go-ethereum
$ cd $GOPATH/src/github.com/ethereum/go-ethereum/contracts/chequebook
$ CGO_ENABLED=1 GOARCH=arm64 CC=aarch64-linux-gnu-gcc-5 go build -v

[...]
# github.com/ethereum/go-ethereum/contracts/chequebook
./cheque.go:643: offset out of range: 364
00508 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:470)	MOVD	"".beneficiary+36(FP), R1
./cheque.go:643: offset out of range: 356
00512 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:470)	MOVD	"".beneficiary+28(FP), R2
./cheque.go:643: offset out of range: 564
00148 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:591)	MOVD	"".beneficiary+44(FP), R1
./cheque.go:643: offset out of range: 556
00152 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:591)	MOVD	"".beneficiary+36(FP), R2
./cheque.go:643: offset out of range: 556
00576 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:606)	MOVD	"".beneficiary+36(FP), R1
./cheque.go:643: offset out of range: 564
00580 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:606)	MOVD	"".beneficiary+44(FP), R2
./cheque.go:643: offset out of range: 564
01676 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:592)	MOVD	"".beneficiary+44(FP), R0
./cheque.go:643: offset out of range: 556
01680 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:592)	MOVD	"".beneficiary+36(FP), R1
$ go version
go version go1.8 linux/amd64

@cherrymui cherrymui self-assigned this Feb 17, 2017

@cherrymui

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

I think I know what's the problem, at least for the original post. It's Zero/Move lowering to unaligned stores. Will send a fix.

@cherrymui

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

No, the Zero/Move rules are ok. It is the folding rules that have bad interaction with them.

@gopherbot

This comment has been minimized.

Copy link

commented Feb 17, 2017

CL https://golang.org/cl/37145 mentions this issue.

@cherrymui

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

With CL https://go-review.googlesource.com/c/37145/, @jolan's code can be built successfully.
@karalabe, could you try the patch? Right now I don't have a C cross-compiler on hand.

@karalabe

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

@gopherbot gopherbot closed this in 3557d54 Feb 17, 2017

@cherrymui

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

reopen for cherry-pick to Go 1.8 release branch.

@cherrymui cherrymui reopened this Feb 17, 2017

@gopherbot

This comment has been minimized.

Copy link

commented Feb 17, 2017

CL https://golang.org/cl/37214 mentions this issue.

@karalabe

This comment has been minimized.

Copy link
Contributor

commented Feb 17, 2017

@cherrymui I cherry picked https://go-review.googlesource.com/37145 on top of the Go 1.8 release, rebuilt and tried compiling my code. It still fails with the exact same errors as reported in my posts above.

@karalabe

This comment has been minimized.

Copy link
Contributor

commented Feb 18, 2017

@cherrymui Hey, so we've merged in a commit to allow building our code (at least this failing part) without CGO too, relying on a fallback package. It still exhibits the same error so you can try it without a C compiler too.

$ git clone https://github.com/ethereum/go-ethereum $GOPATH/src/github.com/ethereum/go-ethereum
$ go get golang.org/x/net/context
$ cd $GOPATH/src/github.com/ethereum/go-ethereum/contracts/chequebook
$ GOARCH=arm64 go build --tags=nocgo -v

[...]
# github.com/ethereum/go-ethereum/contracts/chequebook
./cheque.go:643: offset out of range: 364
00508 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:470)	MOVD	"".beneficiary+36(FP), R1
./cheque.go:643: offset out of range: 356
00512 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:470)	MOVD	"".beneficiary+28(FP), R2
./cheque.go:643: offset out of range: 564
00148 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:591)	MOVD	"".beneficiary+44(FP), R1
./cheque.go:643: offset out of range: 556
00152 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:591)	MOVD	"".beneficiary+36(FP), R2
./cheque.go:643: offset out of range: 556
00576 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:606)	MOVD	"".beneficiary+36(FP), R1
./cheque.go:643: offset out of range: 564
00580 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:606)	MOVD	"".beneficiary+44(FP), R2
./cheque.go:643: offset out of range: 564
01676 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:592)	MOVD	"".beneficiary+44(FP), R0
./cheque.go:643: offset out of range: 556
01680 (/tmp/src/github.com/ethereum/go-ethereum/contracts/chequebook/cheque.go:592)	MOVD	"".beneficiary+36(FP), R1
@cherrymui

This comment has been minimized.

Copy link
Contributor

commented Feb 18, 2017

@karalabe thanks. Yeah, I found the problem. It's a different problem. Will have a fix later today.

@gopherbot

This comment has been minimized.

Copy link

commented Feb 19, 2017

CL https://golang.org/cl/37251 mentions this issue.

@gopherbot gopherbot closed this in 6464e5d Feb 21, 2017

@cherrymui

This comment has been minimized.

Copy link
Contributor

commented Feb 21, 2017

reopen for fixing Go 1.8.

@cherrymui cherrymui reopened this Feb 21, 2017

gopherbot pushed a commit that referenced this issue Mar 3, 2017

[release-branch.go1.8] cmd/compile: check both syms when folding addr…
…ess into load/store on ARM64

The rules for folding addresses into load/stores checks sym1 is
not on stack (because the stack offset is not known at that point).
But sym1 could be nil, which invalidates the check. Check merged
sym instead.

Fixes #19137.

Change-Id: I8574da22ced1216bb5850403d8f08ec60a8d1005
Reviewed-on: https://go-review.googlesource.com/37145
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
(cherry picked from commit 3557d54)
Reviewed-on: https://go-review.googlesource.com/37214
@gopherbot

This comment has been minimized.

Copy link

commented Mar 3, 2017

CL https://golang.org/cl/37719 mentions this issue.

gopherbot pushed a commit that referenced this issue Mar 3, 2017

[release-branch.go1.8] cmd/compile: do not fold offset into load/stor…
…e for args on ARM64

Args may be not at 8-byte aligned offset to SP. When the stack
frame is large, folding the offset of args may cause large
unaligned offsets that does not fit in a machine instruction on
ARM64. Therefore disable folding offsets for args.

This has small performance impact (see below). A better fix would
be letting the assembler backend fix up the offset by loading it
into a register if it doesn't fit into an instruction. And the
compiler can simply generate large load/stores with offset. Since
in most of the cases the offset is aligned or the stack frame is
small, it can fit in an instruction and no fixup is needed. But
this is too complicated for Go 1.8.

name                     old time/op    new time/op    delta
BinaryTree17-8              8.30s ± 0%     8.31s ± 0%    ~     (p=0.579 n=10+10)
Fannkuch11-8                6.14s ± 0%     6.18s ± 0%  +0.53%  (p=0.000 n=9+10)
FmtFprintfEmpty-8           117ns ± 0%     117ns ± 0%    ~     (all equal)
FmtFprintfString-8          196ns ± 0%     197ns ± 0%  +0.72%  (p=0.000 n=10+10)
FmtFprintfInt-8             204ns ± 0%     205ns ± 0%  +0.49%  (p=0.000 n=9+10)
FmtFprintfIntInt-8          302ns ± 0%     307ns ± 1%  +1.46%  (p=0.000 n=10+10)
FmtFprintfPrefixedInt-8     329ns ± 2%     326ns ± 0%    ~     (p=0.083 n=10+10)
FmtFprintfFloat-8           540ns ± 0%     542ns ± 0%  +0.46%  (p=0.000 n=8+7)
FmtManyArgs-8              1.20µs ± 1%    1.19µs ± 1%  -1.02%  (p=0.000 n=10+10)
GobDecode-8                17.3ms ± 1%    17.8ms ± 0%  +2.75%  (p=0.000 n=10+7)
GobEncode-8                15.3ms ± 1%    15.4ms ± 0%  +0.57%  (p=0.004 n=9+10)
Gzip-8                      789ms ± 0%     803ms ± 0%  +1.78%  (p=0.000 n=9+10)
Gunzip-8                    128ms ± 0%     130ms ± 0%  +1.73%  (p=0.000 n=10+9)
HTTPClientServer-8          202µs ± 6%     201µs ±10%    ~     (p=0.739 n=10+10)
JSONEncode-8               42.0ms ± 0%    42.1ms ± 0%  +0.19%  (p=0.028 n=10+9)
JSONDecode-8                159ms ± 0%     161ms ± 0%  +1.05%  (p=0.000 n=9+10)
Mandelbrot200-8            10.1ms ± 0%    10.1ms ± 0%  -0.07%  (p=0.000 n=10+9)
GoParse-8                  8.46ms ± 1%    8.61ms ± 1%  +1.77%  (p=0.000 n=10+10)
RegexpMatchEasy0_32-8       227ns ± 1%     226ns ± 0%  -0.35%  (p=0.001 n=10+9)
RegexpMatchEasy0_1K-8      1.63µs ± 0%    1.63µs ± 0%  -0.13%  (p=0.000 n=10+9)
RegexpMatchEasy1_32-8       250ns ± 0%     249ns ± 0%  -0.40%  (p=0.001 n=8+9)
RegexpMatchEasy1_1K-8      2.07µs ± 0%    2.08µs ± 0%  +0.05%  (p=0.027 n=9+9)
RegexpMatchMedium_32-8      350ns ± 0%     350ns ± 0%    ~     (p=0.412 n=9+8)
RegexpMatchMedium_1K-8      104µs ± 0%     104µs ± 0%  +0.31%  (p=0.000 n=10+7)
RegexpMatchHard_32-8       5.82µs ± 0%    5.82µs ± 0%    ~     (p=0.937 n=9+9)
RegexpMatchHard_1K-8        176µs ± 0%     176µs ± 0%  +0.03%  (p=0.000 n=9+8)
Revcomp-8                   1.36s ± 1%     1.37s ± 1%    ~     (p=0.218 n=10+10)
Template-8                  151ms ± 1%     156ms ± 1%  +3.21%  (p=0.000 n=10+10)
TimeParse-8                 737ns ± 0%     758ns ± 2%  +2.74%  (p=0.000 n=10+10)
TimeFormat-8                801ns ± 2%     789ns ± 1%  -1.51%  (p=0.000 n=10+10)
[Geo mean]                  142µs          143µs       +0.50%

Fixes #19137.

Change-Id: Ib8a21ea98c0ffb2d282a586535b213cc163e1b67
Reviewed-on: https://go-review.googlesource.com/37251
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
(cherry picked from commit 6464e5d)
Reviewed-on: https://go-review.googlesource.com/37719
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@aclements

This comment has been minimized.

Copy link
Member

commented Mar 21, 2017

I'm pretty sure this is fixed on the release branch now. @cherrymui, please reopen if I misunderstood the cherry-picks.

@aclements aclements closed this Mar 21, 2017

jamesr pushed a commit to fuchsia-mirror/garnet that referenced this issue Sep 20, 2017

[wlan] add alignment paddings to avoid Go compiler bug on arm64
Error message:
gen/gopaths/wlanstack/src/wlan/wlan/wlan.go:344: offset out of range:
294

Bug:
golang/go#19137

Change-Id: I27a9e57d8ff38854527b44c5ab98415449615c63

@golang golang locked and limited conversation to collaborators Mar 21, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.