1 |
On Fri, 03 Dec 2010 03:10:02 +0100, Grant Edwards wrote about |
2 |
[gentoo-user] How to build a static application binary?: |
3 |
|
4 |
>It seems that "gcc -static" was broken sometime in the last few years. |
5 |
> |
6 |
>This used to produce reasonable results: |
7 |
> |
8 |
>---------------------------------tiny.c--------------------------------- |
9 |
>#include <unistd.h> |
10 |
> |
11 |
>int main(void) |
12 |
>{ |
13 |
> write(1,"hi there\n",10); |
14 |
> return 0; |
15 |
>} |
16 |
>------------------------------------------------------------------------ |
17 |
> |
18 |
>$ gcc -Wall -static -o tiny tiny.c |
19 |
> |
20 |
>$ strip tiny |
21 |
> |
22 |
>$ size tiny |
23 |
> text data bss dec hex filename |
24 |
> 522618 1928 7052 531598 81c8e tiny |
25 |
> |
26 |
>Over _HALF_A_MEGABYTE_ of cruft for a application who's text size is a |
27 |
>few hundred bytes and makes a single system call. Leaving out the |
28 |
>call to write() reduces the file size by 16 bytes. |
29 |
> |
30 |
>IOW, an _empty_ main requires 531582 bytes. Wow. |
31 |
|
32 |
What you are seeing is a lot of glibc routines being included by the |
33 |
linkage editor. These handle all sorts of conditions that will likely |
34 |
never occur in your program. |
35 |
|
36 |
Try using a smaller C library, like uclibc or klibc. They might not |
37 |
work as well, but they will give you a smaller executable. |
38 |
|
39 |
Alternatively, try rewriting your code in assembler. |
40 |
-- |
41 |
Regards, |
42 |
|
43 |
Dave [RLU #314465] |
44 |
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |
45 |
dwnoon@××××××××.com (David W Noon) |
46 |
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* |