Skip to content

Commit

Permalink
Save R15 before global access (#255)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TotallyGamerJet authored Jun 20, 2024
1 parent 8ebc748 commit 573eba0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
run: |
go vet -v ./...
- name: go build plugin
if: runner.os == 'Linux' || runner.os == 'macOS'
run:
# Make sure that plugin buildmode works since we save the R15 register (#254)
go build -buildmode=plugin ./examples/libc

- name: go build
run: |
go build -v ./...
Expand Down Expand Up @@ -97,6 +103,11 @@ jobs:
env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
echo "=> go build plugin"
# Make sure that plugin buildmode works since we save the R15 register (#254)
env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -buildmode=plugin ./examples/libc
go env -u CC
go env -u CXX
Expand Down Expand Up @@ -147,6 +158,10 @@ jobs:
# verify Go is available
go version
echo "=> go build plugin"
# Make sure that plugin buildmode works since we save the R15 register (#254)
go build -buildmode=plugin ./examples/libc
echo "=> go build"
go build -v ./...
Expand Down
6 changes: 3 additions & 3 deletions sys_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0

PUSHQ R10 // push the stack pointer below registers

// Switch from the host ABI to the Go ABI.
PUSH_REGS_HOST_TO_ABI0()

// determine index into runtime·cbs table
MOVQ $callbackasm(SB), DX
SUBQ DX, AX
Expand All @@ -130,9 +133,6 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
DIVL CX
SUBQ $1, AX // subtract 1 because return PC is to the next slot

// Switch from the host ABI to the Go ABI.
PUSH_REGS_HOST_TO_ABI0()

// Create a struct callbackArgs on our stack to be passed as
// the "frame" to cgocallback and on to callbackWrap.
// $24 to make enough room for the arguments to runtime.cgocallback
Expand Down

0 comments on commit 573eba0

Please sign in to comment.