Skip to content
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: invalid crash stack for morestackc unwind on arm64 mac #65730

Open
rsc opened this issue Feb 15, 2024 · 1 comment
Open

runtime: invalid crash stack for morestackc unwind on arm64 mac #65730

rsc opened this issue Feb 15, 2024 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Feb 15, 2024

Add this to runtime/proc.go:

diff --git a/src/runtime/proc.go b/src/runtime/proc.go
index 401dcd0a11..6d8fde4349 100644
--- a/src/runtime/proc.go
+++ b/src/runtime/proc.go
@@ -267,6 +267,10 @@ func main() {
 		// has a main, but it is not executed.
 		return
 	}
+
+println("oops")
+	oops()
+
 	fn := main_main // make an indirect call, as the linker doesn't know the address of the main package when laying down the runtime
 	fn()
 	if raceenabled {
@@ -7079,3 +7083,14 @@ func doInit1(t *initTask) {
 		t.state = 2 // initialization done
 	}
 }
+
+//go:noinline
+func oops() {
+	oopssys()
+}
+
+//go:systemstack
+//go:noinline
+func oopssys() {
+	println("onsys")
+}
% 

Running any program crashes like this, at least on my arm64 mac:

oops
fatal error: attempt to execute system stack code on user stack

goroutine 1 gp=0x140000021c0 m=0 mp=0x100e67620 [running]:
runtime.throw({0x100c18075?, 0x100a7ee40?})
	/Users/rsc/go/src/runtime/panic.go:1021 +0x40 fp=0x14000131f10 sp=0x14000131ee0 pc=0x100a7c510
runtime.morestackc()
	/Users/rsc/go/src/runtime/stack.go:1296 +0x1c fp=0x14000131f30 sp=0x14000131f10 pc=0x100ab3a4c
runtime.oopssys()
	/Users/rsc/go/src/runtime/proc.go:7094 +0x44 fp=0x14000131f30 sp=0x14000131f30 pc=0x100a8ebd4
runtime.main()
	/Users/rsc/go/src/runtime/proc.go:272 +0x294 fp=0x14000131fc0 sp=0x14000131f30 pc=0x100a7ee44
runtime.main()
	/Users/rsc/go/src/runtime/proc.go:272 +0x294 fp=0x14000132050 sp=0x14000131fc0 pc=0x100a7ee44
runtime: g 1: unexpected return pc for runtime.main called from 0x14000131fb0

Note that the runtime.oops frame is missing entirely
(runtime.main calls oops calls oopssys calls morestackc during prologue).
Probably the unwinder gets out of sync somewhere around there.
Perhaps the out-of-sync is also the reason for the 'unexpected return pc' failure during unwind.

/cc @aclements

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Feb 15, 2024
@rsc rsc added this to the Go1.23 milestone Feb 15, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 15, 2024
@cherrymui
Copy link
Member

cherrymui commented Feb 15, 2024

Yeah, morestackc is called using a weird calling convention (because it is in the stack bounds check prologue, before the function having a frame to push the LR) that the unwind code doesn't understand.

Maybe we could implement morestackc in assembly similar to morestack, then throw with the right PC/SP/LR. Or we could change the calling convention to morestack/morestackc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

3 participants