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 ).
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/data/gnu/bin/../libexec/gcc/powerpc-ibm-aix6.1.0.0/4.7.2/lto-wrapper
Target: powerpc-ibm-aix6.1.0.0
Configured with: ../configure --enable-languages=c,c++
--prefix=/usr/gnu --enable-threads
--enable-version-specific-runtime-libs --disable-nls
--enable-decimal-float=dpd --with-as=/usr/ccs/bin/as
--with-ld=/usr/ccs/bin/ld --with-gmp=/usr/gnu --with-mpfr=/usr/gnu
--with-mpc=/usr/gnu powerpc-ibm-aix6.1.0.0
Thread model: aix
gcc version 4.7.2 (GCC)

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 ?

Thanks in advance for any replies,
Jason Vas Dias <jason.vas.d...@gmail.com>

<code>
#include <pthread.h>
#include <stdio.h>

struct state
{
    unsigned char
         bit1:1       , bit2:1       , bit3:1       , bit4:1
       , bit5:1       , bit6:1       , bit7:1       , bit8:1
        ;
} ;

__thread struct state my_bits;

void* t1(void *arg)
{    return (*((void**)arg)=&my_bits);
}

void* t2(void *arg)
{    return (*((void**)arg)=&my_bits);
}

int main( int argc , char **argv )
{
    pthread_t pth1={0}, pth2={0};
    void *mb1=0, *mb2 =0;
    pthread_attr_t pthrat={0};
    pthread_attr_init(&pthrat);
    pthread_attr_setstacksize(&pthrat, 1<<20);
    unsigned int n_pth=0;
    if( pthread_create( &pth1, &pthrat, t1,&mb1) == 0)
        n_pth += 1;
    if( pthread_create( &pth2, &pthrat, t2,&mb2) == 0)
        n_pth += 1;
    if( n_pth > 0 )
        pthread_join( pth1, &mb1 );
    if( n_pth > 1 )
        pthread_join( pth2, &mb2 );
    pthread_attr_destroy(&pthrat);

    fprintf(stderr,"main : %p %p %p\n", &my_bits, mb1, mb2);
}
</code>

So only on AIX does this program print :

$ ./ttls
main : 20213aac 20213aac 20213aac

On Linux / Solaris / HP-UX, it prints 3 different addresses:
Solaris:
main : ff382a38 ff1e0238 ff1e0a38
Linux:
main : 0x7f3c033f96ff 0x7f3c033f76ff 0x7f3c02c246ff

Reply via email to