On Sunday, 22 December 2013 at 10:00:28 UTC, Johannes Pfau wrote:
If I declare global variables in D as...

__gshared int GlobalDataVar = 2;
__gshared int GlobalBssVar;

... these get put in .data and .bss respectively, and I know what to do in my startup procedure:

However if I declare thread local variables in D as...

int TLSDataVar = 1;
int TLSBssVar;

... two symbols for each variable are created: one in the section ".rodata.__emutls_t" and the other in section ".data.__emutls_v"

I know this may be more specific to GCC than GDC, but if you know something about these sections, please let me know, or point me to some resource that will help me understand them.

Thanks,
Mike

I wrote a long answer here and managed to crash the newsreader before
it was sent so here's a short summary:

Damn! Such valuable information lost... but I understand.


The emutls code is here:
https://github.com/D-Programming-GDC/GDC/blob/master/libphobos/libdruntime/gcc/emutls.d

The compiler calls __emutls_get_address, every symbol gets a
emutls_object_t.

If you have only one thread you could to reimplement emutls.d to
avoid dynamic allocation. But the better solution is probably to add a --single-thread-only option to GDC which rewrites TLS variables to
normal variables.

That's making a lot of sense, my memory.map file looks like this:

 .rodata.__emutls_t._D5start9TLSBssVari
                0x0800006c        0x4 start.o
 .rodata.__emutls_t._D5start10TLSDataVari
                0x08000070        0x4 start.o

.data.__emutls_v._D5start9TLSBssVari
                0x08000080       0x10
 .data.__emutls_v._D5start9TLSBssVari
                0x08000080       0x10 start.o
0x08000080 __emutls_v._D5start9TLSBssVari

.data.__emutls_v._D5start10TLSDataVari
                0x08000090       0x10
 .data.__emutls_v._D5start10TLSDataVari
                0x08000090       0x10 start.o
0x08000090 __emutls_v._D5start10TLSDataVari


In emutls.d, emutls_object_t is exactly 16 bytes, and each symbol in .data.__emutls_v is also 16 bytes. So, I'm assuming .data.__emutls_v sections contain the emutls_object_t object.

Therefore, given the following TLS variables:

int TLSDataVar = 1;
int TLSBssVar;

... and the memory.map information above, examining 0x0800006c and 0x08000070 in gdb yields the following:

(gdb) x 0x08000070
0x8000070 <__emutls_t._D5start10TLSDataVari>:   0x00000001
(gdb) x 0x0800006c
0x800006c <__emutls_t._D5start9TLSBssVari>:     0x00000000

So, these must be the initial values each of the variables.

Now that I have some hypothesis as to what these sections are, I guess I just need to figure out what to do with these in the startup routine. Timo, any ideas?

Reply via email to