4 ms·
The binary relies on the runtime, so yes it is nice. Forma instance, a static compiled and linked "hello world" in C on Linux is around ~785KB
by madduci 9mo ago
The binary relies on the runtime, so yes it is nice.
Forma instance, a static compiled and linked "hello world" in C on Linux is around ~785KB
- oguz-ismail2 9mo ago> a static compiled and linked "hello world" in C on Linux is around ~785KB Huh? $ musl-gcc -xc -static -Wl,-z,norelro -Wl,-z,nosectionheader -Wl,-z,noseparate-code -s - <<eof #include <stdio.h> int main(void) { static const char s[] = "Hello, World!\n"; fwrite(s, (sizeof s)-1, 1, stdout); } eof $ ./a.out Hello, World! $ ls -l a.out -rwxr-xr-x 1 oguz oguz 4976 Jan 12 09:38 a.out And if that's not enough $ musl-gcc -xc -static -nostdlib -fcf-protection=none -fno-asynchronous-unwind-tables -fomit-frame-pointer -Wl,-z,norelro -Wl,-z,nosectionheader -Wl,-z,noseparate-code -s - -lc <<eof #include <unistd.h> void _start(void) { static const char s[] = "Hello, World!\n"; write(1, s, (sizeof s)-1); _exit(0); } eof $ ./a.out Hello, World! $ ls -l a.out -rwxr-xr-x 1 oguz oguz 487 Jan 12 09:58 a.out
- PhilipRoman 9mo agoThat's just because glibc is not designed for static linking. It works, but it doesn't exclude unused code, unlike with other libcs.
- ptspts 9mo agoIt does exclude unused code. But glibc has too many inter-object-file dependencies, so too much code gets used.