We use a simple hello program. Type the following program into your favorite editor.
1 2 3 4 5 6 | #include int main() { printf("Hello world\n"); return 0; } |
We don’t want to debug our intro. We compile it using size-optimization and no frame-pointers.
1 | $ gcc -Os -fomit-frame-pointer test001.c -o test001 |
Let’s see how big it executable.
1 2 | $ ls -l test001 ... 9043 2012-05-19 17:39 test001 |
We have about 9043 bytes.
We’ll strip the executable and remove useless information. The strip command discard symbols from object files.
1 | $ strip -s -R .comment -R .gnu.version test001 |
Let’s see how big it’s now.
1 2 | $ ls -l test001 ... 5300 2012-05-19 17:41 test001 |
Now we have about 5300 bytes.
With sstrip part of the package ELFkickers, we can save about 1k.
1 | $ sstrip test001 |
You can test it.