Size Is Everything: Making Tiny ELF Binaries 40
Milk Toast writes "According to this article one can start with a simple program consisting of 3998 bytes and reduce it down to a mere 45 bytes. Now if they could only reduce the size of my Office install." It involves digging into assembly, naturally, but it's interesting to see the extra code generated not only by the compiler, but by the other steps along the way.
Re:First heard this on Slashdot. (Score:3, Informative)
In fact, I first heard about it here [slashdot.org]...
Re:First heard this on Slashdot. (Score:2, Interesting)
2001 called (Score:4, Funny)
Re:2001 called (Score:1)
At the risk of offending little people... (Score:2, Funny)
Re:At the risk of offending little people... (Score:2)
Re:At the risk of offending little people... (Score:2)
Besides.. the original elf was:
It's a duplicate! (Score:4, Informative)
Man, I've been reading Slashdot way too long.
(It's still a good article though. Worth rereading if you're at all interested in how ELF binaries work.)
Re:It's a duplicate! (Score:3, Interesting)
Damn you beat me to it. Even in 2002, it was just a linux/elf rehash of what optimizating asm-geeks have been doing since the dawn of time. I distinctly remember a contest I had with another guy back around 1994 on 486-class machines running MSDOS, to see which of us could write a functional text pager (ala "more", press spacebar to see the next screen of text from standard input) in the fewest bytes possible in the resulting
Re:It's a duplicate! (Score:2)
I thought it was clever
Jesus that's old (Score:2)
Ugh! (Score:2)
It may not be an executable but... (Score:3, Interesting)
froze@butsuri:~$ cat > tiny
exit 42
froze@butsuri:~$ chmod a+x tiny
froze@butsuri:~$
42
froze@butsuri:~$ wc -c tiny
8 tiny
Re:It may not be an executable but... (Score:2)
Nice troll, good troll, down boy down.
The article is about getting the smallest ELF that will return 42. If returning 42 were an actual requirement and size is all that matters, then this is much more effective as it takes advantage of an already existing process - the shell. Much like the ELF is taking advantage of the kernel. I suppose that one could actually write machine code to run in place of the kernel that would generate the number 42 and do it in fewer than 45 bytes, but I didn
Re:It may not be an executable but... (Score:2)
Re:It may not be an executable but... (Score:2, Informative)
cowgod@kraken:~$ echo -n "exit 42" > tiny
cowgod@kraken:~$ chmod a+x tiny
cowgod@kraken:~$
42
cowgod@kraken:~$ wc -c tiny
7 tiny
gcc opts (Score:2, Insightful)
gcc -Wall -s -O3 tiny.c
shouldn't
gcc -Wall -s -Os tiny.c
make more sense seeing as how -O(1-3) are for SPEED optimization where as -Os is to make things SMALL
pls. Expose my idiocy...
Re:gcc opts (Score:2, Interesting)
Re:gcc opts (Score:1, Insightful)
Re:gcc opts (Score:1)
Completely, utterly, useless (Score:2)
Since nobody is actually going to waste their time doing this for programs large enough that the padding doesn't kill the gain, what's the point?
Re:Completely, utterly, useless (Score:3, Insightful)
Re:Completely, utterly, useless (Score:1)
Re:Completely, utterly, useless (Score:1)
I made this joke last time too... (Score:1)
Re:I made this joke last time too... (Score:1)
Re:RTFA (Score:1)
Re:I made this joke last time too... (Score:1)
Or you could store "42" in a text file, for a grand total of 3 bytes (including EOF). Now that's progress.
Am I the only one who burst out laughing... (Score:1)
... at how he describes the resemblence in the ELF and program headers? Or am I really that much of a geek? =P
Oooh that brings back memories. (Score:1)
Now I didn't bother with messing with ELF headers - but just wanted to create the smallest possible binary output -
Here is a cat-like program.
---------->
.text
.globl _start
_start:
incl %eax
doit:
incl %eax
incl %eax
pushl %esp
popl %ecx
xorl %edx, %edx
incl %edx
int $0x80
cmpl $0,%eax
je exit
incl %eax
incl %eax
incl
I wish somebody would tell the spammers, then (Score:2)