On Fri, 03 Dec 2010 03:10:02 +0100, Grant Edwards wrote about [gentoo-user] How to build a static application binary?:
>It seems that "gcc -static" was broken sometime in the last few years.
>
>This used to produce reasonable results:
>
>---------------------------------tiny.c---------------------------------
>#include <unistd.h>
>
>int main(void)
>{
> write(1,"hi there\n",10);
> return 0;
>}
>------------------------------------------------------------------------
>
>$ gcc -Wall -static -o tiny tiny.c
>
>$ strip tiny
>
>$ size tiny
> text data bss dec hex filename
> 522618 1928 7052 531598 81c8e tiny
>
>Over _HALF_A_MEGABYTE_ of cruft for a application who's text size is a
>few hundred bytes and makes a single system call. Leaving out the
>call to write() reduces the file size by 16 bytes.
>
>IOW, an _empty_ main requires 531582 bytes. Wow.
What you are seeing is a lot of glibc routines being included by the
linkage editor. These handle all sorts of conditions that will likely
never occur in your program.
Try using a smaller C library, like uclibc or klibc. They might not
work as well, but they will give you a smaller executable.
Alternatively, try rewriting your code in assembler.
--
Regards,
Dave [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
[email protected] (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
signature.asc
Description: PGP signature

