Skip to content

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

@rsc

Description

@rsc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions