Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion builder/darwin-libsystem.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
package builder

import (
"os"
"path/filepath"
"strings"

"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/goenv"
)

// Symbols that libSystem exports but the minimal macOS SDK in
// lib/macos-minimal-sdk does not declare. Its generator reads a fixed list of
// headers that does not contain <spawn.h>, so these names are absent from the
// generated libSystem.s. The stubs below have the same form as the generated
// ones, because the linker only needs to know that the names are in
// libSystem.B.dylib.
var darwinExtraLibSystemSymbols = []string{
// The posix_spawn family, which src/os uses to start processes.
// posix_spawn_file_actions_addchdir_np came with macOS 10.15, so a binary
// from this toolchain needs at least that release.
"posix_spawn",
"posix_spawn_file_actions_addchdir_np",
"posix_spawn_file_actions_addclose",
"posix_spawn_file_actions_adddup2",
"posix_spawn_file_actions_destroy",
"posix_spawn_file_actions_init",
"posix_spawnattr_destroy",
"posix_spawnattr_init",
"posix_spawnattr_setflags",
"posix_spawnattr_setpgroup",
"posix_spawnattr_setsigmask",
}

// Create a job that builds a Darwin libSystem.dylib stub library. This library
// contains all the symbols needed so that we can link against it, but it
// doesn't contain any real symbol implementations.
Expand Down Expand Up @@ -36,7 +60,34 @@ func makeDarwinLibSystemJob(config *compileopts.Config, tmpdir string) *compileJ
return err
}

// Link object file to dynamic library.
// Compile the extra stubs into a second object file, so that the
// generated one stays as it is.
extrapath := filepath.Join(tmpdir, "libSystem-extra.s")
extraobjpath := filepath.Join(tmpdir, "libSystem-extra.o")
var extra strings.Builder
extra.WriteString("// Stubs for symbols exported by libSystem but not declared in lib/macos-minimal-sdk.\n")
for _, symbol := range darwinExtraLibSystemSymbols {
extra.WriteString("\n.global _" + symbol + "\n_" + symbol + ":\n")
}
if err := os.WriteFile(extrapath, []byte(extra.String()), 0o666); err != nil {
return err
}
flags = []string{
"-nostdlib",
"--target=" + config.Triple(),
"-c",
"-o", extraobjpath,
extrapath,
}
if config.Options.PrintCommands != nil {
config.Options.PrintCommands("clang", flags...)
}
err = runCCompiler(flags...)
if err != nil {
return err
}

// Link object files to dynamic library.
platformVersion := strings.TrimPrefix(strings.Split(config.Triple(), "-")[2], "macosx")
flags = []string{
"-flavor", "darwin",
Expand All @@ -48,6 +99,7 @@ func makeDarwinLibSystemJob(config *compileopts.Config, tmpdir string) *compileJ
"-install_name", "/usr/lib/libSystem.B.dylib",
"-o", job.result,
objpath,
extraobjpath,
}
if config.Options.PrintCommands != nil {
config.Options.PrintCommands("ld.lld", flags...)
Expand Down
5 changes: 5 additions & 0 deletions compiler/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ func (b *builder) createDarwinFuncPCABI0Call(instr *ssa.CallCommon) llvm.Value {
// in C.
name = "syscall_libc_open"
}
if name == "fcntl" {
// Same for fcntl(), whose third parameter is variadic. See
// src/runtime/os_darwin.c for what goes wrong without the wrapper.
name = "syscall_libc_fcntl"
}
if b.GOARCH == "amd64" {
if name == "fdopendir" || name == "readdir_r" {
// Hack to support amd64, which needs the $INODE64 suffix.
Expand Down
49 changes: 7 additions & 42 deletions src/os/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"syscall"
)

// Errors StartProcess returns for a ProcAttr that it cannot honour. On a
// hosted OS only ErrNotImplementedSys is reachable. The other two stay because
// they are part of the exported API of this package.
var (
ErrNotImplementedDir = errors.New("directory setting not implemented")
ErrNotImplementedSys = errors.New("sys setting not implemented")
Expand Down Expand Up @@ -36,35 +39,12 @@ type ProcAttr struct {
// ErrProcessDone indicates a Process has finished.
var ErrProcessDone = errors.New("os: process already finished")

type ProcessState struct {
}

func (p *ProcessState) String() string {
return "" // TODO
}
func (p *ProcessState) Success() bool {
return false // TODO
}

// Sys returns system-dependent exit information about
// the process. Convert it to the appropriate underlying
// type, such as syscall.WaitStatus on Unix, to access its contents.
func (p *ProcessState) Sys() interface{} {
return nil // TODO
}

func (p *ProcessState) Exited() bool {
return false // TODO
}

// ExitCode returns the exit code of the exited process, or -1
// if the process hasn't exited or was terminated by a signal.
func (p *ProcessState) ExitCode() int {
return -1 // TODO
}

type Process struct {
Pid int

// done reports whether Wait reaped this process. A signal to a reaped pid
// is unsafe, because the number can belong to an unrelated process.
done int32
}

// StartProcess starts a new process with the program, arguments and attributes specified by name, argv and attr.
Expand All @@ -73,21 +53,6 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)
return startProcess(name, argv, attr)
}

func (p *Process) Wait() (*ProcessState, error) {
if p.Pid == -1 {
return nil, syscall.EINVAL
}
return nil, ErrNotImplemented
}

func (p *Process) Kill() error {
return ErrNotImplemented
}

func (p *Process) Signal(sig Signal) error {
return ErrNotImplemented
}

func Ignore(sig ...Signal) {
// leave all the signals unaltered
return
Expand Down
103 changes: 0 additions & 103 deletions src/os/exec_linux.go

This file was deleted.

78 changes: 0 additions & 78 deletions src/os/exec_linux_test.go

This file was deleted.

Loading