Slashdot Mirror


Size Is Everything: Making Tiny ELF Binaries

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.

11 of 40 comments (clear)

  1. 2001 called by Anonymous Coward · · Score: 4, Funny

    and they want their "news" back.

  2. At the risk of offending little people... by brilinux · · Score: 2, Funny

    Should ELF binaries not normally be really small?

  3. Re:First heard this on Slashdot. by Scarblac · · Score: 2, Informative

    In fact, I first heard about it here...

    --
    I believe posters are recognized by their sig. So I made one.
  4. Re:First heard this on Slashdot. by Scarblac · · Score: 2, Interesting

    And, reading through those comments, that wasn't the first time either... That's actually what I thought, but I couldn't find the link to the even older article quick enough.

    --
    I believe posters are recognized by their sig. So I made one.
  5. It's a duplicate! by david.given · · Score: 3, Informative
    From 2002, no less!

    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.)

    1. Re:It's a duplicate! by photon317 · · Score: 2, 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 .COM executable. I can't recall the exact numbers, but he beat me by something around 10 bytes, and the numbers were in the neighboorhood of 100 bytes flat.

      --
      11*43+456^2
  6. It may not be an executable but... by Froze · · Score: 2, Interesting

    It runs and it is only 8 bytes!
    froze@butsuri:~$ cat > tiny
    exit 42
    froze@butsuri:~$ chmod a+x tiny
    froze@butsuri:~$ ./tiny; echo $?
    42
    froze@butsuri:~$ wc -c tiny
    8 tiny

    --
    -- The morphemes of your disquisition are ascertainable, but they have eschewed an ambit of transpicuous exposition.
    1. Re:It may not be an executable but... by the_cowgod · · Score: 2, Informative

      That wastes a byte for a newline! Try:

      cowgod@kraken:~$ echo -n "exit 42" > tiny
      cowgod@kraken:~$ chmod a+x tiny
      cowgod@kraken:~$ ./tiny; echo $?
      42
      cowgod@kraken:~$ wc -c tiny
      7 tiny

  7. gcc opts by beswicks · · Score: 2, Insightful

    Erm, i'm not sure its nearly 5 in the morning here but initially he compiles with

    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...

    1. Re:gcc opts by Anonymous Coward · · Score: 2, Interesting

      The article is so old, I think it was before they had -Os in gcc.

  8. Re:Completely, utterly, useless by Fujamabob · · Score: 3, Insightful

    When you google for ways to fit a program in 512 bytes on the first sector of a floppy, and this is the first article that mentions the options for not using standard include files, etc., it becomes useful.