From a29e1d43f151f50adbc49cfcc228654dcc102576 Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Sat, 22 Jan 2022 19:39:29 +0000 Subject: [PATCH] Kludge: provide stub for syscall.seek on 386 and arm, #1906 This replaces an earlier kludge which was at the wrong level and caused "GOARCH=386 tinygo test os" to fail to compile on linux. Stubbing just the one missing function, syscall.seek, lets os tests compile on linux 386, and skipping tests of seek and Fstat (which has a cryptic dependency on syscall.Seek via time) lets os tests pass on linux 386. The stub can be removed once tinygo implements go assembly and picks up the real definition. --- src/os/file_other.go | 4 ---- src/os/os_anyos_test.go | 4 ++++ src/os/os_test.go | 4 ++++ src/os/seek_unix_bad.go | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/os/seek_unix_bad.go diff --git a/src/os/file_other.go b/src/os/file_other.go index e03c2b4f..7a0ebb89 100644 --- a/src/os/file_other.go +++ b/src/os/file_other.go @@ -62,10 +62,6 @@ func Pipe() (r *File, w *File, err error) { return nil, nil, ErrNotImplemented } -func (f *File) Seek(offset int64, whence int) (ret int64, err error) { - return 0, ErrNotImplemented -} - func Readlink(name string) (string, error) { return "", ErrNotImplemented } diff --git a/src/os/os_anyos_test.go b/src/os/os_anyos_test.go index 20328bc8..9a587968 100644 --- a/src/os/os_anyos_test.go +++ b/src/os/os_anyos_test.go @@ -60,6 +60,10 @@ func equal(name1, name2 string) (r bool) { } func TestFstat(t *testing.T) { + if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { + t.Log("TODO: implement fstat for 386 and arm") + return + } sfname := "TestFstat" path := TempDir() + "/" + sfname payload := writeFile(t, path, O_CREATE|O_TRUNC|O_RDWR, "Hello") diff --git a/src/os/os_test.go b/src/os/os_test.go index deef509a..bf1a1735 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -89,6 +89,10 @@ func checkMode(t *testing.T, path string, mode FileMode) { } func TestSeek(t *testing.T) { + if runtime.GOARCH == "386" || runtime.GOARCH == "arm" { + t.Log("TODO: implement seek for 386 and arm") + return + } f := newFile("TestSeek", t) if f == nil { t.Fatalf("f is nil") diff --git a/src/os/seek_unix_bad.go b/src/os/seek_unix_bad.go new file mode 100644 index 00000000..a242950c --- /dev/null +++ b/src/os/seek_unix_bad.go @@ -0,0 +1,22 @@ +// +build linux,!baremetal,386 linux,!baremetal,arm,!wasi + +package os + +import ( + "syscall" +) + +// On linux, we use upstream's syscall package. +// But we do not yet implement Go Assembly, so we don't see a few functions written in assembly there. +// In particular, on i386 and arm, the function syscall.seek is missing, breaking syscall.Seek. +// This in turn causes os.(*File).Seek, time, io/fs, and path/filepath to fail to link. +// +// To temporarly let all the above at least link, provide a stub for syscall.seek. +// This belongs in syscall, but on linux, we use upstream's syscall. +// Remove once we support Go Assembly. +// TODO: make this a non-stub, and thus fix the whole problem? + +//export syscall.seek +func seek(fd int, offset int64, whence int) (newoffset int64, err syscall.Errno) { + return 0, syscall.ENOTSUP +}