Implementing native TLS on OS X in DMD
Dan Olson via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Sat Jan 9 12:07:34 PST 2016
Dan Olson <gorox at comcast.net> writes:
> Jacob Carlborg <doob at me.com> writes:
>
>> On 2016-01-08 17:40, Jacob Carlborg wrote:
>>
>> Adding the assembly for convenience
>>
>>> * I'm looking at the assembly output of LDC, it looks liked LDC aligns
>>> to the size of the type, i.e. "int" to 4 and "long" to 8 and so on, is
>>> that the case?
>>
>> Without initializer:
>>
>> .tbss __D4main1ai$tlv$init, 4, 3
>>
>> BTW, do you know that the above 3 is?
>
> 3 is alignment like .p2align (power of 2 alignment).
> 2^3 in this case (8-byte)
>
>>> * It looks like the only uses the above form of alignment if the symbol
>>> is placed in the __thread_bss section, i.e. doesn't have an initializer.
>>> Does that make sense? If it's has a initializer and is placed in the
>>> __thread_data section it will have the alignment of 3 or 4, depending of
>>> the size of the variable.
>>
>> With initializer:
>>
>> .section __DATA,__thread_data,thread_local_regular
>> .align 3
>> __D4main1ai$tlv$init:
>> .long 4
>
> Same 8-byte alignment (OSX .align is synonym for .p2align).
>
> The tbss and tdata declarations match.
Just re-reading and it looks like alignments in your example are too big
for a 4-byte type, assuming var is an int. .align only needs to be 2 here.
$ cat tls.c
__thread int x;
__thread int y = 42;
$ clang -S tls.c
$ cat tls.s
.section __TEXT,__text,regular,pure_instructions
.macosx_version_min 10, 10
.section __DATA,__thread_data,thread_local_regular
.align 2 ## @y
_y$tlv$init:
.long 42 ## 0x2a
.section __DATA,__thread_vars,thread_local_variables
.globl _y
_y:
.quad __tlv_bootstrap
.quad 0
.quad _y$tlv$init
.tbss _x$tlv$init, 4, 2 ## @x
.globl _x
_x:
.quad __tlv_bootstrap
.quad 0
.quad _x$tlv$init
.subsections_via_symbols
More information about the digitalmars-d-ldc
mailing list