Adventures in static linking

jjohn on 2005-06-02T19:20:46

What's wrong with this screen dump?

[jjohn@localhost hello]$ gcc -Wall -static hello.c
[jjohn@localhost hello]$ file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, statically linked, not stripped
[jjohn@localhost hello]$ ls -l
total 424
-rwxrwxr-x    1 jjohn    jjohn      424535 Jun  1 17:50 a.out
-rw-rw-r--    1 jjohn    jjohn          90 Jun  1 17:50 hello.c
[jjohn@localhost hello]$ ./a.out
Hello

Good gravy, that's one fine statically compiled binary that's more than 4000 times the size of the source code. It doesn't just print "Hello", it prints the hell of out it!


Static linking

jdavidb on 2005-06-03T15:15:28

That is what you expect with static linking, is it not? I'm not sure you could say there's anything "wrong."

Re:Static linking

jjohn on 2005-06-03T16:10:39

4000x increase?! That's a meaty runtime! 16K, 32K or 64K would be what I would have expected.

Re:Static linking

jdavidb on 2005-06-03T18:14:33

I presume it's linking in libc.a. Here are some libc.a sizes on systems I have access to at the moment:

  • Cygwin: 781142 bytes
  • SunOS 5.8: 1790056 bytes
  • Sparc64 Linux: 2825144 bytes
  • ix86 Linux: 2233342 bytes

Maybe that's a lot larger than it was back in the day, but it seems about right to me.