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: fixup darwin/arm64 framepointer assembly #39524

Open
eliasnaur opened this issue Jun 11, 2020 · 5 comments
Open

runtime: fixup darwin/arm64 framepointer assembly #39524

eliasnaur opened this issue Jun 11, 2020 · 5 comments
Labels
Milestone

Comments

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Jun 11, 2020

Quoting @cherrymui from CL 220588:

For example, in runtime/sys_darwin_arm64.s, function open_trampoline, the frame pointer is not saved. One possibility is to change the frame size (the $0 on the TEXT line) to 16, so the assembler will automatically allocate a frame and save the frame pointer, and remove the SUB and ADD to RSP. Do the same to other functions as well.

Another example is runtime/preempt_arm64.s, currently the frame pointer is only saved #ifdef GOOS_linux. We may want to do this for #ifdef GOOS_darwin as well.

@steeve
Copy link
Contributor

@steeve steeve commented Jun 11, 2020

That may explain why we saw weird unwinding on iOS.

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Jun 11, 2020

I'll try to do this for Go 1.16. Thanks.

@cherrymui cherrymui added this to the Go1.16 milestone Jun 11, 2020
@toothrot toothrot added the NeedsFix label Jun 12, 2020
@steeve
Copy link
Contributor

@steeve steeve commented Jul 2, 2020

Hey @cherrymui, I just tried to do what you said, and ended up with a crash, using Go 1.13.8.

Here is the diff, just in case I'm missing something from your directives:

diff --git a/src/runtime/sys_darwin_arm64.s b/src/runtime/sys_darwin_arm64.s
index ac3ca74f63..63becfb630 100644
--- a/src/runtime/sys_darwin_arm64.s
+++ b/src/runtime/sys_darwin_arm64.s
@@ -15,14 +15,12 @@ TEXT notok<>(SB),NOSPLIT,$0
 	MOVD	R8, (R8)
 	B	0(PC)
 
-TEXT runtime·open_trampoline(SB),NOSPLIT,$0
-	SUB	$16, RSP
+TEXT runtime·open_trampoline(SB),NOSPLIT,$16
 	MOVW	8(R0), R1	// arg 2 flags
 	MOVW	12(R0), R2	// arg 3 mode
 	MOVW	R2, (RSP)	// arg 3 is variadic, pass on stack
 	MOVD	0(R0), R0	// arg 1 pathname
 	BL	libc_open(SB)
-	ADD	$16, RSP
 	RET
 
 TEXT runtime·close_trampoline(SB),NOSPLIT,$0

Also, what was the reason for the frame to be manually allocated, rather than via declaration?

@steeve
Copy link
Contributor

@steeve steeve commented Jul 2, 2020

Also, do you think asmcgocall should have it? We saw unwinders unable to go past it (main thread starting at this function).

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 6, 2020

Change https://golang.org/cl/241158 mentions this issue: runtime: adjust frame pointer on stack copy on ARM64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.