
Tutorial on Creating Really Teensy ELF Executables for Linux  - spudlyo
http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html
======
icefox
On this topic does anyone know of a good article that shows you you can
profile your binary size? Say given binary X object Y takes up 60% and in
object Y source file Z takes up the most. Or a list of common coding practices
in [language] that cause the binary size to significantly increase?

~~~
jacquesm
try the 'nm' program on your binaries.

~~~
malkia
or better use the 'size' program to give how much each .o/.obj file takes.

You can also use 'strip' to remove debug information not needed (normally
appended to the end of the file).

------
Luyt
It would have been brilliant if he could have reduced the program size to 42
bytes - the same as the result when you run it, and the answer to everything.

~~~
silvajoao
In the postscript he mentions:

 _[...] Well, actually, it could be made smaller. When Linux starts up a new
executable, one of the things it does is zero out the accumulator (as well as
most of the other registers). Taking advantage of this fact would have allowed
me to remove the xor [...]_

Removing the xor reduces the program size to 43 bytes. Closer, but not there
yet :-)

However, neither the original nor the 43-byte version run on my machine [1].
The first is simply _Killed_ , the second doesn't even load: _cannot execute
binary file_.

[1] Linux 2.6.28 i686 (Ubuntu 9.04 on Pentium M)

~~~
kelnos
The original runs fine for me[1], but if you actually read the last bit of the
article, you'll see that there's no way to get it below 45 bytes and convince
the kernel to still run it. The 45th byte specifies the number of entries in
the program header table, and that can't be zero (or missing).

[1] Linux 2.6.31 x86_64

------
sid0
The equivalent exercise for the Windows PE file format:

<http://www.phreedom.org/solar/code/tinype/>

------
selven
Very interesting, although we are (sadly) past the point where squeezing every
byte you can get out of your program matters.

~~~
kelnos
I think crazy size optimization like that is a fun exercise, but I completely
disagree with your "sadly" there. Avoiding the need to do all this silly
micro-optimization means more time to create things that people actually care
about and want to use.

Yes, modern software is comparatively huge and bloated, but the less your
average programmer has to worry about code size and speed, the larger the the
body of useful applications we'll have.

~~~
willchang
Nostalgia is surely as bad a vice as they come, but I can't help be a little
nostalgic that marvelous hacks like these no longer have a place in our world.

I've heard there are similar such hacks in the world microbiology, overlapping
genes giving bacteria a selective advantage. But in the world of people,
genomic code bloat is apparently not a problem.

------
abalashov
It's unfortunate. The Sidekick II was the best smartphone I ever had in terms
of usability, keyboard and speed, and I am still highly partisan to it.

~~~
alnayyir
Wrong topic. :)

