Subject: Explanation of "-soname"
To: None <tech-toolchain@NetBSD.ORG>
From: Todd Vierling <>
List: tech-toolchain
Date: 07/17/1998 23:12:21
I was asked by someone in private e-mail about the reason for needing
"-soname" in shared libraries on ELF systems.  I thought the explanation
would be good to share.

:      -soname library-name
:              This option and its libraryname argument are ignored.

It's not ignored for the binutils ld, used on ELF systems.  :>

Here's what you have: (symlink to (symlink to

OK, let's say you link `program' with -lraryname (<g>).  The ELF ld looks
for, and lo and behold, there it is.  It takes the -soname
stored in the library, or if there is no -soname,, and
encodes that into the list of libraries needed by `program'.

Okay, let's now look at how `program' finds its libraries.  It looks for
libc, libutil, blah, blah, libraryname.  `Program' was linked against
libraryname 1.2, but it doesn't know that (ELF binaries don't know about
version numbering) - it only knows the name `', or whatever
was in the -soname argument. 

You go upgrade libraryname to a new major version, and you have: (symlink to (symlink to (symlink to

This new libraryname is not binary compatible with version 1, but you
haven't recompiled/linked `program'.  You run `program' and it goes hunting
for its libraries.  If `program' chooses `', you're SOL - it
isn't compatible.

That's why you encode the name `' into the library:  so that
`program' knows which version to fetch in case the major version gets

And you don't use `-soname', because that gives you the
opposite problem; if you upgrade to and delete, it won't be able to find its library anymore.  That's
why the major-only symlink is there:  to provide a reference point for a
given major version of the library, even if the minor version changes.

-- Todd Vierling (Personal; Bus.