Save R15 before global access (#255)
In -buildmode=plugin R15 is used when accessing global variables but we need to save it since we are actually called from C code. We save the R15 register before we access any globals to avoid clobbering the register. Closes #254
- commit
- 573eba027cb6d037833ae1fdb23bca0228ac0e4c
- author
- TotallyGamerJet · · 2024-06-20 02:45 UTC
- committer
- GitHub · · 2024-06-20 02:45 UTC
- parent
- 8ebc748
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown
2 files · +18 -3
M .github/workflows/test.yml +15 -0
| @@ -39,6 +39,12 @@ jobs: | |||
| 39 | 39 | run: | | |
| 40 | 40 | go vet -v ./... | |
| 41 | 41 | ||
| 42 | + | - name: go build plugin | |
| 43 | + | if: runner.os == 'Linux' || runner.os == 'macOS' | |
| 44 | + | run: | |
| 45 | + | # Make sure that plugin buildmode works since we save the R15 register (#254) | |
| 46 | + | go build -buildmode=plugin ./examples/libc | |
| 47 | + | ||
| 42 | 48 | - name: go build | |
| 43 | 49 | run: | | |
| 44 | 50 | go build -v ./... | |
| @@ -97,6 +103,11 @@ jobs: | |||
| 97 | 103 | env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 | |
| 98 | 104 | env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo . | |
| 99 | 105 | env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 | |
| 106 | + | ||
| 107 | + | echo "=> go build plugin" | |
| 108 | + | # Make sure that plugin buildmode works since we save the R15 register (#254) | |
| 109 | + | env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -buildmode=plugin ./examples/libc | |
| 110 | + | ||
| 100 | 111 | go env -u CC | |
| 101 | 112 | go env -u CXX | |
| 102 | 113 | ||
| @@ -147,6 +158,10 @@ jobs: | |||
| 147 | 158 | ||
| 148 | 159 | # verify Go is available | |
| 149 | 160 | go version | |
| 161 | + | ||
| 162 | + | echo "=> go build plugin" | |
| 163 | + | # Make sure that plugin buildmode works since we save the R15 register (#254) | |
| 164 | + | go build -buildmode=plugin ./examples/libc | |
| 150 | 165 | ||
| 151 | 166 | echo "=> go build" | |
| 152 | 167 | go build -v ./... | |
| @@ -39,6 +39,12 @@ jobs: | |||||
| 39 | run: | | 39 | run: | | ||
| 40 | go vet -v ./... | 40 | go vet -v ./... | ||
| 41 | 41 | ||||
| 42 | + | - name: go build plugin | |||
| 43 | + | if: runner.os == 'Linux' || runner.os == 'macOS' | |||
| 44 | + | run: | |||
| 45 | + | # Make sure that plugin buildmode works since we save the R15 register (#254) | |||
| 46 | + | go build -buildmode=plugin ./examples/libc | |||
| 47 | + | ||||
| 42 | - name: go build | 48 | - name: go build | ||
| 43 | run: | | 49 | run: | | ||
| 44 | go build -v ./... | 50 | go build -v ./... | ||
| @@ -97,6 +103,11 @@ jobs: | |||||
| 97 | env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 | 103 | env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10 | ||
| 98 | env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo . | 104 | env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo . | ||
| 99 | env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 | 105 | env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10 | ||
| 106 | + | ||||
| 107 | + | echo "=> go build plugin" | |||
| 108 | + | # Make sure that plugin buildmode works since we save the R15 register (#254) | |||
| 109 | + | env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -buildmode=plugin ./examples/libc | |||
| 110 | + | ||||
| 100 | go env -u CC | 111 | go env -u CC | ||
| 101 | go env -u CXX | 112 | go env -u CXX | ||
| 102 | 113 | ||||
| @@ -147,6 +158,10 @@ jobs: | |||||
| 147 | 158 | ||||
| 148 | # verify Go is available | 159 | # verify Go is available | ||
| 149 | go version | 160 | go version | ||
| 161 | + | ||||
| 162 | + | echo "=> go build plugin" | |||
| 163 | + | # Make sure that plugin buildmode works since we save the R15 register (#254) | |||
| 164 | + | go build -buildmode=plugin ./examples/libc | |||
| 150 | 165 | ||||
| 151 | echo "=> go build" | 166 | echo "=> go build" | ||
| 152 | go build -v ./... | 167 | go build -v ./... | ||
M sys_amd64.s +3 -3
| @@ -122,6 +122,9 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||
| 122 | 122 | ||
| 123 | 123 | PUSHQ R10 // push the stack pointer below registers | |
| 124 | 124 | ||
| 125 | + | // Switch from the host ABI to the Go ABI. | |
| 126 | + | PUSH_REGS_HOST_TO_ABI0() | |
| 127 | + | ||
| 125 | 128 | // determine index into runtime·cbs table | |
| 126 | 129 | MOVQ $callbackasm(SB), DX | |
| 127 | 130 | SUBQ DX, AX | |
| @@ -130,9 +133,6 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||
| 130 | 133 | DIVL CX | |
| 131 | 134 | SUBQ $1, AX // subtract 1 because return PC is to the next slot | |
| 132 | 135 | ||
| 133 | - | // Switch from the host ABI to the Go ABI. | |
| 134 | - | PUSH_REGS_HOST_TO_ABI0() | |
| 135 | - | ||
| 136 | 136 | // Create a struct callbackArgs on our stack to be passed as | |
| 137 | 137 | // the "frame" to cgocallback and on to callbackWrap. | |
| 138 | 138 | // $24 to make enough room for the arguments to runtime.cgocallback | |
| @@ -122,6 +122,9 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||||
| 122 | 122 | ||||
| 123 | PUSHQ R10 // push the stack pointer below registers | 123 | PUSHQ R10 // push the stack pointer below registers | ||
| 124 | 124 | ||||
| 125 | + | // Switch from the host ABI to the Go ABI. | |||
| 126 | + | PUSH_REGS_HOST_TO_ABI0() | |||
| 127 | + | ||||
| 125 | // determine index into runtime·cbs table | 128 | // determine index into runtime·cbs table | ||
| 126 | MOVQ $callbackasm(SB), DX | 129 | MOVQ $callbackasm(SB), DX | ||
| 127 | SUBQ DX, AX | 130 | SUBQ DX, AX | ||
| @@ -130,9 +133,6 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0 | |||||
| 130 | DIVL CX | 133 | DIVL CX | ||
| 131 | SUBQ $1, AX // subtract 1 because return PC is to the next slot | 134 | SUBQ $1, AX // subtract 1 because return PC is to the next slot | ||
| 132 | 135 | ||||
| 133 | - | // Switch from the host ABI to the Go ABI. | |||
| 134 | - | PUSH_REGS_HOST_TO_ABI0() | |||
| 135 | - | ||||
| 136 | // Create a struct callbackArgs on our stack to be passed as | 136 | // Create a struct callbackArgs on our stack to be passed as | ||
| 137 | // the "frame" to cgocallback and on to callbackWrap. | 137 | // the "frame" to cgocallback and on to callbackWrap. | ||
| 138 | // $24 to make enough room for the arguments to runtime.cgocallback | 138 | // $24 to make enough room for the arguments to runtime.cgocallback | ||