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

Support for x86_64 Linux #28

Open
leongross opened this issue May 21, 2024 · 3 comments
Open

Support for x86_64 Linux #28

leongross opened this issue May 21, 2024 · 3 comments

Comments

@leongross
Copy link

There was a discussion in the tinygo slack channel on the functionality of the net package on non-embedded platforms such as regular Linux platforms on x86_64.
What are the current limitations / issues that we have to overcome that we can use the net package for scenarios where tinygo should be run on desktop/servers that run Linux?
As soon as we figured out the issues, I'd be happy to help with the implementation.

@scottfeldman
Copy link
Contributor

@leongross Here's a start; I think this is on the right track...

loader/goroot.go file controls which std lib pkgs get overridden for tinygo, based on target. To build on x86_64, we need to not use the tinygo "net" pkg, but rather use the std lib pkg. I hacked loader/goroot.go to use std lib "net" pkg:

diff --git a/loader/goroot.go b/loader/goroot.go
index ea2f705d..629f1880 100644
--- a/loader/goroot.go
+++ b/loader/goroot.go
@@ -241,14 +241,14 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
                "internal/reflectlite/": false,
                "internal/task/":        false,
                "machine/":              false,
-               "net/":                  true,
-               "net/http/":             false,
+               //"net/":                  true,
+               //"net/http/":             false,

        }

I then tried building a test app using (note the -tags netgo). It built, but getting linker errors:

$ ~/go/bin/tinygo build -tags netgo  main.go
ld.lld-17: error: undefined symbol: internal/poll.runtime_pollReset
>>> referenced by fd_poll_runtime.go:68 (/usr/local/go/src/internal/poll/fd_poll_runtime.go:68)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:((*internal/poll.pollDesc).prepare)

ld.lld-17: error: undefined symbol: internal/poll.runtime_pollWait
>>> referenced by fd_poll_runtime.go:84 (/usr/local/go/src/internal/poll/fd_poll_runtime.go:84)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:((*internal/poll.pollDesc).wait)

ld.lld-17: error: undefined symbol: internal/poll.runtime_pollSetDeadline
>>> referenced by fd_poll_runtime.go:161 (/usr/local/go/src/internal/poll/fd_poll_runtime.go:161)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:(internal/poll.setDeadlineImpl)

ld.lld-17: error: undefined symbol: getrandom
>>> referenced by os_linux.go:125 (/home/sfeldma/work/tinygo/src/runtime/os_linux.go:125)
>>>               /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:((*net.Resolver).exchange)
error: failed to link /tmp/tinygo3732967082/main: exit status 1

So the next thing to figure out is why internal/poll didnt' get picked up.

Here's the test app:

package main

import (
        "fmt"
        "net"
)

func main() {
        conn, err := net.Dial("tcp", "localhost")
        if err != nil {
                fmt.Println(err)
        }
        conn.Close()
}

@scottfeldman
Copy link
Contributor

Also, on a parallel topic, there is an effort to use the full "net" pkg with embedded targets. See tinygo-org/tinygo#4187.

@leongross
Copy link
Author

I did some work to enable the sys/unix package syscalls tinygo-org/tinygo#4310. @scottfeldman feel free to have look there as well

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

No branches or pull requests

2 participants