Hi,
I am trying to port a program from Linux to macosx. The program uses
several features one of them is Thread-Local Storage. It uses __thread
GCC attribute for this.
The program compiles fine on Linux i386 but fails on macosx
10.6.4/clang2.8 with following error: "error: thread-local storage is
unsupported for the current target"
My question is: what is the status of this feature? Are you going to
implement it any time soon? If not - what is the best alternative of
TLS on macosx/clang?
This issue a little bit confusing as the LLVM2.0 release note [1]
states that "A number of ELF features are now supported by LLVM,
including ... Thread Local Storage (TLS) with the __thread keyword"
[1] http://llvm.org/releases/2.0/docs/ReleaseNotes.html
Hi,
I am trying to port a program from Linux to macosx. The program uses
several features one of them is Thread-Local Storage. It uses __thread
GCC attribute for this.
The program compiles fine on Linux i386 but fails on macosx
10.6.4/clang2.8 with following error: "error: thread-local storage is
unsupported for the current target"
My question is: what is the status of this feature?
It depends on the OS, it isn't a clang specific feature.
Are you going to
implement it any time soon? If not - what is the best alternative of
TLS on macosx/clang?
pthreads.
This issue a little bit confusing as the LLVM2.0 release note [1]
states that "A number of ELF features are now supported by LLVM,
including ... Thread Local Storage (TLS) with the __thread keyword"
OS X doesn't use ELF.
-eric
Hello
My question is: what is the status of this feature? Are you going to
implement it any time soon? If not - what is the best alternative of
TLS on macosx/clang?
This issue a little bit confusing as the LLVM2.0 release note [1]
states that "A number of ELF features are now supported by LLVM,
including ... Thread Local Storage (TLS) with the __thread keyword"
The problem is that MacOS X does not support thread local storage stuff at all.
Regardless of compiler used. You'll have same error message with gcc, etc.
Hi
Hi,
I am trying to port a program from Linux to macosx. The program uses
several features one of them is Thread-Local Storage. It uses __thread
GCC attribute for this.
The program compiles fine on Linux i386 but fails on macosx
10.6.4/clang2.8 with following error: "error: thread-local storage is
unsupported for the current target"
My question is: what is the status of this feature?
It depends on the OS, it isn't a clang specific feature.
Is it spcific to OS or binary format? I have following simple program
__thread int a = 0;
void main() {
a = 2;
}
that is fails to compile with gcc-4.2 and clang-2.8 but compiles fine
with gcc-4.5 from macports. I believe that gcc-4.5 has support of this
feature on macosx. The binary produced by gcc-4.5 is Mach-O file.
$ file ./a.out
./a.out: Mach-O 64-bit executable x86_64
I also googled following ticket that requests __thread "support on
macosx" rdar://6850750: thread-local storage not supported for this target . It is closed as
duplicated of an internal issue. The reporter claims "suggests that
the specification of thread-local storage (tls) is ELF specific, it
really isn't. In fact the document referred to by the gcc page
referenced in "SUMMARY:" describes the required implementation details
and they are easily implemented on Darwin/Mac OS X without any need
for ELF."
Are you going to
implement it any time soon? If not - what is the best alternative of
TLS on macosx/clang?
pthreads.
Yeah, there are pthread_getspecific/pthread_setspecific functions but
they are less convenient than __thread.
It depends on the OS, it isn't a clang specific feature.
Is it spcific to OS or binary format? I have following simple program
It's specific to the OS (which generally has a specific binary format).
__thread int a = 0;
void main() {
a = 2;
}
that is fails to compile with gcc-4.2 and clang-2.8 but compiles fine
with gcc-4.5 from macports. I believe that gcc-4.5 has support of this
feature on macosx. The binary produced by gcc-4.5 is Mach-O file.
$ file ./a.out
./a.out: Mach-O 64-bit executable x86_64
Yes, it uses an emulated tls that ends up being calls out to pthread
and semaphore functions. I don't believe there's any plans to implement
this sort of thing in clang - at the least I don't plan to 
I also googled following ticket that requests __thread "support on
macosx" rdar://6850750: thread-local storage not supported for this target . It is closed as
duplicated of an internal issue. The reporter claims "suggests that
the specification of thread-local storage (tls) is ELF specific, it
really isn't. In fact the document referred to by the gcc page
referenced in "SUMMARY:" describes the required implementation details
and they are easily implemented on Darwin/Mac OS X without any need
for ELF."
Sure. It is possible to implement it in any format with the proper relocations.
Are you going to
implement it any time soon? If not - what is the best alternative of
TLS on macosx/clang?
pthreads.
Yeah, there are pthread_getspecific/pthread_setspecific functions but
they are less convenient than __thread.
Agreed.
-eric
Presumably someone plans to implement C++0x's thread_local storage duration?
Implementing thread_local would be great if you're interested, please have it generate the same IR as __thread.
-Chris
There is nothing official here, but we can hope to see __thread support in the future on OS X.
Mach-O TSL generation was added to llvm so times ago, and clang accept to compile it if target is darwin 11 
-- Jean-Daniel
Implementing thread_local at this point would be premature, I think, since there is still an AFAIK unresolved issue about object lifetime. I see two proposals for resolution of this issue, but neither has been adopted into the working paper.
Doug may know more, though.
Sebastian
C1X also has a _Thread_local storage qualifier, which has the same semantics as __thread.
David
-- Sent from my PDP-11