Static linking considered harmful

Jakub Jelinek jakub at redhat.com
Wed Nov 22 10:56:07 UTC 2006


On Wed, Nov 22, 2006 at 11:39:35AM +0100, Patrice Dumas wrote:
> On Wed, Nov 22, 2006 at 11:34:14AM +0100, Arjan van de Ven wrote:
> > 
> > actually static linking DECREASES that portability !!
> 
> Are you saying that you can compile a program dynamically and run it
> on old redhat, centos, old debian, mandrake and fedora core boxes?
> I tried, it fails, while statically linked programs are fine (at least 
> numerical models).

Yes and no.

Assuming if you link statically on very recent distro that your program
will work on any old Linux distro is just very bad assumption.
E.g. each glibc is configured for some minimal kernel version, if you
attempt to run the program on older kernel some functions will crash,
misbehave or the program won't start at all.  E.g. FC5+ glibc is
configured for 2.6.9 and later kernels, so running it on say FC1
just isn't going to fly.

If you want to create a program that will work on older distributions
(within reasonable limits, e.g. glibc 2.0 or libc5 or a.out stuff
isn't supported anymore in recent FCs), just compile/link against
the oldest glibc etc. you want to support, whether by installing
an old distro in the chroot or by installing and linking against
something like compat-glibc (these days only present in RHEL,
but could very well be revived for FC as well), using compat-gcc
(on FC6 that has e.g. a side-effect of using -Wl,--hash-style=sysv
etc.).

	Jakub




More information about the fedora-devel-list mailing list