3 ms·
Very nice; tried it and got a 129 byte working true command. Now I have to understand what's in the 28896 bytes of the true command that comes with the distro I
by corecoder 10y ago
Very nice; tried it and got a 129 byte working true command.
Now I have to understand what's in the 28896 bytes of the true command that comes with the distro I have here.
- oblio 10y agoGNU true: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true.c http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/true... The real kicker is GNU false: http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/false.c http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/fals... A sort of "reversed polarity", if you will.
- LeifCarrotson 10y agoSo it's basically int main (int argc, char **argv) { return EXIT_SUCCESS; } plus all the stuff required to handle --version and --help. But even compiling just that results in 60 kB on my system. What's in those other kilobytes, indeed!
- zokier 10y agoI'd guess most of code weight will be setting up and tearing down glibc, initializing stdio etc. Then there is all sorts of metadata that gcc (and ld etc) include by default. There are plenty of resources on how to create minimal C executables, but `-nostdlib` gcc option would be a good starting point as a low-hanging fruit.
- cheiVia0 10y agoPeople like to dig at the size of GNU's /bin/true and /bin/false, but the reality is - who cares? Does anyone actually ever use it? $ type true true is a shell builtin
- ktRolster 10y agoI don't know how you compiled it, but you can often cut down by using the '-O3' command line option when you are compiling. Then you can use the 'strip a.out' (or whatever your executable name is) to cut it down further. Then if you open it in a hex editor (or use od -x), I'll bet you'll see pages and pages of zeroes, which are used for aligning it appropriately in RAM when it loads. At least, those are all things that work on some systems, can't be sure about yours.
- aexaey 10y agoThere is also an sstrip tool [1], written by the same Brian Raiter already mentioned here. It strips a bit more eagerly: $ gcc tiny.c -O3 -o tiny; wc -c tiny 8456 tiny $ strip tiny; wc -c tiny 6224 tiny $ sstrip tiny; wc -c tiny 4140 tiny [1] http://www.muppetlabs.com/~breadbox/software/elfkickers.html http://www.muppetlabs.com/~breadbox/software/elfkickers.html
- ben_bai 10y agoThe real kicker is this comment in GNU true(1). /* Note true(1) will return EXIT_FAILURE in the edge case where writes fail with GNU specific options. */ If you can't program a bug free true(1), please stop with whatever you think you are doing.