Go version

go version go1.25.0 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/jhg/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/jhg/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3644727866=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/jhg/go-mips-poc/poc/go.mod'
GOMODCACHE='/home/jhg/go-mips-poc/go/packages/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/jhg/go-mips-poc/go/packages'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/jhg/go-mips-poc/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='off'
GOTELEMETRYDIR='/home/jhg/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/jhg/go-mips-poc/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

package main

import (
    "golang.org/x/crypto/sha3"
)

func main() {
    hasher := sha3.New256()
    hasher.Write([]byte{0})
    hasher.Write([]byte{0,0})
}

Build with GOARCH=mips go build and then run using qemu on Linux (Ubuntu) x64.

What did you see happen?

Panic:

unexpected fault address 0x584ed9
fatal error: fault
[signal SIGBUS: bus error code=0x1 addr=0x584ed9 pc=0xd1f7c]

goroutine 1 gp=0x400128 m=0 mp=0x196a40 [running]:
runtime.throw({0xf9ddd, 0x5})
    /home/jhg/go-mips-poc/go/src/runtime/panic.go:1094 +0x48 fp=0x584e24 sp=0x584e10 pc=0xa759c
runtime.sigpanic()
    /home/jhg/go-mips-poc/go/src/runtime/signal_unix.go:922 +0x23c fp=0x584e54 sp=0x584e24 pc=0xa8f4c
crypto/internal/fips140/subtle.xorBytes(0x584ed9, 0x584ed9, 0x584ed5, 0x2)
    /home/jhg/go-mips-poc/go/src/crypto/internal/fips140/subtle/xor_mipsx.s:195 +0x2cc fp=0x584e58 sp=0x584e58 pc=0xd1f7c
crypto/internal/fips140/subtle.XORBytes({0x584ed9, 0x87, 0xc7}, {0x584ed9, 0x87, 0xc7}, {0x584ed5, 0x2, 0x2})
    /home/jhg/go-mips-poc/go/src/crypto/internal/fips140/subtle/xor.go:28 +0x128 fp=0x584e70 sp=0x584e58 pc=0xd1c10
crypto/subtle.XORBytes(...)
    /home/jhg/go-mips-poc/go/src/crypto/subtle/xor.go:18
golang.org/x/crypto/sha3.(*state).Write(0x584ed8, {0x584ed5, 0x2, 0x2})
    /home/jhg/go-mips-poc/go/packages/pkg/mod/golang.org/x/crypto@v0.41.0/sha3/sha3.go:123 +0xe4 fp=0x584eb4 sp=0x584e70 pc=0xd1840
main.main()
    /home/jhg/go-mips-poc/poc/x.go:10 +0xc8 fp=0x584fb4 sp=0x584eb4 pc=0xd1ac8
runtime.main()
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:285 +0x334 fp=0x584fec sp=0x584fb4 pc=0x65f00
runtime.goexit({})
    /home/jhg/go-mips-poc/go/src/runtime/asm_mipsx.s:657 +0x4 fp=0x584fec sp=0x584fec pc=0xae3b4

goroutine 2 gp=0x400488 m=nil [force gc (idle)]:
runtime.gopark(0x102cc4, 0x195e88, 0x11, 0xa, 0x1)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:460 +0x128 fp=0x440fd4 sp=0x440fc8 pc=0xa76d4
runtime.goparkunlock(...)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:466
runtime.forcegchelper()
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:373 +0x128 fp=0x440fec sp=0x440fd4 pc=0x663c8
runtime.goexit({})
    /home/jhg/go-mips-poc/go/src/runtime/asm_mipsx.s:657 +0x4 fp=0x440fec sp=0x440fec pc=0xae3b4
created by runtime.init.6 in goroutine 1
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:361 +0x44

goroutine 3 gp=0x400a28 m=nil [GC sweep wait]:
runtime.gopark(0x102cc4, 0x195f90, 0xc, 0x9, 0x1)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:460 +0x128 fp=0x4417c4 sp=0x4417b8 pc=0xa76d4
runtime.goparkunlock(...)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:466
runtime.bgsweep(0x466000)
    /home/jhg/go-mips-poc/go/src/runtime/mgcsweep.go:279 +0xe8 fp=0x4417e4 sp=0x4417c4 pc=0x4af20
runtime.gcenable.gowrap1()
    /home/jhg/go-mips-poc/go/src/runtime/mgc.go:212 +0x64 fp=0x4417ec sp=0x4417e4 pc=0x37a3c
runtime.goexit({})
    /home/jhg/go-mips-poc/go/src/runtime/asm_mipsx.s:657 +0x4 fp=0x4417ec sp=0x4417ec pc=0xae3b4
created by runtime.gcenable in goroutine 1
    /home/jhg/go-mips-poc/go/src/runtime/mgc.go:212 +0xb4

goroutine 4 gp=0x400b48 m=nil [GC scavenge wait]:
runtime.gopark(0x102cc4, 0x1960a0, 0xd, 0xa, 0x2)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:460 +0x128 fp=0x441fbc sp=0x441fb0 pc=0xa76d4
runtime.goparkunlock(...)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:466
runtime.(*scavengerState).park(0x1960a0)
    /home/jhg/go-mips-poc/go/src/runtime/mgcscavenge.go:425 +0x98 fp=0x441fd0 sp=0x441fbc pc=0x47a00
runtime.bgscavenge(0x466000)
    /home/jhg/go-mips-poc/go/src/runtime/mgcscavenge.go:653 +0x74 fp=0x441fe4 sp=0x441fd0 pc=0x482b4
runtime.gcenable.gowrap2()
    /home/jhg/go-mips-poc/go/src/runtime/mgc.go:213 +0x64 fp=0x441fec sp=0x441fe4 pc=0x379c8
runtime.goexit({})
    /home/jhg/go-mips-poc/go/src/runtime/asm_mipsx.s:657 +0x4 fp=0x441fec sp=0x441fec pc=0xae3b4
created by runtime.gcenable in goroutine 1
    /home/jhg/go-mips-poc/go/src/runtime/mgc.go:213 +0x114

goroutine 5 gp=0x400ea8 m=nil [GOMAXPROCS updater (idle)]:
runtime.gopark(0x102cc4, 0x195f60, 0x12, 0xa, 0x1)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:460 +0x128 fp=0x4427a4 sp=0x442798 pc=0xa76d4
runtime.goparkunlock(...)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:466
runtime.updateMaxProcsGoroutine()
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:6706 +0x17c fp=0x4427ec sp=0x4427a4 pc=0x79ce4
runtime.goexit({})
    /home/jhg/go-mips-poc/go/src/runtime/asm_mipsx.s:657 +0x4 fp=0x4427ec sp=0x4427ec pc=0xae3b4
created by runtime.defaultGOMAXPROCSUpdateEnable in goroutine 1
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:6694 +0x78

goroutine 6 gp=0x400fc8 m=nil [finalizer wait]:
runtime.gopark(0x102b80, 0x1a0040, 0x10, 0xa, 0x1)
    /home/jhg/go-mips-poc/go/src/runtime/proc.go:460 +0x128 fp=0x442f90 sp=0x442f84 pc=0xa76d4
runtime.runFinalizers()
    /home/jhg/go-mips-poc/go/src/runtime/mfinal.go:210 +0x164 fp=0x442fec sp=0x442f90 pc=0x36488
runtime.goexit({})
    /home/jhg/go-mips-poc/go/src/runtime/asm_mipsx.s:657 +0x4 fp=0x442fec sp=0x442fec pc=0xae3b4
created by runtime.createfing in goroutine 1
    /home/jhg/go-mips-poc/go/src/runtime/mfinal.go:172 +0x98

What did you expect to see?

No output, no crash.

Comment From: guidovranken

@rolandshoemaker observes the panic when running in QEMU but not on a real MIPS system.

The cause is possibly an unaligned memory access in https://github.com/golang/go/blob/master/src/crypto/internal/fips140/subtle/xor_mipsx.s

@rolandshoemaker says:

It appears that the qemu-mips default CPU is a rather old one (from 2006) which predates the removal of unaligned instructions (since ~2014 all moves appear to tolerate unaligned loads.)

Comment From: rolandshoemaker

It's not immediately obvious to me how frequently the MIPS Go port is used on (a) qemu or (b) hardware old enough to trigger this failure. We may want more data on that before making a decision on how to fix this. If there is not an obvious way to handle these unaligned reads on older hardware, a reasonable fix may be to just revert https://go.dev/cl/666275.

Since MIPS is not a first class port, we may be fine just accepting this failure for the performance gain it gives us on newer hardware.

cc @golang/mips

Comment From: gabyhelp

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: randall77

I think we should revert. (Not sure why I didn't catch this at review time.) We currently don't allow unaligned accesses on mips. If we were to change that policy, we should probably do so through a proposal.

Comment From: rolandshoemaker

Sounds good to me.