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

cmd/compile: R12 can be clobbered for write barrier call on PPC64 #40851

Closed
cherrymui opened this issue Aug 17, 2020 · 10 comments
Closed

cmd/compile: R12 can be clobbered for write barrier call on PPC64 #40851

cherrymui opened this issue Aug 17, 2020 · 10 comments
Labels
arch-ppc64x FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@cherrymui
Copy link
Member

Most Go function calls potentially clobber all registers, except a small set of special ones, including the write barrier call. Currently, on PPC64, the write barrier call is marked as preserving R0, R3-R15 (except R13), and R20, R11. In external linking mode, for large binaries, the external linker may insert a trampoline for the write barrier call, which looks like

0000000005a98cc8 <__long_branch_runtime.gcWriteBarrier>:
 5a98cc8:       86 01 82 3d     addis   r12,r2,390
 5a98ccc:       d8 bd 8c e9     ld      r12,-16936(r12)
 5a98cd0:       a6 03 89 7d     mtctr   r12
 5a98cd4:       20 04 80 4e     bctr

It clobbers R12 (and CTR, which is never live across a call).

As at compile time we don't know whether the binary is big and what link mode will be used, I think we need to mark R12 as clobbered for write barrier call. I'll send a CL.

(Internal linking mode is okay, as the trampoline emitted by Go linker uses R31, the dedicated temp register, instead of R12.)

It has been like that several releases ago. I think we may want to back port, as there could cause runtime crash or data corruption without workaround.

@gopherbot
Copy link

Change https://golang.org/cl/248917 mentions this issue: cmd/compile, runtime: mark R12 clobbered for write barrier call on PPC64

@cherrymui
Copy link
Member Author

@ianlancetaylor pointed out that for future-proof, the external linker could clobber any caller-saved register that cannot be used for function arguments, that also includes R11. We could consider marking R11 as clobbered as well.

@cherrymui
Copy link
Member Author

@gopherbot please consider backporting this to Go 1.15. Thanks.

@gopherbot
Copy link

Backport issue(s) opened: #40868 (for 1.15).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot
Copy link

Change https://golang.org/cl/249019 mentions this issue: [release-branch.go1.15] cmd/compile, runtime: mark R12 clobbered for write barrier call on PPC64

@aclements
Copy link
Member

@cherrymui , does this also need a 1.14 backport? I'm pretty sure it does.

@cherrymui
Copy link
Member Author

Yeah, I think it also has this problem in Go 1.14.

@cherrymui
Copy link
Member Author

@gopherbot please consider backporting this to Go 1.14. Thanks.

@aclements
Copy link
Member

GopherBot is lazy (#25574), so I'm afraid you'll have to open the 1.14 backport issue by hand.

@gopherbot
Copy link

Change https://golang.org/cl/249697 mentions this issue: [release-branch.go1.14] cmd/compile, runtime: mark R12 clobbered for write barrier call on PPC64

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 2, 2020
@dmitshur dmitshur added this to the Go1.16 milestone Sep 2, 2020
gopherbot pushed a commit that referenced this issue Sep 3, 2020
…write barrier call on PPC64

When external linking, for large binaries, the external linker
may insert a trampoline for the write barrier call, which looks

0000000005a98cc8 <__long_branch_runtime.gcWriteBarrier>:
 5a98cc8:       86 01 82 3d     addis   r12,r2,390
 5a98ccc:       d8 bd 8c e9     ld      r12,-16936(r12)
 5a98cd0:       a6 03 89 7d     mtctr   r12
 5a98cd4:       20 04 80 4e     bctr

It clobbers R12 (and CTR, which is never live across a call).

As at compile time we don't know whether the binary is big and
what link mode will be used, I think we need to mark R12 as
clobbered for write barrier call. For extra safety (future-proof)
we mark caller-saved register that cannot be used for function
arguments, which includes R11, as potentially clobbered as well.

Updates #40851.
Fixes #40868.

Change-Id: Iedd901c5072f1127cc59b0a48cfeb4aaec81b519
Reviewed-on: https://go-review.googlesource.com/c/go/+/248917
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
(cherry picked from commit b58d297)
Reviewed-on: https://go-review.googlesource.com/c/go/+/249019
gopherbot pushed a commit that referenced this issue Sep 3, 2020
…write barrier call on PPC64

When external linking, for large binaries, the external linker
may insert a trampoline for the write barrier call, which looks

0000000005a98cc8 <__long_branch_runtime.gcWriteBarrier>:
 5a98cc8:       86 01 82 3d     addis   r12,r2,390
 5a98ccc:       d8 bd 8c e9     ld      r12,-16936(r12)
 5a98cd0:       a6 03 89 7d     mtctr   r12
 5a98cd4:       20 04 80 4e     bctr

It clobbers R12 (and CTR, which is never live across a call).

As at compile time we don't know whether the binary is big and
what link mode will be used, I think we need to mark R12 as
clobbered for write barrier call. For extra safety (future-proof)
we mark caller-saved register that cannot be used for function
arguments, which includes R11, as potentially clobbered as well.

Updates #40851.
Fixes #40938.

Change-Id: Iedd901c5072f1127cc59b0a48cfeb4aaec81b519
Reviewed-on: https://go-review.googlesource.com/c/go/+/248917
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
(cherry picked from commit b58d297)
Reviewed-on: https://go-review.googlesource.com/c/go/+/249697
claucece pushed a commit to claucece/go that referenced this issue Oct 22, 2020
…write barrier call on PPC64

When external linking, for large binaries, the external linker
may insert a trampoline for the write barrier call, which looks

0000000005a98cc8 <__long_branch_runtime.gcWriteBarrier>:
 5a98cc8:       86 01 82 3d     addis   r12,r2,390
 5a98ccc:       d8 bd 8c e9     ld      r12,-16936(r12)
 5a98cd0:       a6 03 89 7d     mtctr   r12
 5a98cd4:       20 04 80 4e     bctr

It clobbers R12 (and CTR, which is never live across a call).

As at compile time we don't know whether the binary is big and
what link mode will be used, I think we need to mark R12 as
clobbered for write barrier call. For extra safety (future-proof)
we mark caller-saved register that cannot be used for function
arguments, which includes R11, as potentially clobbered as well.

Updates golang#40851.
Fixes golang#40868.

Change-Id: Iedd901c5072f1127cc59b0a48cfeb4aaec81b519
Reviewed-on: https://go-review.googlesource.com/c/go/+/248917
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
(cherry picked from commit b58d297)
Reviewed-on: https://go-review.googlesource.com/c/go/+/249019
@golang golang locked and limited conversation to collaborators Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-ppc64x FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants