Brian Raiter wrote a tutorial how to "shave" an ELF program as much as possible. He started with a program that does nothing but returns the number 42 to the invoker. The original binary was 3998 bytes long. He began to shave it and the result was a 91 byte ELF image that did the same thing. But he wanted to shave the program more. Using additional dirty tricks he ended up with a 45 byte binary that was still working. But the disadvantage of this binary is that it is not an ELF binary anymore (even if it masquerades as if it is). He broke the ELF standard by utilizing the fact that Linux (the kernel) does not enforce many aspects of it. This makes the second part of "shaving" method unusable for real production-quality work.
So let's see how he would perform with OSHS binary file format. This is the same program he "shaved" but using the OSHS binary executable file specification format:
; tiny.asm org 0 ; does not matter in this program header: db "FP" ; Specify OSHS Flat Program file. db 0 ; Nothing but 4 KB stack present. _start: mov al, 42 ; OSHS programs are procedures ret ; that return the exit code in AL.
Compile and try it out:
$ nasm -f bin -o a.out tiny.asm $ chmod u+x a.out $ a.out ; echo $? 42
Well, it works. And how about its size?
$ wc -c a.out 6 a.out
Ehm, only six bytes! And with no dirty tricks !!! Yes, this extremely tiny program is a valid OSHS binary that perfectly complies with the OSHS native binary file format specification. Do that with the extremely bloated binary file format like ELF!
But that isn't the shortest possible program in OSHS. The program called "true" is even shorter:
; true.asm org 0 ; does not matter in this program header: db "FP" ; Specify OSHS Flat Program file. db 0 ; Nothing but 4 KB stack present. _start: ; OSHS clears registers at startup and ; we want to return 0. ret ; So just immediately return the already ; fetched zero in AL.
Let's try it !
$ nasm -f bin -o true true.asm $ chmod u+x true $ true ; echo $? 0 $ wc -c true 4 true
That's it! Compare these results to the 45 bytes of the badly mangled ELF binary produced in the tutorial. And when we want to count the fact that our 6 byte program is a standard OSHS binary, we must compare it to the 91 byte standard ELF binary, not the 45 badly-mangled one.