tinygo-org / net

Port of Go's "net" package to work with TinyGo on embedded processors.
https://tinygo.org
BSD 2-Clause "Simplified" License
23 stars 9 forks source link

Add support for golang.org/x/net/internal/socket #14

Open scottfeldman opened 11 months ago

scottfeldman commented 11 months ago

Damian Gryski wrote:

Will any of the netdev stuff help with stubbing out the net package, so that things like

golang.org/x/net/internal/socket

../../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/rawconn.go:27:17: cannot use (net.TCPConn)(nil) (value of type net.TCPConn) as tcpConn value in variable declaration: *net.TCPConn does not implement tcpConn (missing method SetLinger) ../../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/rawconn.go:36:23: undefined: net.UDPConn ../../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/rawconn.go:45:22: undefined: net.IPConn

Need to port/stub out the missing pieces.

scottfeldman commented 11 months ago

Also reported by Randy Reddig on Slack. He gave this this test to repo issue:

sfeldma@nuc:~/work$ git clone https://github.com/domainr/dnsr.git
Cloning into 'dnsr'...
remote: Enumerating objects: 1724, done.
remote: Counting objects: 100% (376/376), done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 1724 (delta 309), reused 254 (delta 245), pack-reused 1348
Receiving objects: 100% (1724/1724), 316.26 KiB | 1.76 MiB/s, done.
Resolving deltas: 100% (1052/1052), done.
sfeldma@nuc:~/work$ cd dnsr
sfeldma@nuc:~/work/dnsr$ go work use .
sfeldma@nuc:~/work/dnsr$ tinygo test
go: downloading github.com/miekg/dns v1.1.57
go: downloading golang.org/x/net v0.19.0
go: downloading golang.org/x/sys v0.15.0
go: downloading github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32
FAIL    github.com/domainr/dnsr 0.000s
# golang.org/x/net/internal/socket
../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/rawconn.go:27:17: cannot use (*net.TCPConn)(nil) (value of type *net.TCPConn) as tcpConn value in variable declaration: *net.TCPConn does not implement tcpConn (missing method SetLinger)
../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/rawconn.go:36:17: cannot use (*net.UDPConn)(nil) (value of type *net.UDPConn) as udpConn value in variable declaration: *net.UDPConn does not implement udpConn (missing method ReadMsgUDP)
../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/rawconn.go:45:22: undefined: net.IPConn
../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/sys_posix.go:127:43: undefined: net.Interface
../../go/pkg/mod/golang.org/x/net@v0.19.0/internal/socket/sys_posix.go:137:21: undefined: net.Interfaces
scottfeldman commented 11 months ago

Ok, I've stubbed out a lot of stuff in src/net and src/crypto so dnsr tinygo test compiles, but now getting undefined symbols on link:

sfeldma@nuc:~/work/dnsr$ tinygo test
ld.lld-16: error: undefined symbol: crypto/subtle.xorBytes
>>> referenced by xor.go:22 (/usr/local/go/src/crypto/subtle/xor.go:22)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((crypto/cipher.StreamReader).Read)

ld.lld-16: error: undefined symbol: crypto/aes.encryptBlockAsm
>>> referenced by cipher_asm.go:81 (/usr/local/go/src/crypto/aes/cipher_asm.go:81)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/aes.aesCipherAsm).Encrypt)

ld.lld-16: error: undefined symbol: crypto/internal/edwards25519/field.feSquare
>>> referenced by fe.go:309 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:309)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/internal/edwards25519.Point).SetBytes)
>>> referenced by fe.go:309 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:309)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/internal/edwards25519.Point).SetBytes)
>>> referenced by fe.go:309 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:309)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/internal/edwards25519.Point).SetBytes)
>>> referenced 21 more times

ld.lld-16: error: undefined symbol: crypto/internal/edwards25519/field.feMul
>>> referenced by fe.go:303 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:303)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/internal/edwards25519.Point).SetBytes)
>>> referenced by fe.go:303 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:303)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/internal/edwards25519.Point).SetBytes)
>>> referenced by fe.go:303 (/usr/local/go/src/crypto/internal/edwards25519/field/fe.go:303)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-42E97D33C4936406C74B6B10925F4C503BF6B817:((*crypto/internal/edwards25519.Point).SetBytes)
>>> referenced 17 more times
FAIL    github.com/domainr/dnsr 0.000s
error: failed to link /tmp/tinygo1198081133/main: exit status 1

Not sure how to resolve these at the moment...

scottfeldman commented 11 months ago

I've create two PRs to capture the work on this Issue so far:

tinygo-org/tinygo/pull/4035 (the crypto/tls changes) tinygo-org/net/pull/16 (the src/net changes)

scottfeldman commented 11 months ago

Closing those PRs until we can figure out to get passed the link failures above

scottfeldman commented 11 months ago

Ok, Damian Gryski gave me the hint to get past the link failure above.

sfeldma@nuc:~/work/dnsr$ tinygo test -target=wasi
error: could not find wasm-opt, set the WASMOPT environment variable to override

I'll re-submit PRs for tinygo and tinygo/net.