internal/fakecgo: don't overwrite the caller stack on arm64 trampolines (#379)
amd64 and arm64 assembly trampolines moved from stack arguments to register arguments in #73. This means that we don't need to store the registers on the stack anymore. Note that doing so might even lead to some nasty bugs, as we are writing on stack slots that haven't been allocated in the function frame, potentially corrupting the caller stack. Updates #343
- commit
- f6151bf170c6121805bae36e805fd92554e79773
- author
- Quim Muntal · · 2025-12-18 15:11 UTC
- committer
- GitHub · · 2025-12-18 15:11 UTC
- parent
- 5bb15cb
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown
1 file · +2 -6
M internal/fakecgo/trampolines_arm64.s +2 -6
| @@ -7,32 +7,28 @@ | |||
| 7 | 7 | #include "go_asm.h" | |
| 8 | 8 | #include "abi_arm64.h" | |
| 9 | 9 | ||
| 10 | - | // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. | |
| 10 | + | // These trampolines map the gcc ABI to Go ABIInternal and then calls into the Go equivalent functions. | |
| 11 | + | // Note that C arguments are passed in R0-R7, which matches Go ABIInternal for the first eight arguments. | |
| 11 | 12 | ||
| 12 | 13 | TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0 | |
| 13 | - | MOVD R0, 8(RSP) | |
| 14 | - | MOVD R1, 16(RSP) | |
| 15 | 14 | MOVD ·x_cgo_init_call(SB), R26 | |
| 16 | 15 | MOVD (R26), R2 | |
| 17 | 16 | CALL (R2) | |
| 18 | 17 | RET | |
| 19 | 18 | ||
| 20 | 19 | TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $0-0 | |
| 21 | - | MOVD R0, 8(RSP) | |
| 22 | 20 | MOVD ·x_cgo_thread_start_call(SB), R26 | |
| 23 | 21 | MOVD (R26), R2 | |
| 24 | 22 | CALL (R2) | |
| 25 | 23 | RET | |
| 26 | 24 | ||
| 27 | 25 | TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $0-0 | |
| 28 | - | MOVD R0, 8(RSP) | |
| 29 | 26 | MOVD ·x_cgo_setenv_call(SB), R26 | |
| 30 | 27 | MOVD (R26), R2 | |
| 31 | 28 | CALL (R2) | |
| 32 | 29 | RET | |
| 33 | 30 | ||
| 34 | 31 | TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $0-0 | |
| 35 | - | MOVD R0, 8(RSP) | |
| 36 | 32 | MOVD ·x_cgo_unsetenv_call(SB), R26 | |
| 37 | 33 | MOVD (R26), R2 | |
| 38 | 34 | CALL (R2) | |
| @@ -7,32 +7,28 @@ | |||||
| 7 | #include "go_asm.h" | 7 | #include "go_asm.h" | ||
| 8 | #include "abi_arm64.h" | 8 | #include "abi_arm64.h" | ||
| 9 | 9 | ||||
| 10 | - | // these trampolines map the gcc ABI to Go ABI and then calls into the Go equivalent functions. | 10 | + | // These trampolines map the gcc ABI to Go ABIInternal and then calls into the Go equivalent functions. |
| 11 | + | // Note that C arguments are passed in R0-R7, which matches Go ABIInternal for the first eight arguments. | |||
| 11 | 12 | ||||
| 12 | TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0 | 13 | TEXT x_cgo_init_trampoline(SB), NOSPLIT, $0-0 | ||
| 13 | - | MOVD R0, 8(RSP) | |||
| 14 | - | MOVD R1, 16(RSP) | |||
| 15 | MOVD ·x_cgo_init_call(SB), R26 | 14 | MOVD ·x_cgo_init_call(SB), R26 | ||
| 16 | MOVD (R26), R2 | 15 | MOVD (R26), R2 | ||
| 17 | CALL (R2) | 16 | CALL (R2) | ||
| 18 | RET | 17 | RET | ||
| 19 | 18 | ||||
| 20 | TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $0-0 | 19 | TEXT x_cgo_thread_start_trampoline(SB), NOSPLIT, $0-0 | ||
| 21 | - | MOVD R0, 8(RSP) | |||
| 22 | MOVD ·x_cgo_thread_start_call(SB), R26 | 20 | MOVD ·x_cgo_thread_start_call(SB), R26 | ||
| 23 | MOVD (R26), R2 | 21 | MOVD (R26), R2 | ||
| 24 | CALL (R2) | 22 | CALL (R2) | ||
| 25 | RET | 23 | RET | ||
| 26 | 24 | ||||
| 27 | TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $0-0 | 25 | TEXT x_cgo_setenv_trampoline(SB), NOSPLIT, $0-0 | ||
| 28 | - | MOVD R0, 8(RSP) | |||
| 29 | MOVD ·x_cgo_setenv_call(SB), R26 | 26 | MOVD ·x_cgo_setenv_call(SB), R26 | ||
| 30 | MOVD (R26), R2 | 27 | MOVD (R26), R2 | ||
| 31 | CALL (R2) | 28 | CALL (R2) | ||
| 32 | RET | 29 | RET | ||
| 33 | 30 | ||||
| 34 | TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $0-0 | 31 | TEXT x_cgo_unsetenv_trampoline(SB), NOSPLIT, $0-0 | ||
| 35 | - | MOVD R0, 8(RSP) | |||
| 36 | MOVD ·x_cgo_unsetenv_call(SB), R26 | 32 | MOVD ·x_cgo_unsetenv_call(SB), R26 | ||
| 37 | MOVD (R26), R2 | 33 | MOVD (R26), R2 | ||
| 38 | CALL (R2) | 34 | CALL (R2) | ||