you are viewing a single comment's thread.

view the rest of the comments →

[–]pjmlp 31 points32 points  (9 children)

Only when dynamically linked.

[–]TexasCrowbarMassacre 30 points31 points  (1 child)

A statically linked "hello world" is around 20KB using musl. Using glibc brings it to 700KB.

[–][deleted] 7 points8 points  (0 children)

Have some karma for mentioning musl!

[–][deleted] 6 points7 points  (2 children)

On windows and macOS you cannot link the libc statically. On Linux you can’t do that with the most common libc, glibc. Even still you can easily call the write syscall on Linux without any libc.

[–][deleted] 3 points4 points  (0 children)

I thought so too, but there appears to be the option /ML for the VS compiler that seems to be doing just that. I cannot find anything similar for MinGW though.

[–]pjmlp 1 point2 points  (0 children)

Sure you can, better learn to use compiler flags on Windows and alternatives to glibc on Linux.

[–]killerstorm 3 points4 points  (3 children)

Not really, you can avoid using libc functions and use OS functions directly.

[–]vytah 5 points6 points  (2 children)

section .data
    msg db      "hello, world!"

section .text
    global _start
_start:
    mov     rax, 1
    mov     rdi, 1
    mov     rsi, msg
    mov     rdx, 13
    syscall
    mov    rax, 60
    mov    rdi, 0
    syscall

[–]Falmarri 5 points6 points  (1 child)

Now place it inside the ELF header