test.rb:

puts "hello world\n"

0.04s real, 1,403 syscalls, 12.83 MiB of disk space required

test.py:

print("hello world")

0.02s real, 1,202 syscalls, 151 MiB of disk space required

Show thread

test.c (glibc):

int puts(const char *s);

int main(int argc, char *argv[]) {
puts("hello world");
}

0s real, 67 syscalls, 46 MiB of disk space required (glibc cannot be statically linked) + 14 KiB for stripped binary

Show thread

test.c (musl libc):

int puts(const char *s);

int main(int argc, char *argv[]) {
puts("hello world");
}

0s real, 7 syscalls, 14 KiB of disk space required

Show thread

test.S (linux):

section .text
global _start
_start:
mov rdx, len
mov rsi, msg
mov rdi, 1
mov rax, 1
syscall

mov rdi, 0
mov rax, 60
syscall

section .rodata
msg: db "hello world", 10
len: equ $-msg

0s real, 2 syscalls, 8.5 KiB of disk space required

Size of the instructions + data without the ELF wrapper: 52 bytes

Show thread

@steph aye, which actually gets one too many syscalls but w/e

@sir

test.cr (musl libc)

puts "Hello World"

0s real, 183 syscalls, 867.2KiB for stripped binary

so, better than go, which is something

@steph what commands do I use to build this, and the static version?

@sir crystal build test.cr

crystal build --static test.cr

obviously the latter fails on glibc because glibc is a trashfire

@steph save me a little bit of effort, how many unique syscalls for both versions?

@sir

non-static musl (26 syscalls)

1 arch_prctl
1 clock_gettime
1 execve
1 exit_group
1 getcwd
1 membarrier
1 pipe
1 set_tid_address
1 sigaltstack
1 write
2 brk
2 getrandom
2 ioctl
2 madvise
3 clone
3 fstat
4 close
4 read
8 futex
10 mprotect
10 rt_sigaction
11 fcntl
11 open
13 rt_sigprocmask
22 mmap
64 mremap

static musl (24 syscalls)

1 arch_prctl
1 clock_gettime
1 close
1 execve
1 exit_group
1 getcwd
1 open
1 pipe
1 read
1 set_tid_address
1 sigaltstack
1 write
2 getrandom
2 ioctl
2 madvise
3 brk
3 clone
5 mprotect
8 fcntl
8 futex
10 mmap
10 rt_sigaction
13 rt_sigprocmask
64 mremap

@steph what is the size of the dynamic binary including any files required at runtime (libc, loader, etc)?

@sir

868.0K ./test
580.0K /lib/ld-musl-x86_64.so.1
4.0K /usr/lib/libpcre.so.1
4.0K /usr/lib/libevent-2.1.so.7
76.0K /usr/lib/libgcc_s.so.1
580.0K /lib/ld-musl-x86_64.so.1

2.1MiB
Follow

@sir @steph sorry to hop in thread like that, system rookie wanting to know if syscall actually are Linux kernel stuff or more baremetal stuff to the cpu?

I know they go trough kernels but wondered this

@Miaourt @sir they're function calls to the kernel. CPU facilitates them, but doesn't interpret them. They're "essentially" just functions you call in user-land and which are implemented in kernel-land.

@Miaourt @steph syscall behavior is implemented by the kernel, but the CPU is involved in moving control from userspace to the kernel

@Miaourt @sir @steph "yes"

syscalls are generally done via a cpu instruction, but it's a request for the kernel to do something

Sign in to participate in the conversation
niu.moe

Welcome to your niu world ! We are a cute and loving international community O(≧▽≦)O !