Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for NetBSD #249

Open
6 tasks
0-wiz-0 opened this issue May 17, 2024 · 14 comments
Open
6 tasks

Add support for NetBSD #249

0-wiz-0 opened this issue May 17, 2024 · 14 comments
Labels
enhancement New feature or request

Comments

@0-wiz-0
Copy link

0-wiz-0 commented May 17, 2024

PureGo Version

6cd1224

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • Android
  • iOS

Go Version (go version)

1.21.10

What steps will reproduce the problem?

I wanted to track down a build problem in an older version, but started with building main, and it didn't build:

$ go121  build .                                                                                                                                                                                                   # github.com/ebitengine/purego
./struct_amd64.go:12:46: undefined: syscall15Args

What is the expected result?

Successful build.

What happens instead?

see above.

Anything else you feel useful to add?

That's on NetBSD/amd64.

@0-wiz-0 0-wiz-0 added the bug Something isn't working label May 17, 2024
@TotallyGamerJet
Copy link
Collaborator

NetBSD isn't supported so this is a feature request?

@0-wiz-0
Copy link
Author

0-wiz-0 commented May 17, 2024

I have no idea if that version did anything, but since 0.5.0 built on NetBSD I thought it was a regression.
Yes, please, let's make this a feature request then :)

@0-wiz-0
Copy link
Author

0-wiz-0 commented May 17, 2024

I have started adding the dlfcn_* code for NetBSD based on the FreeBSD one here, but that still fails to build with

./struct_amd64.go:12:46: undefined: syscall15Args

and I have no idea what to do about that.

@TotallyGamerJet
Copy link
Collaborator

and I have no idea what to do about that.

You have to add netbsd to the build tag in syscall.go

@TotallyGamerJet
Copy link
Collaborator

I have no idea if that version did anything, but since 0.5.0 built on NetBSD I thought it was a regression.

We probably added build tags to ensure that only the supported platforms actually build which we were missing before.

@TotallyGamerJet TotallyGamerJet added enhancement New feature or request and removed bug Something isn't working labels May 17, 2024
@0-wiz-0
Copy link
Author

0-wiz-0 commented May 17, 2024

I've added netbsd to three files but I got a missing syscall15X and now missing runtime_cgocall and numOfIntegerRegisters. Does the current version work on FreeBSD?
I'm out of my depth hear.

@TotallyGamerJet
Copy link
Collaborator

You are just missing build tags. Add netbsd to the //go:build at the top of the files

@TotallyGamerJet TotallyGamerJet changed the title NetBSD build problem Add support for NetBSD May 17, 2024
@0-wiz-0
Copy link
Author

0-wiz-0 commented May 17, 2024

Ok, adding lots of tags makes it build. Yay! I've pushed them to my fork.

go test reports:

# github.com/ebitengine/purego
package github.com/ebitengine/purego_test
        imports github.com/ebitengine/purego/internal/load: build constraints exclude all Go files in /archive/foreign/purego-fork/internal/load
FAIL    github.com/ebitengine/purego [setup failed]

@0-wiz-0
Copy link
Author

0-wiz-0 commented May 17, 2024

I've added the netbsd tag to the libc example and tried to run it, but:

./libc
fatal error: cgocall nil

goroutine 1 [running]:
runtime.throw({0x48a7c6?, 0x1?})
        /usr/pkg/go121/src/runtime/panic.go:1077 +0x5c fp=0xc0000cd4a8 sp=0xc0000cd478 pc=0x4304dc
runtime.cgocall(0x0?, 0xc000014160?)
        /usr/pkg/go121/src/runtime/cgocall.go:130 +0xc5 fp=0xc0000cd4e0 sp=0xc0000cd4a8 pc=0x4045a5
github.com/ebitengine/purego.RegisterFunc.func4({0xc0000c4390?, 0x2?, 0x2?})
        /archive/foreign/purego-fork/func.go:319 +0xc5f fp=0xc0000cd960 sp=0xc0000cd4e0 pc=0x46eadf
reflect.callReflect(0xc0000c4180, 0xc0000cdec0, 0xc0000cdd98, 0xc0000cdda0)
        /usr/pkg/go121/src/reflect/value.go:782 +0x54b fp=0xc0000cdd48 sp=0xc0000cd960 pc=0x46764b
reflect.callReflect(0xc0000c4180, 0xc0000cdec0, 0xc0000cdd98, 0xc0000cdda0)
        <autogenerated>:1 +0x45 fp=0xc0000cdd78 sp=0xc0000cdd48 pc=0x46b625
reflect.makeFuncStub()
        /usr/pkg/go121/src/reflect/asm_amd64.s:47 +0x6e fp=0xc0000cdec0 sp=0xc0000cdd78 pc=0x46b0ae
github.com/ebitengine/purego.Dlopen({0x48a100?, 0x404585?}, 0x4010cf?)
        /archive/foreign/purego-fork/dlfcn.go:37 +0x1f fp=0xc0000cdef8 sp=0xc0000cdec0 pc=0x46d6ff
main.openLibrary(...)
        /archive/foreign/purego-fork/examples/libc/main_unix.go:11
main.main()
        /archive/foreign/purego-fork/examples/libc/main.go:33 +0x29 fp=0xc0000cdf40 sp=0xc0000cdef8 pc=0x471109
