After some package upgrade on my Ubuntu 24.04 I stumbled upon inability to build/install/work with almost any of golang packages.
So, I'm trying to install staticcheck and get the following error:
$ go install -v honnef.co/go/tools/cmd/staticcheck@latest
go: downloading honnef.co/go/tools v0.6.1
go: downloading golang.org/x/tools v0.30.0
go: downloading github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
go: downloading golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678
go: downloading golang.org/x/sync v0.11.0
go: downloading golang.org/x/mod v0.23.0
go: downloading golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
runtime/cgo
# runtime/cgo
/tmp/ccyaXynT.s: Assembler messages:
/tmp/ccyaXynT.s: Internal error (Segmentation fault).
Please report this bug.
My go env is:
$ go env
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/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3918232214=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.1'
GOWORK=''
PKG_CONFIG='pkg-config'
Removing ~/.cache/go-build doesn't help. After some digging in I figured out exact command causes the error:
WORK=/tmp/go-build94545583
cd /usr/local/go/src/runtime/cgo
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x003.o -c gcc_context.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x004.o -c gcc_fatalf.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x005.o -c gcc_libinit.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x006.o -c gcc_linux_amd64.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x007.o -c gcc_mmap.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x008.o -c gcc_setenv.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x009.o -c gcc_sigaction.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x010.o -c gcc_stack_unix.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x011.o -c gcc_traceback.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x012.o -c gcc_util.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x013.o -c linux_syscall.c
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o $WORK/b331/_x014.o -c gcc_amd64.S
# runtime/cgo
/tmp/ccuohmsg.s: Assembler messages:
/tmp/ccuohmsg.s: Internal error (Segmentation fault).
Please report this bug.
GCC version is 13.3.0.
The interesting thing is it's compiled with gcc-9:
$ gcc-9 -I . -fPIC -m64 -pthread -fmessage-length=0 -ffile-prefix-map=$WORK/b331=/tmp/go-build -gno-record-gcc-switches -I $WORK/b331/ -O2 -g -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement -ffile-prefix-map=/usr/local/go=/_/GOROOT -frandom-seed=LT5_d3ncbMuqN3lN9Xk7 -o ~/_x014.o -c gcc_amd64.S
$ echo $?
0
This is go1.25.1 install from go.dev.
What is it? GCC bug? Ubuntu bug? How to solve it?
UPDATE:
Both version of gcc produce temporary assembly file and then try to compile it with as utility. I saved this temporary file (added -save-temps option to gcc invocation) and used strace utility to know how this compilers call as on it.
So, gcc version is:
$ as --debug-prefix-map /tmp/go-build94545583/b331=/tmp/go-build --debug-prefix-map usr/local/go=/_/GOROOT -I . -I /tmp/go-build94545583/b331/ --gdwarf-5 --64 -o ~/_x014.o ~/_x014.s
/home/user/_x014.s: Assembler messages:
/home/user/_x014.s: Internal error (Segmentation fault).
Please report this bug.
And gcc-9 version is:
$ as --gdwarf2 -I . -I /tmp/go-build94545583/b331/ --64 -o ~/_x014.o ~/_x014.s
$ echo $?
0
Since they both use the same version of as compiler the main difference is in -gdwarf2 and -gdwarf5 options. Indeed, if I swap it the file compiles!
Any suggestions? Please.
PS: I uploaded the content of _x014.s to https://gist.github.com/naughtyfox/7e26d52e63b78b60246349b7553c9784
_x014.sthe GNU assembler chokes on? It's already pretty tiny, so I guess no need to edit it down further, although in general that's something people can do even without knowing assembly, since GNU assembler assumes undefined symbols are external, and the effect of each line is usually pretty much local. (Compiler output doesn't define macros etc.).as --versionGNU assembler (GNU Binutils) 2.45.0 on my desktop, usingas --gdwarf-5 --64 segfault.sor--gdwarf2. (Or with the full copy/pasted command, but my system doesn't have the tmp or usr/local/go directories it references, in case that matters. The-Ioptions shouldn't matter since the.sfile doesn't use.include, but I don't know what--debug-prefix-mapdoes.) Anyway, probably this was a GAS bug which has since been fixed. If you look at reporting it upstream, check for duplicates. Or just try out the latest stable Binutils yourself.