detached 573eba0

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 UnverifiedB5690EEEBB952194 The key is unknown
2 files · +18 -3
M .github/workflows/test.yml +15 -0
@@ -39,6 +39,12 @@ jobs:
3939 run: |
4040 go vet -v ./...
4141
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+
4248 - name: go build
4349 run: |
4450 go build -v ./...
@@ -97,6 +103,11 @@ jobs:
97103 env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
98104 env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
99105 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+
100111 go env -u CC
101112 go env -u CXX
102113
@@ -147,6 +158,10 @@ jobs:
147158
148159 # verify Go is available
149160 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
150165
151166 echo "=> go build"
152167 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 build48 - 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=10103 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=10105 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 CC111 go env -u CC
101 go env -u CXX112 go env -u CXX
102 113
@@ -147,6 +158,10 @@ jobs:
147 158
148 # verify Go is available159 # verify Go is available
149 go version160 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
122122
123123 PUSHQ R10 // push the stack pointer below registers
124124
125+ // Switch from the host ABI to the Go ABI.
126+ PUSH_REGS_HOST_TO_ABI0()
127+
125128 // determine index into runtime·cbs table
126129 MOVQ $callbackasm(SB), DX
127130 SUBQ DX, AX
@@ -130,9 +133,6 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
130133 DIVL CX
131134 SUBQ $1, AX // subtract 1 because return PC is to the next slot
132135
133- // Switch from the host ABI to the Go ABI.
134- PUSH_REGS_HOST_TO_ABI0()
135-
136136 // Create a struct callbackArgs on our stack to be passed as
137137 // the "frame" to cgocallback and on to callbackWrap.
138138 // $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 registers123 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 table128 // determine index into runtime·cbs table
126 MOVQ $callbackasm(SB), DX129 MOVQ $callbackasm(SB), DX
127 SUBQ DX, AX130 SUBQ DX, AX
@@ -130,9 +133,6 @@ TEXT callbackasm1(SB), NOSPLIT|NOFRAME, $0
130 DIVL CX133 DIVL CX
131 SUBQ $1, AX // subtract 1 because return PC is to the next slot134 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 as136 // 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.cgocallback138 // $24 to make enough room for the arguments to runtime.cgocallback

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close