-
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: runtime.Breakpoint() generates illegal instruction on windows/arm64 #53837
Comments
This seems like it would've been a problem since the origin of the port. This isn't new in 1.19 is it? |
That's right. Some more context: I found this while porting go-delve to windows/arm64, and it uses |
I naively tried to fix it updating the TEXT runtime·breakpoint(SB),NOSPLIT|NOFRAME,$0-0
#ifdef GOOS_windows
WORD $0x00003ed4 // BRK #0xF000
#else
BRK
#endif
RET |
What does the argument do? |
I don't know. Found it thanks to this llvm issue: https://www.mail-archive.com/[email protected]/msg09058.html and confirmed llocally that it works. |
I don't think we should expect a successful run. Usually runtime.Breakpoint generates some sort of trap (usually SIGTRAP on UNIX-y systems). Maybe Windows doesn't distinguish a trap vs. an illegal instruction exception? Is there a SIGTRAP-like thing on Windows? |
My bad, it does not end successfully on The problem on |
The BRK instructions needs an immediate 16 bits argument. It seems like the operating system could inspect the immediate set by BRK and then send a different signal to the process depending on the value. BRK without the immediate would then become a shorthand for BRK 0. |
Thanks. Sounds like changing the function body to Is there a document about what constant Windows expects? The ARM instruction manual doesn't seem to mention what the constant does exactly. |
I can confirm that changing TEXT runtime·breakpoint(SB),NOSPLIT|NOFRAME,$0-0
BRK $0xf000
RET I don't have a Linux ARM64 machine, so can't test it.
The only place I've seen Windows docs mention the BRK argument for ARM64 is here: https://docs.microsoft.com/en-us/cpp/intrinsics/debugbreak?view=msvc-170#remarks
|
I tried @aarzilli does it sound okay to you? |
If we do this change, https://cs.opensource.google/go/go/+/master:src/runtime/export_debug_arm64_test.go;l=24 probably needs update. https://cs.opensource.google/go/go/+/master:src/runtime/signal_darwin_arm64.go;l=85 should probably be made to understand all BRK instructions. |
Changing Maybe it's the assembler that should be changed to emit |
Wouldn't it be better to add the argument just on windows/arm64? Who knows what can we break on older unix/darwin machines with this change. |
Change https://go.dev/cl/418734 mentions this issue: |
@cherrymui change submitted. I've finally only set the argument on windows/arm64 to avoid breaking changes, what do you think? @ianlancetaylor Could we make this into go1.19? It is low risk and will facilitate Delve support for windows/arm64. |
SGTM. Thanks. I would think we don't change the assembler to emit a different instruction for
Does Delve require a specific type of exception? Just curious. |
Delve does different things with different types of exceptions, most of them just get sent back to the target process. It would be possible to check what the illegal instruction is and if it is a BRK (with any argument) treat it as if it was a breakpoint (I'm assuming here that illegal instruction exceptions do get sent to the debugger first, I haven't checked). IMO however it is better to not fight the os on this and just use the instruction microsoft wants us to use. |
Sounds good. Thanks! |
Fixes golang#53837 Change-Id: I4219fe35aac1a88aae2905998fbb1d7db87bbfb2 Reviewed-on: https://go-review.googlesource.com/c/go/+/418734 Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Alessandro Arzilli <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Alessandro Arzilli <[email protected]>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go run .
What did you expect to see?
Edited:
exit status 0xc0000409
Hello World!
What did you see instead?
Program crashes due to an ilegal instruction:
The text was updated successfully, but these errors were encountered: