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: illegal instruction (core dumped) on FreeBSD ARM64 #37345

Closed
artooro opened this issue Feb 20, 2020 · 22 comments
Closed

cmd/compile: illegal instruction (core dumped) on FreeBSD ARM64 #37345

artooro opened this issue Feb 20, 2020 · 22 comments

Comments

@artooro
Copy link

@artooro artooro commented Feb 20, 2020

What version of Go are you using? 1.14rc1

go version go1.14rc1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/artooro/Library/Caches/go-build"
GOENV="/Users/artooro/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/artooro/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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=/var/folders/9z/jlqzn0wj4g12dg0ykj78dyph0000gn/T/go-build674964893=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

This can be reproduced by a very basic program, for example:

package main

import "fmt"

func main() {
	fmt.Println("Hello world")
}

Compile with the following environment variables.

GOOS=freebsd
GOARCH=arm64

Tried to run it on a Marvell Armada 3720LP (88F3720) dual core ARM Cortex A53.

What did you expect to see?

For the program to print "Hello World"

What did you see instead?

I get the following output: Illegal instruction (core dumped)

Here is the core dump file of that test program.
testfreebsdarm64.core.zip

@ianlancetaylor ianlancetaylor changed the title Illegal instruction (core dumped) on FreeBSD ARM64 cmd/compile: illegal instruction (core dumped) on FreeBSD ARM64 Feb 21, 2020
@ianlancetaylor ianlancetaylor added this to the Go1.15 milestone Feb 21, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 21, 2020

Can you run the program under gdb to find out exactly what the illegal instruction is?

@bcmills
Copy link
Member

@bcmills bcmills commented Feb 21, 2020

See also #35851 (SIGILL on darwin/arm64).

@artooro
Copy link
Author

@artooro artooro commented Feb 21, 2020

@ianlancetaylor when running in gdb here is the output.

(gdb) source go/src/runtime/runtime-gdb.py
Loading Go Runtime support.
(gdb) run
Starting program: /root/testfreebsdarm64 

Program received signal SIGILL, Illegal instruction.
runtime.getisar0 () at /usr/local/go/src/runtime/sys_freebsd_arm64.s:522
522	/usr/local/go/src/runtime/sys_freebsd_arm64.s: No such file or directory.
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 21, 2020

Thanks. Please use x/i $pc to see the exact instruction.

@artooro
Copy link
Author

@artooro artooro commented Feb 21, 2020

Ok I think this is what you're looking for.

(gdb) x/i $pc
=> 0x66030 <runtime.getisar0>:	mrs	x0, id_aa64isar0_el1

Sorry my first time using gdb.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 21, 2020

Thanks.

Does anybody know why that instruction would trigger an illegal instruction interrupt? As far as I can tell it should be supported on any ARMv8 processor. Is it a privileged instruction?

CC @cherrymui @4a6f656c @tklauser @4ad

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Feb 21, 2020

Reading the manual, it looks to me the register id_aa64isar0_el1 is privileged. It seems accessing the register in user mode is "UNDEFINED". Maybe @zhangfannie can confirm.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 22, 2020

@MikaelUrankar
Copy link

@MikaelUrankar MikaelUrankar commented Feb 22, 2020

yes, id_aa64isar0_el1 is privileged. The FreeBSD kernel traps the exception and returns correct values to userland (at least on "recent" version of FreeBSD, I think it appears in FreeBSD 12.0, not sure it works in 11.x)
@artooro, what version do you run?

@myfreeweb
Copy link

@myfreeweb myfreeweb commented Feb 22, 2020

Yes, it appears in 12.0.

12.0 also introduced the 64-bit-inodes ABI, and IIRC go uses it, not the legacy one. So forget about 11.x and older.

@zhangfannie
Copy link
Contributor

@zhangfannie zhangfannie commented Feb 24, 2020

@cherrymui yes, id_aa64isar0_el1 is not accessible in user mode.

@shawn-xdji
Copy link
Contributor

@shawn-xdji shawn-xdji commented Feb 24, 2020

could the 'features' of /proc/cpuinfo be shared? Thanks.

@MikaelUrankar
Copy link

@MikaelUrankar MikaelUrankar commented Feb 24, 2020

What's /proc/cpuinfo?

@tklauser
Copy link
Member

@tklauser tklauser commented Feb 24, 2020

/proc/cpuinfo is only available on Linux, not on FreeBSD.

@shawn-xdji
Copy link
Contributor

@shawn-xdji shawn-xdji commented Feb 24, 2020

/proc/cpuinfo is only available on Linux, not on FreeBSD.

Thanks a lot, I've no idea of the difference.

Out of curiosity, does FreeBSD kernel have the same feature of 'mrs emulation' as linux's, a similar issue could be reproduced on an arm64 machine with linux kernel before 4.10 where the feature is not present, a higher version works fine.

@myfreeweb
Copy link

@myfreeweb myfreeweb commented Feb 24, 2020

@shawn-xdji yes! @MikaelUrankar mentioned this above!!! This is why the register is read.

linux kernel before 4.10

And for FreeBSD that version is 12.0.

Which as I already mentioned is the minimum version for other reasons too.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 24, 2020

@artooro What version of FreeBSD are you using?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 24, 2020

Would somebody who understands the details like to update https://golang.org/wiki/MinimumRequirements? Thanks.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 24, 2020

Change https://golang.org/cl/220426 mentions this issue: doc/go1.14: freebsd/arm64 requires FreeBSD 12.0 or later

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 24, 2020

Change https://golang.org/cl/220427 mentions this issue: doc/go1.14: document that freebsd/arm64 requires FreeBSD 12.0 or later

gopherbot pushed a commit that referenced this issue Feb 24, 2020
Updates #24715
Updates #37345

Change-Id: I787a9b2ab1c68e1d379aac0a31bdf6217f04f911
Reviewed-on: https://go-review.googlesource.com/c/go/+/220426
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
gopherbot pushed a commit that referenced this issue Feb 24, 2020
…res FreeBSD 12.0 or later

Updates #24715
Updates #37345

Change-Id: I787a9b2ab1c68e1d379aac0a31bdf6217f04f911
Reviewed-on: https://go-review.googlesource.com/c/go/+/220426
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
(cherry picked from commit 28c501b)
Reviewed-on: https://go-review.googlesource.com/c/go/+/220427
@artooro
Copy link
Author

@artooro artooro commented Feb 25, 2020

@ianlancetaylor yeah I'm using 11.3 so yeah if it requires FreeBSD 12.0+ that would explain things.

@tklauser
Copy link
Member

@tklauser tklauser commented Feb 25, 2020

Given that the originally reported problem occurs on FreeBSD 11.3 and we now explicitly document that freebsd/arm64 is only supported on FreeBSD 12.0 and later, I think we can close this.

@tklauser tklauser closed this Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants
You can’t perform that action at this time.