4 ms·
> I've written hello.c and it's about 84 bytes of C and 8.3k as an executable. Would hand-coded assembler be that large? The answer is generally no. A lot of t
by jsjohnst 7y ago
> I've written hello.c and it's about 84 bytes of C and 8.3k as an executable. Would hand-coded assembler be that large?
The answer is generally no. A lot of that overhead is due to the C std library. If memory serves from a blog post I read long ago, with very very aggressive tuning, you can get a hello world binary down under 50 bytes (which is smaller than the ELF header). A “normal” ASM coded “hello world” binary could easily be in the range of a few hundred bytes without anything special.
- m463 7y agoI looked a little further. hello.c: 4 loc, 84 bytes hello.s: 30 loc, 517 bytes hello: 8.3k so it must be data structures for linking. oh, and if I use -static, hello becomes 844704 bytes. :)
- ajxs 7y agoYou can use the `-S` switch with gcc to produce the intermediate assembler representation of your C program instead of binary output. From there you can see for yourself what optimisation has been performed and what hand optimisations are possible. I just compiled my own 'hello.c' on Linux, with the optimisation flag set for 'code size', and the binary weighed in around 8.3k. I then removed the `printf` call and the inclusion of `stdio.h`. The resulting binary was 8.1k. This is exactly as expected. Why would the inclusion of a call to a dynamic library bloat the final binary size?
- jsjohnst 7y ago> Why would the inclusion of a call to a dynamic library bloat the final binary size? Here’s two good links to read on it: https://www.muppetlabs.com/~breadbox/software/tiny/teensy.html https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht... http://timelessname.com/elfbin/ http://timelessname.com/elfbin/
- deleted 7y ago[deleted]