On Mon, Mar 11, 2013 at 3:46 PM, Jason Vas Dias
<jason.vas.d...@gmail.com> wrote:
> Hi - I wonder if anyone could please tell me if gcc's thread local
> storage support is meant to be enabled on AIX or not -
> I've built gcc-4.7.2 on AIX 6.1 OK,   with "---enable-threads" ,
> using the AIX system /usr/ccs/bin ld and as ,  both of which
> claim to provide TLS support , but now this test program is getting
> the same address for its  __thread variable in different threads -
>  it is compiled and linked without warnings or error, and prints three
> different addresses at the end on Linux, Solaris x86 & SPARC, and
> HP-UX,
> but not on AIX 6.1 .  This also happens with the IBM freeware
> gcc-4.4.6.  Yet 4.7.2's libgomp was built OK ... doesn't this depend
> on TLS?
>
> Must I use --enable-tls as well as --enable-threads in configuration
> options and rebuild GCC ? Is this likely to work ?
>
> gcc-4.7.2 is reporting its thread model as 'aix' - shouldn't this be
> 'posix' ( the system /usr/lib/libpthread.a is installed and the
> pthread_* headers look POSIX compatible ).

> Shouldn't GCC be terminating compilation with an error if it
> encounters use of __thread when TLS is not enabled ?
> Is there an option to enable this / if not , could one be added ?
> Is there an option to make GCC tell the user if TLS is enabled or not
> - again, if not, could there be one ?
>
> I don't think gcc should be allowing programmers to assume TLS is in
> use when it is not - this is dangerous!
>
> If GCC does not support TLS with AIX 'ld' + 'as' (which seems likely),
>  could this not be documented somewhere in the installation
> documentation (it does not appear to be) ?   Any plans to enable it in
> near future ?

First, because of the way that AIX supports pthreads, GCC requires
different libraries for pthread and non-pthread code.  GCC -pthread
links with the pthread version of the libraries.  This is why thread
model is reported as "aix" and not "posix".

Second, when native TLS is not available, GCC emulates TLS using
pthread keys.  All previous and current releases of GCC do not support
native TLS on AIX.  GCC 4.8 will provide TLS on AIX, as listed in the
announcements for the release.

Third, one should not add configuration options like "--enable-tls" or
"--enable-threads".  The defaults are correct and will enable the
appropriate features for the system.  No one chose to implement a
feature but leave it disabled by default.  No one is hiding features
and one should not approach the configuration process by trying to
force override options.

Compiling your example with GCC 4.8 snapshot from last night produces
the following on AIX 7.1:

$ ./xgcc -B./ -O2 -pthread code.c
$ ./a.out
main : 200080d0 20112000 20218000
$ ./xgcc -B./ -O2 -pthread -maix64 code.c
$ ./a.out
main : 11000de20 11011a000 110221000

Thanks, David

Reply via email to