r/C_Programming • u/Bullzzie • Oct 19 '25
What could be the smallest c binary possible
what is the smallest c binary possible on linux from gcc compiler I somewhat as far as 4.9k on fedora42
I was just curious what king of c programming can make smallest c binary using just gcc (not other c compiler)
To accomplish 4.9k binary I did cheat by taking the linking process in my hands.
Challenge:
Write the smallest c binary possible on linux using only gcc and a simple text editor.
>NOTE: if the post is not clear the I will edit it.
35
Upvotes
52
u/nekokattt Oct 19 '25
https://stackoverflow.com/a/76705747
This guy got gcc down to 349 bytes using thumb in arm
13
u/AccomplishedSugar490 Oct 19 '25
We used to have this question a lot during the compiler wars, so often that it got listed as one of benchmarks. It was eventually abandoned as far as I recall because the compromises the compiler writers had to make to beat the others on that score inevitably made their runtime libraries inappropriately unsafe for regular use.
It’s the same as saying that the only bug-free C program is
which in the first place was debunked because there might yet be bugs in the startup code that invokes it, but secondly because a nil program is meaningless. If you need to be so tight the runtime size matters, you’re already looking at specialised cross compilers for embedded systems, and their vendors will almost certainly publish their minimum runtime requirements.
8
u/gizahnl Oct 19 '25
If you're interested in small size applications, look at the demo scene, though at the more extreme classes they do handcraft their assembly.
Even at 256 bytes impressive beautiful demos are possible.
6
u/pjc50 Oct 19 '25
Not really an interesting "challenge" specifying gcc, since you get what you're given. Handcrafting the ELF file is more interesting to explore the file format: https://nathanotterness.com/2021/10/tiny_elf_modernized.html
3
u/__nohope Oct 19 '25
does it need to be portable?
Is inline assembly allowed?
5
u/flyingron Oct 19 '25
Hopefully, you are only allowed to:
2
u/AdreKiseque Oct 19 '25
Related video
Doesn't quite match all the criteria of your post but you might find it interesting
1
u/olikn Oct 19 '25
Something like: https://irq5.io/2019/09/30/generating-small-static-binaries/
23
u/[deleted] Oct 19 '25
[removed] — view removed comment