Consider the following program:
#include <stdio.h>
int main(void)
{
printf("hello world\n");
return 0;
}
If I build it with GCC, optimizing for size, and with static linking, and then strip it for further size minimization (maybe):
$ gcc -Os -static hello.c -o hello
$ strip hello
I get an executable of size ~695 KB.
Why is it so big? I realize it's not just my object code, and that there are stubs and what-not, but still, that's kind of huge.
Notes:
- OS: Devuan GNU/Linux Chimaera (~= Debian Bullseye)
- Compiler: GCC 10.2
- libc: glibc 2.31-13
- Processor architecture: x86_64
- It doesn't improve if I build with
-O3 -flto.
A partial answer: The executable's inflated size...
printf.<stdio.h>.Why? Because even if you compile an empty program:
You still get the same 695 KB executable.
Thanks @SparKot for the comment indicating this direction.