On Thu, Mar 06, 2003, Eli Billauer wrote about "[Haifux] Huge file with static linking": > [EMAIL PROTECTED] helloworld]$ gcc -static -o hello hello.c > [EMAIL PROTECTED] helloworld]$ ls -l hello > -rwxrwxr-x 1 eli eli 441940 Mar 6 21:05 hello* > [EMAIL PROTECTED] helloworld]$ > > As you can see, this little program takes 440 kB. Hmmm. Why does this > look too much to me? > > I mean, even without glibc and other wonders, surely one could implement > "puts" with less? > > Any suggestions of how to shrink this down to some normal size?
strip will save so a bit, but not more than 20%. If you want to see the kind of crap from glibc that gets into your generated program, try gcc -Wl,--verbose -static z.c or after you have an unstripped program try nm a.out What happens has a simple name: bloat. Years ago, when shared libraries were rare, library designers actually cared about the issue you specify. If you used only puts() and stdout, very little else of the C library would get into your program. Today, they don't care if using stdout includes code running malloc(), that uses printf(), which ends up (to make a long story short) using locales, threads, quicksort, wide-character routines, yacc parsers, and who knows what else. They stopped caring because with shared libraries, indeed this issue does not matter. But they forgot that static compilations is sometimes still important. I think it's a real shame :( A striking example: I have a program "bundle.c" that I compiled in 1990 and now (2003). Let's compare the stripped binaries: 1990 - 16,638 bytes - DOS binary (no shared libraries, of course) 2003 - 7,992 bytes - Linux binary with shared libraries 398,348 bytes - Linux binary, static So the compiled static code of a simple C program (300 lines) got 24 times larger (!) in the last 13 years. Shared-library-using code is still quite small. -- Nadav Har'El | Friday, Mar 7 2003, 3 Adar II 5763 [EMAIL PROTECTED] |----------------------------------------- Phone: +972-53-245868, ICQ 13349191 |I don't suffer from insanity, I enjoy http://nadav.harel.org.il |every minute of it. -------------------------------------------------------------------------- Haifa Linux Club Mailing List (http://www.haifux.org) To unsub send an empty message to [EMAIL PROTECTED]