tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

Darwin: linker could not find symbol _syscall.Syscall

Open Tryanks opened this issue 9 months ago • 1 comments

Cannot call the syscall.Syscall() method on MacOS.

  • System Version: MacOS 15.3.1 (24D70)
  • Go Version: 1.24.1
  • Tinygo Version: 0.36.0

Minimal reproducible code:

package main

import (
	"syscall"
)

func main() {
	// Only building is required, not executing them, so this line of code can be used for issue reproduction.
	syscall.Syscall(0, 0, 0, 0)
}

Compilation passes with the command go build; compilation also passes with GOOS=linux tinygo build.
However, compilation fails when directly using tinygo build on MacOS:

❯ tinygo build
main.go:8: linker could not find symbol _syscall.Syscall  

Additional information: This also leads to the following issues:
Package golang.org/x/sys reports an error:

golang.org/x/[email protected]/unix/zsyscall_darwin_arm64.go:734: linker could not find symbol _golang.org/x/sys/unix.syscall_syscall  

Package modernc.org/memory reports an error:

modernc.org/[email protected]/mmap_unix.go:25: linker could not find symbol _syscall.Syscall  

Tryanks avatar Mar 10 '25 11:03 Tryanks

Raw syscalls are not supported on MacOS, and are not documented as far as I know. Go used to use these raw syscalls, but switched to using the system libc instead that are supported. TinyGo also uses the system libc (and not raw syscalls) for the same reason.

If you look at modernc.org/memory for example, you'll see this:

func unmap(addr uintptr, size int) error {
	_, _, errno := syscall.Syscall(syscall.SYS_MUNMAP, addr, uintptr(size), 0)
	if errno != 0 {
		return errno
	}
	return nil
}

This uses the unsupported raw syscalls. They might still work in standard Go, but can break at any time Apple decides to change these syscalls. I think the best solution here would be for the modernc.org/memory package to use syscall.Mmap instead.

As for golang.org/x/sys, that's probably a genuine bug in TinyGo. I'll need to look into it.

aykevl avatar Mar 10 '25 16:03 aykevl