__emutls_v & __emutls_t
Timo Sintonen
t.sintonen at luukku.com
Sun Dec 22 00:16:31 PST 2013
On Sunday, 22 December 2013 at 02:01:15 UTC, Mike wrote:
> I need to make a startup procedure for my ARM Cortex-M
> platform. In C/C++ this includs copying the .data segment to
> RAM and initializing the .bss segment to 0.
>
> 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"
>
> minlibd's linker script
> (https://bitbucket.org/timosi/minlibd/src/c4503befb556ff3edf04eeb63c384e0ea723a6aa/tools/ldscript4?at=default)
> does not deal with these sections, I'm assuming because my
> version of GDC (yesterday's 4.8.2 backport {Thanks Johannes})
> has changes for supporting emulated TLS.
>
> My GDC is configured with --disable-tls and --disable-threads,
> so I believe I could treat these the same as __gshared
> variables, but I need to first understand what these sections
> are and what they contain.
>
> 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 have not investigated this but this is my assumption:
Tdata section is just like ordinary data section, but every
thread has its own copy of it. Data section is copied from rom to
ram when the program starts, but tdata has to be copied every
time a new thread starts. The address of data section is fixed
and variables are addressed with absolute address (which the
linker calculates at link time) The address of tls data is not
known at link time so addresses are relative to the start of
current tls. In standard gcc compiler the call is __aeabi_read_tp
that should return the start of current tls.
Something like this in normal gcc. In minlibd I have built my own
tls on top of this.
Emutls seems to group tdata and tbss in one section. The initial
values are stored in the rodata section and the data section is
the real tdata.
Rodata should be put in rom, in linker script before any other
rodata (because rodata.* consumes all remaining rodata sections)
and marked with start and end like tdata.
As we now have only one thread, I would put the data section to a
fixed address before data (again, data.* will consume all
remaining data sections) and marked like tdata so that it is
possible to copy the data here from rom at init. This address
should be available when the compiler calls it. Look at tls.d in
minlibd example.
More information about the D.gnu
mailing list