[dmd-internals] __tls_callbacks_a

Walter Bright walter at digitalmars.com
Fri Jan 20 01:12:30 PST 2012


I don't really understand why you cannot define your own tls_callbacks_a to do 
what you want. Incorporate it in your code, and the one from snn.lib will not be 
linked in.

On 1/19/2012 11:53 PM, Alex wrote:
> The way I see it, we can do three things:
>
> a) Do something similar to what mingw is doing:
> http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/trunk/mingw-w64-crt/crt/tlssup.c?revision=4739&view=markup
> (line 44 to 57). This is problematic because we're going to need a
> pragma in D to place data in the right place.
> b) Use a callback registration mechanism. That is, snn.lib defines a
> global handler that it emits to _tls_used. When this handler is
> called, it will enumerate and call all registered callbacks. So we
> would need to expose two functions to register and deregister
> callbacks.
> c) The really dirty way: Add a linker flag that lets you overwrite the
> symbol regardless of previous different definitions.
>
> Any thoughts on what would be best?
>
> Regards,
> Alex
>
> On Fri, Jan 20, 2012 at 3:00 AM, Walter Bright<walter at digitalmars.com>  wrote:
>> Here's the source code for it. If you can propose a change to it, I can
>> merge it in.
>> -----------------------------------------------------------------------------------------
>> /*_ tlsdata.c   Tue Jan 24 1995 */
>> /* Copyright (C) 1995 by Digital Mars */
>> /* All Rights Reserved                          */
>> /* $Revision: 1.1.1.1 $ */
>>
>> #if defined(_WIN32)
>>
>> /************************************************************************
>>   * This file contains the necessary declartions for __declspec(thread)
>>   * support.  The main work is done by the linker.  The values in tls_used
>>   * are fixed up into a special segment by the linker that NT will then
>>   * fix up to FS:__tls_array for each thread.
>>   *   See file tlsseg.asm for other declarations.
>>   */
>>
>>   extern long _tlsstart;
>>   extern long _tlsend;
>>
>>   unsigned _tls_index = 0;  /* index referred to by compiler */
>>   void *_tls_callbacks_a[1] = { 0 };
>>
>>   struct {
>>     void *tlsstart;   /* contains address of start of tls segment (Raw Data
>> Start VA) */
>>     void *tlsend;     /* contains address of end of tls segment */
>>     void *tlsindex;   /* contains address of index into tls segment */
>>     void *tlscallbacks;  /* Pointer to an array of TLS callback functions
>>                             The array is null-terminated, so if there
>>                             is no callback function support, this field
>>                             points to four bytes set to 0.  The prototype
>>                             for these functions is the same as DLL-Entry.
>>                             These are most useful for declspec(thread) tagged
>>                             objects which need to be constructed and
>> destructed
>>                             for each thread that attaches.
>>                           */
>>     long  zerofill;   /* The size in bytes of hte template beyond the
>>                          initialized data defined by tlsstart
>>                          and tlsend.  The total template
>>                          size should be the same as the total size of TLS
>>                          data in the image file.  The zero fill is the amount
>>                          of data that comes after the initialized non-zero
>> data
>>                          The linker fills this in at link time.
>>                        */
>>     long  characteristics;  /* Reserved, currently not used */
>>
>>   } _tls_used = {
>> &_tlsstart,
>> &_tlsend,
>> &_tls_index,
>> &_tls_callbacks_a[0],
>>     0,
>>     0
>>   };
>>
>> #endif
>>
>>
>> _______________________________________________
>> dmd-internals mailing list
>> dmd-internals at puremagic.com
>> http://lists.puremagic.com/mailman/listinfo/dmd-internals
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals
>
>


More information about the dmd-internals mailing list