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: fails to run on some ARMv7 processors #14711

Closed
aka-mj opened this issue Mar 8, 2016 · 8 comments
Closed

cmd/compile: fails to run on some ARMv7 processors #14711

aka-mj opened this issue Mar 8, 2016 · 8 comments
Milestone

Comments

@aka-mj
Copy link

aka-mj commented Mar 8, 2016

Please answer these questions before submitting your issue. Thanks!

1. What version of Go are you using (go version)?
go version go1.6 linux/amd64

2. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mjohn/workspace/gopath"
GORACE=""
GOROOT="/home/mjohn/software/go"
GOTOOLDIR="/home/mjohn/software/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

3. What did you do?
(Use play.golang.org to provide a runnable example, if possible.)

I am cross-compiling for ARMv7. I have a simple hello world program.

package main

import "fmt"

func main() {
    fmt.Println("Hello, tester")
}

I built Go to cross-compile.
GOARCH=arm GOARM=7 GOOS=linux ./make.bash

Then compiled the code.
GOARCH=arm GOARM=7 GOOS=linux go build hello.go

The resulting executable runs on one ARMv7 board but fails on another with a different ARMv7 processor.

Processor where code runs:
Freescale i.MX53

$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 799.53
Features        : swp half thumb fastmult vfp edsp neon vfpv3
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x2
CPU part        : 0xc08
CPU revision    : 5

Processor where code does not run:
Ti am3352

$ cat /proc/cpuinfo
Processor       : ARMv7 Processor rev 2 (v7l)
BogoMIPS        : 797.80
Features        : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x3
CPU part        : 0xc08
CPU revision    : 2

4. What did you expect to see?
./hello
Hello, tester

5. What did you see instead?
./hello
Illegal instruction

@ianlancetaylor ianlancetaylor changed the title Fails to run on some ARMv7 processors cmd/compile: fails to run on some ARMv7 processors Mar 8, 2016
@ianlancetaylor ianlancetaylor added this to the Go1.7 milestone Mar 8, 2016
@ianlancetaylor
Copy link
Contributor

Can you find out what the illegal instruction is? It should work to run something like

gdb ./hello
r
x/i $pc

@aka-mj
Copy link
Author

aka-mj commented Mar 8, 2016

Sure, see below:

(gdb) r
Starting program: /root/hello
Cannot access memory at address 0x0
Cannot access memory at address 0x0

Program received signal SIGILL, Illegal instruction.
0x00067620 in ?? ()
(gdb) x/i $pc
=> 0x67620:     mcr2    4, 7, r8, cr2, cr0, {7}

@mwhudson
Copy link
Contributor

mwhudson commented Mar 8, 2016

My understand and experiments both suggest that we don't generate the mcr2 instruction. (I tried this:

(master)mwhudson@aeglos:go$ GOARCH=arm GOARM=7 GOOS=linux go build /opt/opensource/go-test-cases/hello.go 
(master)mwhudson@aeglos:go$ objdump -d trivial | grep -i mcr

so maybe somehow that's executing data that is not intended to be code?

@davecheney
Copy link
Contributor

I know it's not directly helpful to the problem at hand, but

I built Go to cross-compile.
GOARCH=arm GOARM=7 GOOS=linux ./make.bash

This is not necessary since Go 1.5, and in fact could be considered to be the wrong thing to do. To cross compile all that is necessary is GOOS=NNN GOARCH=YYY go build $PKG

@minux
Copy link
Member

minux commented Mar 9, 2016 via email

@aka-mj
Copy link
Author

aka-mj commented Mar 9, 2016

@minux Sure, you can get it here

@minux
Copy link
Member

minux commented Mar 9, 2016

It seems the binary is completely corrupted.

Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] go.buildid NULL 00000000 000000 000000 00 0 0 0
[ 1] o.buildid PROGBITS 00011000 001000 0abf84 00 AX 0 0 4
[ 2] b PROGBITS 000bd000 0ad000 04bc90 00 A 0 0 8
[ 3] b PROGBITS 00108c90 0f8c90 001028 00 A 0 0 4
[ 4] bbrev PROGBITS 00109cb8 0f9cb8 000000 00 A 0 0 1
[ 5] ug_aranges PROGBITS 00109cb8 0f9cb8 03e40e 00 A 0 0 8
[ 6] STRTAB 00000000 1380c8 00012a 00 0 0 1
[ 7] did PROGBITS 00149000 139000 001740 00 WA 0 0 8
[ 8] a PROGBITS 0014a740 13a740 001230 00 WA 0 0 8
[ 9] ata NOBITS 0014b970 13b970 00d62c 00 WA 0 0 8
[10] typelink NOBITS 00158fa0 148fa0 004720 00 WA 0 0 8
[11] gosymtab NOTE 00010fc8 000fc8 000038 00 A 0 0 4
[12] .debug_frame SYMTAB 00000000 13c000 00a630 10 13 136 4
[13] rame STRTAB 00000000 146630 00ead0 00 0 0 1
[14] bug_info PROGBITS 00000000 155100 0000ff 00 0 0 1
[15] pubnames PROGBITS 00000000 1551ff 0108e8 00 0 0 1
[16] oc PROGBITS 00000000 165ae7 00de84 00 0 0 1
[17] info PROGBITS 00000000 17396b 03a022 00 0 0 1
[18] PROGBITS 00000000 1ad98d 01144a 00 0 0 1
[19] ug_gdb_scripts PROGBITS 00000000 1bedd7 0064cc 00 0 0 1
[20] g_line PROGBITS 00000000 1c52a3 000020 00 0 0 1
[21] PROGBITS 00000000 1c52c3 000034 00 0 0 1

Symbol table '.debug_frame' contains 2659 entries:
Num: Value Size Type Bind Vis Ndx Name
0: b8000000 4252 NOTYPE LOCAL DEFAULT 256
1: 3c000000 4194 NOTYPE LOCAL DEFAULT 256
2: 34000000 4114 NOTYPE LOCAL DEFAULT 256
3: 48000000 3637 NOTYPE LOCAL DEFAULT 256
4: 2c000000 4203 NOTYPE LOCAL DEFAULT 256
5: 60000000 0xcc001068 FUNC LOCAL DEFAULT 256

6760c: dae04bb0 ble ff87a4d4 <(null)+0x387a405>
67610: 00eaffff strdeq pc, [sl], #255 ; 0xff ;

67614: 04e59d00 strbteq r9, [r5], #3328 ; 0xd00
67618: 04e28d10 strbteq r8, [r2], #3344 ; 0xd10
6761c: 00e59f40 rsceq r9, r5, r0, asr #30
67620: fee284f0 mcr2 4, 7, r8, cr2, cr0, {7}
67624: 2ceaffff stclcs 15, cr15, [sl], #1020 ; 0x3fc
67628: 03000676 movweq r0, #1654 ; 0x676

@aka-mj
Copy link
Author

aka-mj commented Mar 9, 2016

I removed Go from my system, and preformed a fresh install. This time I took @davecheney advice and did not define GOARCH or GOARM on the install, only while building the executable.

$ ./make.bash
....
$ GOARCH=arm GOARM=7 go build hello.go

This produces the expected result on the target when ran.

@aka-mj aka-mj closed this as completed Mar 9, 2016
@golang golang locked and limited conversation to collaborators Mar 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants