Skip to content

Instantly share code, notes, and snippets.

@invidian
Created December 3, 2021 17:03
Show Gist options
  • Save invidian/1a01bccc50ce59b5d64891df245ae2a0 to your computer and use it in GitHub Desktop.
Save invidian/1a01bccc50ce59b5d64891df245ae2a0 to your computer and use it in GitHub Desktop.
Golang hello world syscalls

Obtained using:

$ cat <<EOF > main.go
> package main

import "fmt"

func main() {
        fmt.Println("vim-go")
}
EOF
CGO_ENABLED=0 go build -trimpath -ldflags '-w -extldflags "-static"' main.go
strace ./main 2>&1 | grep '(' | cut -d'(' -f1 | sort -u

Result with some explanation:

arch_prctl        # Use 64 bits for thread local storage.
clone             # Creates new process. Required for threading.
close             # Closing file descriptor. Used for reading files, network connections etc.
execve            # Executes program. Used to spawn the main process.
exit_group        # Termiate all threads in thread's group.
fcntl             # Gets file descriptor access mode and status flags. Done for stdin (fd 0), stdout (fd 1) and stderr (fd 2).
futex             # To implement locking.
gettid            # Returns thread ID. Used for threading.
mmap              # For memory allocation?
openat            # For reading files.
read              # Read from file descriptor. For reading file contents.
rt_sigaction      # Examine and change a signal action. For signal handling.
rt_sigprocmask    # Examine and change blocked signals. For briefly blocking the signals.
rt_sigreturn      # Return from signal handler.
sched_getaffinity # Sets CPU affinity.
sigaltstack       # Register alterate stack. For handling panics.
write             # Write to fd. Used for printing to stdout for example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment