specifying an ELF soname when linking shared libs
duncan at well-typed.com
Thu May 14 05:41:37 EDT 2009
On Thu, 2009-05-14 at 09:15 +0100, Simon Marlow wrote:
> On 13/05/2009 19:54, Duncan Coutts wrote:
> > Shared libs enthusiasts,
> > We can use ghc to link a bunch of .o files into a shared lib:
> > $ ghc -dynamic -shared Blah.o -o libHSblah.so
> > The question on ELF platforms is how we should set the "soname". This
> > name is name baked into the .so lib and used to identify the library by
> > the dynamic linker (to tell when two other libs are talking about the
> > same dependency).
> > With gcc, on ELF platforms you would use:
> > $ gcc -shared Blah.o -o libblah.so -Wl,-soname,libblah.so
> > Now for ghc, we would normally use a soname corresponding to the package
> > name, which usually also corresponds to the library file name.
> > We could look at the file name given by -o, though this is a little
> > non-standard for such tools.
> So the default soname is just the filename, correct? What happens with
> gcc -shared when you don't specify an soname?
In that case you get no soname embedded in the binary at all. This means
that when you link another ELF object against it, that object records a
dependency on the file name as the soname. So I guess we can think of it
using the filename as the soname by default. I'm not sure if there is
any additional subtlety in the dynamic linker when a .so file is missing
> > We could require (or at least suggest) -package-name be given when
> > linking a shared lib. However that would involve baking in the "HS"
> > library prefix name convention into ghc.
> > Or we can make the caller specify the soname specifically.
> "caller specifies" sounds right, with a sensible default that matches
> what gcc does.
Perhaps having none by default does work for Haskell packages, however I
think it's good practise to specify a soname. On my system there are
only 2 out of 700+ .so libs that are missing a soname.
I hadn't looked before but what libtool does is require that you specify
an output name with the -o flag. Perhaps this is the most sensible thing
for ghc -shared. Using a default of "a.out" is plainly silly. We only
have "a.out" as a default for binaries because of historical convention.
There is no need to perpetuate this for the shared library world (it's
not as if there are any makefiles out there relying on a.out behaviour
of ghc -shared).
So default to the output file name and provide a mechanism to override
it. The simplest possible is to just put -Wl,-soname,$name on the gcc
command line before user-supplied options and since later ones take
precedence the user can say:
ghc -dynamic -shared -o libfoo.so foo.o -optl-Wl,-soname,libbar.so
Summary: require -o with ghc -shared and use the output name as the
soname but let people override the soname by passing extra flags to the
More information about the Cvs-ghc