3 ms·
I think large chunk of it is from dynamic linker, rather than glibc. At least that appear to be the case according to "file a.out". Adding "-static" option seem
by nousermane 4y ago
I think large chunk of it is from dynamic linker, rather than glibc. At least that appear to be the case according to "file a.out". Adding "-static" option seems to prevent that:
$ gcc -Wall -s -nostdlib tiny.o; wc -c a.out
12780 a.out
$ gcc -Wall -s -nostdlib tiny.o -static
$ wc -c a.out
4304 a.out
Bulk of what remains is page-size alignment. Linux works with 4KB pages:
$ getconf PAGESIZE
4096
...so it makes sense that gcc (ld, really) aligns to that. But we can dial it down:
$ gcc -Wall -s -nostdlib tiny.o -static \
-Wl,-zmax-page-size=64; wc -c a.out
400 a.out
...and a bit more could be shaven by dropping Build ID:
$ strip -R .note.gnu.build-id a.out; wc -c a.out
344 a.out
This wonderful piece of software: https://github.com/aunali1/super-strip https://github.com/aunali1/super-strip seem to find more things to remove, although not sure what would be that:
$ sstrip a.out; wc -c a.out
220 a.out
Of course, this is not quite "golfed", and I too, would love to see OP's article updated to x86_64 and current crop of gcc/binutils.
- Alupis 4y agoNot quite 45 bytes, but 12,780 bytes down to 220 (a 98% footprint reduction) is very impressive on it's own.