From abf842a4a5d244d69770a0199b601aa23897c7d7 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Mon, 17 Jun 2024 18:02:28 -0400 Subject: [PATCH 1/4] Move saving of registers to before we get the address of a global variable 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. --- .github/workflows/test.yml | 3 +++ sys_amd64.s | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6813d8be..4ae91c01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,6 +46,9 @@ jobs: # The option '-gcflags=all=-N -l' is often used at Visual Studio Code. # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120. go build "-gcflags=all=-N -l" -v ./... + + # Make sure that plugin build mode works since we save the R15 register (#254) + go build -buildmode=plugin ./examples/libc # Check cross-compiling Windows binaries. env GOOS=windows GOARCH=386 go build -v ./... diff --git a/sys_amd64.s b/sys_amd64.s index 4eb26d65..cabde1a5 100644 --- a/sys_amd64.s +++ b/sys_amd64.s @@ -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 @@ -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 From dcc0e6bac3f98fe24144987b93a22f24c806856f Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Mon, 17 Jun 2024 18:09:05 -0400 Subject: [PATCH 2/4] Move test just for Linux --- .github/workflows/test.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4ae91c01..2f4dcc43 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,12 @@ jobs: run: | go vet -v ./... + - name: go build plugin + if: runner.os == 'Linux' + 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 ./... @@ -46,9 +52,6 @@ jobs: # The option '-gcflags=all=-N -l' is often used at Visual Studio Code. # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120. go build "-gcflags=all=-N -l" -v ./... - - # Make sure that plugin build mode works since we save the R15 register (#254) - go build -buildmode=plugin ./examples/libc # Check cross-compiling Windows binaries. env GOOS=windows GOARCH=386 go build -v ./... From 27be5b840ffaff5d76348108f834c6ca51211183 Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Wed, 19 Jun 2024 17:20:22 -0400 Subject: [PATCH 3/4] add macOS, Freebsd, and arm Linux --- .github/workflows/test.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2f4dcc43..0d94d4d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: go vet -v ./... - name: go build plugin - if: runner.os == 'Linux' + 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 @@ -103,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) + go build -buildmode=plugin ./examples/libc + go env -u CC go env -u CXX @@ -153,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 ./... From 23986b90047afb61df3d7988ac75a284f9a023ac Mon Sep 17 00:00:00 2001 From: TotallyGamerJet Date: Wed, 19 Jun 2024 17:22:18 -0400 Subject: [PATCH 4/4] add cgo --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0d94d4d3..aa77afc4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -106,7 +106,7 @@ jobs: echo "=> go build plugin" # Make sure that plugin buildmode works since we save the R15 register (#254) - go build -buildmode=plugin ./examples/libc + env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go build -buildmode=plugin ./examples/libc go env -u CC go env -u CXX