-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: cross compile for OpenBSD arm64 fails with SIGILL Illegal instruction #66040
Comments
Can you print the stack pointer at those failures? It might be incorrectly aligned. https://stackoverflow.com/questions/63003217/behaviors-of-stack-pointer-in-arm64 |
Included a couple extra commands of gdb output in case it helps:
|
this is possibly BTI as it appears that you are running -current. I can't reproduce it on an arm64 machine without BTI (and unfortunately don't have one with it). |
Go from ports is patched to mark executables NOBTCFI; something similar is going to be needed in upstream Go as well. |
Upstream should really implement support for PAC and/or BTI. |
This is a fresh install of 7.4 from
Although separately yes, upstream support for BTI and PAC would be great :) Is there a way I could use the go build flags to test if this is BTI related? |
The ports patch is relevant to the system's native linker (ld.lld), not cross compiling. It is adding a PT_OPENBSD_NOBTCFI section but I'm not sure if this can be done without modifications to cmd/link. If you update to -current and use ports Go, you could probably test this hypothesis comparing |
BTI is used on amd64/arm64 if supported by the cpu in 7.4, no need for -current. |
IIRC we have patched for both internal and external linkers. |
Ah, yes that true: https://github.com/openbsd/ports/blob/master/lang/go/patches/patch-src_cmd_link_internal_ld_elf_go So that experiment won't work, both will have the section. In any case, this seems to be the issue. |
I think the issue is my CPU is too new. Reproducing the exact same test on an M1 instead of an M3 Max works without issue, and I now see that only M1 and M2 generation chips are currently supported on the OpenBSD hardware support page. Curiously, it doesn't seem to be BTI. My M3 Max doesn't show
And on the M1 it also doesn't show up:
Sorry about the false alarm all, I'll close the issue now and wait patiently for M3 support in OpenBSD :) |
BTI support was introduced on the M2. It's not unexpected that you wouldn't see this crash on M1. I don't know why BT is missing from the M3's dmesg. OpenBSD (nor Asahi) does not support booting the platform natively yet. Perhaps enforcement is still occurring despite it being missing from dmesg. I would reopen the issue. In the short term, NOBTCFI will work around this, but OpenBSD would prefer that BTI (and IBT on amd64) be properly implemented, and for these instructions to not only be emitted for OpenBSD targets, but all platforms. |
Can you build the hello world program from ports Go to confirm this? It should run and you should also see
|
Confirmed when building with go from ports it runs fine, and that is the exact output from readelf. |
Also confirmed the issue is BTI being enforced: I upgraded the VM to the most recent snapshot which includes the recently added code meant to identify this exact scenario, and there it is at the end of the output of
On 7.4 the code was just |
Change https://go.dev/cl/568435 mentions this issue: |
Just chiming in to confirm that 1e43391 has fixed the issue for me. Compiling go from source after the commit on Linux, and cross building hello world for openbsd/arm64, the resulting binary runs correctly and readelf shows the OPENBSD_NOBTCF section. Thanks! |
Go version
go version go1.22.0 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Cross compiling a simple hello world program for OpenBSD arm64 fails with SIGILL Illegal instruction.
Hello world code:
Compiled with
GOOS=openbsd GOARCH=arm64 go build hello.go
from a different machine, and run on an OpenBSD VM running on my MacBook with an M3 Max chip:OpenBSD openbsd-dev.my.domain 7.4 GENERIC.MP#2273 arm64
fails with illegal instruction.What did you see happen?
Natively building hello world on OpenBSD arm64 works fine, and that machine does have GOOS=openbsd and GOARCH=arm64 defined in the
go env
, but building the above code with the above command from my darwin/arm64 machine running go1.22.0 as above, and also my linux/amd64 machine running go 1.21.7 produces the illegal instruction error.GDB on openbsd with the build from linux:
GDB on openbsd from the build from my Mac:
GDB on openbsd from mac with
GOOS=openbsd GOARCH=arm64 go build -trimpath hello.go
:What did you expect to see?
Note that building the above hello world code into an OpenBSD amd64 binary from both my darwin/arm64 machine and my linux/amd64 machine works and the resulting binary works on a separate OpenBSD amd64 machine I have without issue, so something seems to be wrong with OpenBSD arm64 specifically. I do see openbsd/arm64 in the output of
go tool dist list
, so I would expect it to work.The text was updated successfully, but these errors were encountered: