Go 1.22.0 breaks BOOTBOOT compilation

Hi all, seeing if anyone else has happened across this issue or similar and has an idea of how to proceed.

I’m writing an OS and am doing my testing with QEMU’s Raspberry Pi 3 emulation. I am using bzt’s BOOTBOOT located here: bzt / bootboot · GitLab

Using just BOOTBOOT things, I can compile and get started with Go 1.21.6, but upon updating to Go 1.22.0, the following error message is shown on attempted compilation.

#
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath -gcflags=gitlab.com/bztsrc/bootboot=-std -ldflags="-linkmode external -extld aarch64-linux-gnu-ld -extldflags '-nostdlib -n -v -static -m aarch64elf -T link.ld'" -o mykernel.aarch64.elf
-linkmode requires external (cgo) linking, but cgo is not enabled
make: *** [Makefile:41: mykernel.aarch64.elf] Error 1

Setting CGO_ENABLED=1 gives the following error message.

#
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 go build -trimpath -gcflags=gitlab.com/bztsrc/bootboot=-std -ldflags="-linkmode external -extld aarch64-linux-gnu-ld -extldflags '-nostdlib -n -v -static -m aarch64elf -T link.ld'" -o mykernel.aarch64.elf
# runtime/cgo
gcc_arm64.S: Assembler messages:
gcc_arm64.S:30: Error: no such instruction: `stp x29,x30,[sp,'
gcc_arm64.S:34: Error: too many memory references for `mov'
gcc_arm64.S:36: Error: no such instruction: `stp x19,x20,[sp,'
gcc_arm64.S:39: Error: no such instruction: `stp x21,x22,[sp,'
gcc_arm64.S:42: Error: no such instruction: `stp x23,x24,[sp,'
gcc_arm64.S:45: Error: no such instruction: `stp x25,x26,[sp,'
gcc_arm64.S:48: Error: no such instruction: `stp x27,x28,[sp,'
gcc_arm64.S:52: Error: too many memory references for `mov'
gcc_arm64.S:53: Error: too many memory references for `mov'
gcc_arm64.S:54: Error: too many memory references for `mov'
gcc_arm64.S:56: Error: no such instruction: `blr x20'
gcc_arm64.S:57: Error: no such instruction: `blr x19'
gcc_arm64.S:59: Error: no such instruction: `ldp x27,x28,[sp,'
gcc_arm64.S:62: Error: no such instruction: `ldp x25,x26,[sp,'
gcc_arm64.S:65: Error: no such instruction: `ldp x23,x24,[sp,'
gcc_arm64.S:68: Error: no such instruction: `ldp x21,x22,[sp,'
gcc_arm64.S:71: Error: no such instruction: `ldp x19,x20,[sp,'
gcc_arm64.S:74: Error: no such instruction: `ldp x29,x30,[sp],'
make: *** [Makefile:41: mykernel.aarch64.elf] Error 1

I’m not sure what’s happened, but I agree with bzt’s response on the GitLab issue I opened. Any idea what might be causing this error and perhaps how to fix it? I’d like to stay up to date on Go’s releases but this one has me stumped. Thanks for any help!

1 Like

Wild guess but could be because of the changes in the memory allocator?

Try building with GOEXPERIMENT=noallocheaders to have the old behaviour again.

Hey duckduck, sorry about the late reply and thanks for the help. I wasn’t able to build with the option you listed, so I’m unable to confirm if it works or not. I’m sure it’s an issue on my end in terms of actually getting that option into my Go environment. Either it gives me an error (rightfully so) if I put the wrong option in or it seems to silently fail or ignore my noallocheaders. As far as the actual issue goes, it seems to be that the compiler is reading the # symbol as a comment, so the rest of the instruction after the assembly immediate is cut off at compilation.

i.e. stp x19, x20, [sp, #4] is shown as
stp x19, x20, [sp,

I’m not sure how to fix this so I’m sitting on Go 1.21.7 for the moment.