This is the mail archive of the gcc@gcc.gnu.org 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 looking for pointers into the GCC codebase


On Wed, Oct 15, 2003 at 08:16:58PM +0800, Jonathan Wilson wrote:
> 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

This is actually the hardest part.  I'm not quite sure how to make
this happen, and get all the correct checks enabled.  For the moment,
let's ignore this and use the existing syntax:

	__thread int foo;

we can come back to it after everything else works.

> 2.all variable marked "thread local" need to go into a segment called .tls$ 
> instead of wherver else they would go

This happens with the TARGET_ASM_SELECT_SECTION target hook.  
You'll need to write a new one to handle this.  You'll know
to put a variable in the .tls section when 

  if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))

> 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)

Things to do:

(1) Add a new enum tls_dialect entry.
(2) Add new code to legitimize_tls_address to handle your case.

    I suggest that the computation of edx above be represented
    during early compilation as generated by get_thread_pointer:

	   (unspec:SI [(const_int 0)] UNSPEC_TP)

    This allows good optimization so that we don't have to 
    recompute the value.  Later we can add a post-reload splitter
    to make this schedule a bit better.

I guess that's it.


r~


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