Loads of undefined reference to `pthread_foo`

Joe Marcus Clarke marcus at marcuscom.com
Tue Apr 29 12:41:29 PDT 2003


On Tue, 2003-04-29 at 15:28, Philip Paeps wrote:
> On 2003-04-29 12:22:47 (-0400), Joe Marcus Clarke <marcus at marcuscom.com> wrote:
> > On Tue, 2003-04-29 at 07:31, Philip Paeps wrote:
> > > On 2003-04-28 23:12:33 (-0400), Joe Marcus Clarke <marcus at marcuscom.com> wrote:
> > > > On Mon, 2003-04-28 at 22:42, Philip Paeps wrote:
> > > > > Mmm, it seems as though www/mod_php4 isn't compiling.  It's giving the same
> > > > > errors as above.  From work/php4.3.1/config.log:
> > > > > 
> > > > >     [...]
> > > > >     /usr/local/lib/libxml2.so: undefined reference to `pthread_setspecific'
> > > > >     [...]
> > > > > 
> > > > > I'm trying to figure out where in the configure script best to add the
> > > > > -pthread bit.
> > > > 
> > > > You shouldn't need to.  What does:
> > > > 
> > > > xml2-config --libs
> > > > 
> > > > report?  It should contain -pthread.
> > > 
> > > That gives me:
> > > 
> > >   (pub:/usr/ports/www/mod_php4)# xml2-config --libs
> > >   -L/usr/local/lib -lxml2 -lz -pthread -L/usr/local/lib -liconv -lm
> > >   -L/usr/local/lib
> > > 
> > > For some reason, PHP doesn't seem to be picking it up though :-/
> > 
> > Yeah, I looked further at PHP's configure, and it explicitly filters out
> > -lc_r and -pthread.  I add a flag to libxml2 to build it without thread
> > support.  Rebuild libxml2 with -DLIBXML_WITHOUT_THREADS, and you should be
> > set with PHP.  
> 
> Thanks!  That works :-)
> 
> > I wonder if it would be okay to allow -pthread in mod_php (of course,
> > FreeBSD may prevent -pthread from being linked in to the final mod_php .so).
> 
> I seem to recall that there was a reason for disabling pthread, at least on
> FreeBSD-4?

Marcel Moolenaar responded to my hackers@ question on the subject.  Here
is my question:

"I've noticed something I think is strange with gcc, the -shared flag,
and -pthread on -STABLE.  I'm hoping someone can enlighten me as to why
this happens or if it's a bug.  If I compile something with the
following command, I do not see libc_r.so linked in the resulting
object..."

And Marcel's response:

"The -shared option tells the compiler driver that you're trying to
create a shared object. In that case -lc_r is not added to the link
line. Adding -lc_r explicitly is dangerous, because now the linker
will construct a shared object that has code linked in from an
archive library that has not been compiled with PIC. Consequently,
some architectures (eg ia64) may barf when you try to link against
this shared object because it may contain invalid relocations.

Using -Wl,-shared tricks the compiler driver in thinking you are
creating an executable. It will therefore make sure dependencies
are correct by adding -lc_r on the link line. You tell the linker
however that you're creating a shared object, but now it also has
-lc_r explicitly. Again, this can result in a bad shared object.

I don't think there's a bug."

And from the commit message to bsd.port.mk that adds -pthread for
-STABLE and -lc_r for -CURRENT:

"Add new variables PTHREAD_CFLAGS and PTHREAD_LIBS to help the
transition with the new pthread linking scheme."

Apparently, after 500016, libc and libc_r can now be linked together.

Joe

> 
>  - Philip
-- 
PGP Key : http://www.marcuscom.com/pgp.asc


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-ports/attachments/20030429/b3c69cf2/attachment.bin


More information about the freebsd-ports mailing list