Operating System - Linux
1752818 Members
4168 Online
108789 Solutions
New Discussion юеВ

thread-local storage doesnt work with gcc

 
SOLVED
Go to solution
Frank Mehlhose
Occasional Advisor

thread-local storage doesnt work with gcc

Hi all,
Is there a way to use thread-local storage with gcc compiler on HP-UX 11.11?
I am using gcc 3.3.3 and want to compile some test code:

thread_locals_sub.c:
--------------------------------------------------
#include
#include

static __thread int i;
void *t(void *x) {
for(i = 0; i<100; i++)
printf("%d: %d\n",pthread_self(),i);
return;
}

--------------------------------------------------

CC lets me compile the thread_globals_sub object:
cc -c -o thread_globals_sub.o thread_globals_sub.c -lpthread

But gcc comes up with an error:
gcc -c -o thread_globals_sub.o thread_globals_sub.c -lpthread
thread_globals_sub.c:5: error: thread-local storage not supported for this target

It would be nice if I could make the object with the gcc. Or if there is no way, then it would be nice to know the reason.
14 REPLIES 14
Dennis Handly
Acclaimed Contributor

Re: thread-local storage doesnt work with gcc

>I am using gcc 3.3.3 and want to compile some test code:

As the error message says, you can't, yet.
3.4.3 works, at least on IPF.
Steve Ellcey
Valued Contributor

Re: thread-local storage doesnt work with gcc

With GCC you should use -pthread or -mt options instead of -lpthread. -lpthread will add the pthread library but -pthread will add the library and add the -D_REENTRANT -D_THREAD_SAFE and -D_POSIX_C_SOURCE=199506L macro definitions during the compilation. You still probably need a newer version of GCC than 3.3.3.
Frank Mehlhose
Occasional Advisor

Re: thread-local storage doesnt work with gcc

I have tried it with the -pthread option, but it still does not work.

After vacation I will try to test it with a newer version of gcc.

Steven Schweda
Honored Contributor

Re: thread-local storage doesnt work with gcc

> [...] a newer version of gcc.

They are up to 4.2.1, now. I did better not
building Java, as there seems to be a known
out-of-memory problem in the middle of that,
but otherwise it seemed to go well enough on
11.11 (PA-RISC).
Frank Mehlhose
Occasional Advisor

Re: thread-local storage doesnt work with gcc

I have installed the gcc-4.2.0, but it still doesn't work.
(/opt/hp-gcc-4.2.0/bin/gcc -c -pthread -o thread_globals_sub.o thread_globals_sub.c)

I assume that some of the system librarys are too old, or that the linker has the wrong version. Both, the librarys and the linker have to support TLS. But I'am not sure about it.

I will not update all these items. So I have to compile the object with the cc.

Thanks for trying to help me.
Dennis Handly
Acclaimed Contributor

Re: thread-local storage doesnt work with gcc

>I have installed the gcc-4.2.0, but it still doesn't work.

What do you meant doesn't work? You get the same error message?

>I assume that some of the system libraries are too old, or that the linker has the wrong version. Both, the libraries and the linker have to support TLS.

Static TLS should be supported on any 11.11. Dynamic TLS needs 11.23.
Frank Mehlhose
Occasional Advisor

Re: thread-local storage doesnt work with gcc

>What do you meant doesn't work? You get the same error message?
Yes, its the same error message with gcc 3.3.3 and 4.2.0:
thread_globals_sub.c:5: error: thread-local storage not supported for this target

This is the output of the -v option of gcc 4.2.0:
--------------------------------------------------
XXX@YYY: ./gcc -v
Using built-in specs.
Target: hppa1.1-hp-hpux11.11
Configured with: /tmp/gcc-4.2.0.tar.gz/gcc-4.2.0/configure --host=hppa1.1-hp-hpux11.11 --target=hppa1.1-hp-hpux11.11 --build=hppa1.1-hp-hpux11.11 --prefix=/opt/hp-gcc-4.2.0 --with-gnu-as --without-gnu-ld --with-ld=/usr/ccs/bin/ld --enable-threads=posix --enable-languages=c,c++
Thread model: posix
gcc version 4.2.0
--------------------------------------------------

Dennis Handly
Acclaimed Contributor

Re: thread-local storage doesnt work with gcc

Perhaps this is hinting you need to go to Integrity? ;-)

Steve would have to tell you why TLS doesn't seem to work.
Steve Ellcey
Valued Contributor

Re: thread-local storage doesnt work with gcc

It looks like existing GCC's on the HP web site, including 4.2.1, were built without posix threads being enabled. This is a configuration option specified when GCC is built. The next (4.2.2, 4.3) GCC's will default to having posix threads being enabled by on HPPA 11.*. If you build GCC yourself you could set --enable-threads=posix during configuration and then you would be able to use threads and thread local storage.