This is the mail archive of the
mailing list for the GCC project.
Re: GCC-3.0.4 (pre) on AIX requires pthreads
- From: David Edelsohn <dje at watson dot ibm dot com>
- To: "Michael Veksler" <VEKSLER at il dot ibm dot com>
- Cc: gcc at gcc dot gnu dot org, libstdc++ at cc dot gnu dot org
- Date: Wed, 20 Feb 2002 15:49:52 -0500
- Subject: Re: GCC-3.0.4 (pre) on AIX requires pthreads
>>>>> Michael Veksler writes:
Michael> For some reason, on AIX 4.3.3, g++ requires -lpthreads while linking
Michael> executables. Is there a way to fix g++ installation/compilation procedures
Michael> to eliminate the need for -lpthreads?
Michael> $ g++ -v
Michael> Reading specs from
Michael> Configured with: ../gcc/configure --enable-languages=c++
Michael> Thread model: single
Michael> gcc version 3.0.4 20020215 (prerelease)
Michael> $ g++ t.cc # adding "-lpthreads", or even "-pthreads" removes this
Michael> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
Michael> ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
Michael> ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
Michael> This suggests that these symbols are required by the generated
Michael> object file.
This is not a problem with g++ or with the libstdc++ library. It
is a problem with single instance of libstdc++ headers serving both
"single" and "pthread" multilibs of AIX without necessary logic in gthr.h.
AIX does not have weak no-op implementations of the pthread
routines in libc because it does not have weak symbols. On AIX, pthread
is a multilib.
Although libstdc++ configuration checks for the thread model and
sees both "single" and "pthread" for each multilib, as appropriate,
gthr-default.h exists meaning bits/c++config.h defines
_GLIBCPP_HAVE_GTHR_DEFAULT. This causes bits/gthr.h to include
gthr-default.h which references all of the pthread functions.
Some libstdc++ header files (e.g., STL) make use of
__gthread_mutex_lock and __gthread_mutex_unlock. Because the libstdc++
headers include gthr-default.h and not gthr-single.h, those get defined
relative to pthread routines, so we get an unwanted dependencies on AIX.
This does not happen with all libstdc++ programs, only those that include
header files which lead to gthr.h.
There is gcc/gthr-aix.h which is not installed or used by
libstdc++ because it only checks "single" or "pthread". To fix this,
something needs to be corrected in the gthr.h logic, but I do not know
what the libstdc++ would find palatable.