Subject: Re: Shared library troubles
To: None <andyf@vei.net>
From: Ken Nakata <ksn@tkf.att.ne.jp>
List: port-mac68k
Date: 07/06/1999 20:29:54
On Mon, 05 Jul 1999 22:24:20 -0400, Andy Finnell <andyf@vei.net> wrote:
> Ken Nakata wrote:
> > 
> > On Mon, 05 Jul 1999 18:48:04 -0400, Andy Finnell <andyf@vei.net> wrote:
> > > I'm having a hard time getting the pthread shared library to work
> > > correctly.  Everything works fine in the compile & link phase, but when
> > > I run the program, I run into trouble.
> > >
> > > Here's what ld.so gives me:
> > >
> > > /usr/libexec/ld.so: symbol ___sF at 0x403d1ec in
> > > /usr/local/pthreads/lib/libpthread.so.1.60 changed size: expected 264,
> > > actual 192
> > >
> > > After this the program segfaults.  At first I thought it was my code, so
> > > I moved the function it was segfaulting in, into the function that calls
> > > it.  The above error still shows up.  If I statically link the program
> > > everything goes fine.
> > >
> > > Any ideas of why ld.so is giving me the above warning/error?  What
> > > should I be looking for?  Thanks,
> > 
> > Are libpthread.a and libpthread.so.1.60 built from the same source?
> > lib*.a is used when you compile the offending program whereas
> > lib*.so.* is loaded by ld.so when you run that program.

To correct myself, this is incorrect.  When compiling a dynamically
linked binary, lib*.so.* is used.  lib*.a is used only when you link
the binary statically.

> >  Are you sure
> > you don't still have an old libpthread.a around somewhere cc might
> > look into for library files?
> 
> Thanks!  That was my problem, kinda.  You see, there are actually *3*
> libraries being built.  The first one, lipthread.a, is the *static* link
> library (what I was linking in).  The second was libpthread_pic.a, which
> is the shared object library.  And still yet the third was
> libpthread.so.1.60, which is the one being loaded at runtime.  The first
> two are created from the same sources, and the third seems to created
> from libpthread_pic.a using the ld command.  When I was linking I
> specified the -lpthread option which gave me the static library.  After
> changing the flag to -lpthread_pic, everything worked fine.  

This sounds like you have libpthread.so.* somewhere ld.so looks.  What
do you see when you do "ldconfig -r | grep pthread"?  Is it
/usr/local/pthreads/lib/libpthread.so.1.60?

When you cc -lpthread, it looks for libpthread.so.x.y (where x and y
are the highest version numbers it can find) but when you cc
-lpthread_pic, it looks for libpthread_pic.so.x.y, fails to find it,
and *statically* links libpthread_pic.a in, instead.

And you can specify different lib directories for cc and ld.so, by -L
option for cc, and by /etc/ld.so.conf or by ldconfig for ld.so.

That's why it works when you cc -lpthread_pic whereas it doesn't when
you -lpthread.  I bet you got a different set of libpthread.a and
libpthread.so.* somewhere other than /usr/local/pthreads/lib in your
system that ld.so is trying to load at runtime (how about
/usr/pkg/lib?).  There's no other explanation I can think of.

Ken