-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
runtime: GOARM64=v8.1 crash with illegal hardware instruction on v8.6 #71411
Comments
The crash is on Added in https://go.dev/cl/610195. I feel like I'm missing something, doesn't cc @golang/runtime @golang/arm |
I do seem to be missing something because GOARM64=v8.1 is fine on a linux-arm64 gomote. |
I think some OS kernels emulate the read of ID_AA64ISAR0_EL1. But apparently darwin kernel doesn't. We probably should not use it on darwin. |
IIUC, Linux emulates this instruction: https://elixir.bootlin.com/linux/v6.12.6/source/arch/arm64/kernel/cpufeature.c#L3653 This instruction is Op0 = 0x3, CRn = 0x0, Op1 = 0x0, CRm = 6. Probably safest to only use this instruction on OSes that we are sure emulate it, rather than slowly adding a denylist as bugs come in? |
I think we should just revert 610195 and try again next cycle. |
For future reference, there do seem to be sysctls on Darwin to check for CPU features: https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/kern/kern_mib.c#L1185 Though I'm unsure if we'd manage to successfully run long enough to be able to call into libc before crashing from a bad instruction. |
Yeah, we use sysctls on Darwin in the internal/cpu package. Instead of checking the CPU features in assembly code, perhaps we just check it against what we got from internal/cpu, and use only the lowest level instructions in runtime startup before the check, if that is possible. |
Does anyone managed to look into a fix? It seems that we have to shift logic around a bit to do a proper fix since this assembly code runs before any runtime init, so I would rather revert it as Keith suggested. |
Change https://go.dev/cl/644695 mentions this issue: |
Hi @prattmic , I'm the original author of the offending code, so perhaps it makes sense to add me to CC list of related bugs? Thanks! |
@cherrymui , there is a similar note from @4a6f656c during the original code review: https://go-review.googlesource.com/c/go/+/610195/10#message-d03c129bec9642058969f7ee21b46a178ee18c1b. We have two options: either #ifndef not only OpenBSD, but all BSD flavors, including Darwin, as well -- or #ifdef it only for Linux. What would you prefer? |
@andreybokhanko, apologies, I indeed should have CC'd you when I found https://go.dev/cl/610195.
If we're going to continue using assembly, I think #ifdef enabling it only for OSes that we know for sure do emulation is the way to go. That said, I agree with @cherrymui that it would be nice if we could use internal/cpu for feature checks, since that package already knows how to get the features. Though as we use more and more advanced features in the compiler, it seems like it might be hard to ensure that we don't use any unsupported features long enough to get to internal/cpu. |
I was thinking if possible to ensure the compiler to use just the basic ISA to compile the startup functions, either by having a hard-coded list of functions, or using some (internal) pragma. They only run during startup, so it doesn't need to be very fast, using the newest CPU features. If we want to keep using assembly, perhaps start with |
Change https://go.dev/cl/645795 mentions this issue: |
TBH, I don't feel comfortable enough to change the whole approach to startup checks, so let me choose the easier way ( https://go-review.googlesource.com/c/go/+/645795 submitted; please take a look. |
Go version
go1.24-608acff84
Output of
go env
in your module/workspace:What did you do?
I tried to compile a darmin/arm64 binary and specifying a GOARM64 version my Macbook Air M2 should support.
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: