This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: wanting to implement Thread Local Storage on windows and am lookingfor pointers into the GCC codebase

just posted patch for binutils support of TLS to binutils list.

Anyway, the gist of what GCC needs to do:
1.anytime it sees a variable marked with __declspec(thread) it should mark it as "thread local" somehow
2.all variable marked "thread local" need to go into a segment called .tls$ instead of wherver else they would go
3.when the variable is accessed, the folowing must be output: (or something similar)
mov eax, ds:__tls_index
mov ecx, dword ptr fs:__tls_array
mov edx, edx, [ecx+eax*4]
then you do something like:
mov ds:_x[edx], 0 (in this case it sets it to 0)

Thats what it looks like in the obj file.
__tis_index and __tls_array should be marked external (they come from the tlssup.c and atlssup.s respectivly, see my post to the binutils list for details)
if the variable is local to this file, it should be defined as a SEGEF that points to the .tls$ segment.
if the variable is in another file, the same ASM as above is used but it points to an extern not a SEGDEF.

BTW, you cant access a variable thats Thread Local across DLL boundries.

Would like to get all of this stuff into GCC, Binutils and MingW-Runtime for the next release of each (in particular, I want to get it into GCC 3.4 because if I miss the boat, GCC 3.5 is a very long way off)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]