runtime.main()
        /usr/pkg/go121/src/runtime/proc.go:267 +0x2bb fp=0xc0000cdfe0 sp=0xc0000cdf40 pc=0x432ebb
runtime.goexit()
        /usr/pkg/go121/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000cdfe8 sp=0xc0000cdfe0 pc=0x45b941

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/pkg/go121/src/runtime/proc.go:398 +0xce fp=0xc000084fa8 sp=0xc000084f88 pc=0x43330e
runtime.goparkunlock(...)
        /usr/pkg/go121/src/runtime/proc.go:404
runtime.forcegchelper()
        /usr/pkg/go121/src/runtime/proc.go:322 +0xb3 fp=0xc000084fe0 sp=0xc000084fa8 pc=0x433193
runtime.goexit()
        /usr/pkg/go121/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000084fe8 sp=0xc000084fe0 pc=0x45b941
created by runtime.init.6 in goroutine 1
        /usr/pkg/go121/src/runtime/proc.go:310 +0x1a

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/pkg/go121/src/runtime/proc.go:398 +0xce fp=0xc000085778 sp=0xc000085758 pc=0x43330e
runtime.goparkunlock(...)
        /usr/pkg/go121/src/runtime/proc.go:404
runtime.bgsweep(0x0?)
        /usr/pkg/go121/src/runtime/mgcsweep.go:280 +0x94 fp=0xc0000857c8 sp=0xc000085778 pc=0x420954
runtime.gcenable.func1()
        /usr/pkg/go121/src/runtime/mgc.go:200 +0x25 fp=0xc0000857e0 sp=0xc0000857c8 pc=0x415b05
runtime.goexit()
        /usr/pkg/go121/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000857e8 sp=0xc0000857e0 pc=0x45b941
created by runtime.gcenable in goroutine 1
        /usr/pkg/go121/src/runtime/mgc.go:200 +0x66

goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc0000aa000?, 0x4a71e0?, 0x1?, 0x0?, 0xc0000071e0?)
        /usr/pkg/go121/src/runtime/proc.go:398 +0xce fp=0xc000085f70 sp=0xc000085f50 pc=0x43330e
runtime.goparkunlock(...)
        /usr/pkg/go121/src/runtime/proc.go:404
runtime.(*scavengerState).park(0x50c6c0)
        /usr/pkg/go121/src/runtime/mgcscavenge.go:425 +0x49 fp=0xc000085fa0 sp=0xc000085f70 pc=0x41e229
runtime.bgscavenge(0x0?)
        /usr/pkg/go121/src/runtime/mgcscavenge.go:653 +0x3c fp=0xc000085fc8 sp=0xc000085fa0 pc=0x41e7bc
runtime.gcenable.func2()
        /usr/pkg/go121/src/runtime/mgc.go:201 +0x25 fp=0xc000085fe0 sp=0xc000085fc8 pc=0x415aa5
runtime.goexit()
        /usr/pkg/go121/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc000085fe8 sp=0xc000085fe0 pc=0x45b941
created by runtime.gcenable in goroutine 1
        /usr/pkg/go121/src/runtime/mgc.go:201 +0xa5

goroutine 5 [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/pkg/go121/src/runtime/proc.go:398 +0xce fp=0xc000086620 sp=0xc000086600 pc=0x43330e
runtime.runfinq()
        /usr/pkg/go121/src/runtime/mfinal.go:193 +0x107 fp=0xc0000867e0 sp=0xc000086620 pc=0x414b27
runtime.goexit()
        /usr/pkg/go121/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc0000867e8 sp=0xc0000867e0 pc=0x45b941
created by runtime.createfing in goroutine 1
        /usr/pkg/go121/src/runtime/mfinal.go:163 +0x3d

@TotallyGamerJet
Copy link
Collaborator

Ok, adding lots of tags makes it build. Yay! I've pushed them to my fork.

go test reports:


# github.com/ebitengine/purego

package github.com/ebitengine/purego_test

        imports github.com/ebitengine/purego/internal/load: build constraints exclude all Go files in /archive/foreign/purego-fork/internal/load

FAIL    github.com/ebitengine/purego [setup failed]

It's telling you that you are missing a build tag in that file.

@0-wiz-0
Copy link
Author

0-wiz-0 commented May 18, 2024

I tried looking at all files with build tags. I think I found a problem for FreeBSD (because it affects NetBSD too).

#cgo LDFLAGS: -ldl

#cgo LDFLAGS: -ldl

both have

 #cgo LDFLAGS: -ldl

but *BSD do not provide this library, the dl*() functions are in libc.
What's the proper go way to conditionalize this without making complete copies of the files?

@TotallyGamerJet
Copy link
Collaborator

Well build tags in the Cgo comment can be used.

The directive can include a list of build constraints limiting its effect to systems satisfying one of the constraints

https://pkg.go.dev/cmd/cgo

I'm a little confused as FreeBSD is tested in CI and it passes with the current code

@0-wiz-0
Copy link
Author

0-wiz-0 commented May 18, 2024

I have no clue why it works on FreeBSD in CI.

Thanks, that worked. I've pushed my changes to the fork.
It builds now, but segfaults when I run go test.
log.txt

@JupiterRider
Copy link
Contributor

I just want to let you know, that I do not have any issues with purego and FreeBSD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants