Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't static linking used more?

I understand the benefits of dynamic linking (old code can take advantage of library upgrades automatically, it's more space efficient), but it definitely has downsides, especially in the heterogeneous Linux ecosystem. It makes it difficult to distribute a distribution-agnostic binary that "just works" and makes a previously working program more likely to break due to a system upgrade that breaks backwards compatibility or introduces regressions into a shared library.

Given these disadvantages, why does dynamic linking seem to be so universally preferred? Why is it so hard to find statically linked, distribution-agnostic Linux binaries, even for small applications?

like image 930
dsimcha Avatar asked Aug 24 '11 18:08

dsimcha


1 Answers

There are three big reasons:

  1. GNU libc doesn't support static linkage to itself, because it makes extensive internal use of dlopen. (This means that static linkage to anything else is less worthwhile, because you can't get a totally static binary without replacing the C library.)
  2. Distributions don't support static linkage to anything else, because it increases the amount of work they have to do when a library has a security vulnerability.
  3. Distributions have no interest whatsoever in distribution-agnostic binaries. They want to get the source and build it themselves.

You should also keep in mind that the Linux-not-Android software ecology is entirely source-based. If you are shipping binaries and you're not a distribution vendor you are Doing It Wrong.

like image 106
zwol Avatar answered Sep 24 '22 20:09

zwol