<div dir="ltr">It looks like TBSS size is wrong.The bug is in the function Segment<ELFT>::assignVirtualAddress as you pointed.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 3, 2015 at 9:13 AM, Shankar Easwaram <span dir="ltr"><<a href="mailto:shankarke@gmail.com" target="_blank">shankarke@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Ah this is a nasty bug. You might want to checkout if some of the TLS variables are allocated elsewhere? It cannot just disappear from the output.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> On Jun 3, 2015, at 08:16, Adhemerval Zanella <<a href="mailto:adhemerval.zanella@linaro.org">adhemerval.zanella@linaro.org</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> Yes, ldd is generating wrong tbss size.  It is just considering one tbss section<br>
> and not calculating all sections from all objects.  The following example on<br>
> x86_64 shows the issue:<br>
><br>
> --- t0.c ---<br>
><br>
> #include <stdio.h><br>
><br>
> extern __thread int t0;<br>
> extern __thread int t1;<br>
> extern __thread int t2;<br>
> extern __thread int t3;<br>
><br>
> __thread int t4;<br>
> __thread int t5;<br>
> __thread int t6;<br>
> __thread int t7;<br>
><br>
> int main ()<br>
> {<br>
>  t4 = 1;<br>
>  t5 = 2;<br>
>  t6 = 3;<br>
>  t7 = 4;<br>
><br>
>  printf ("%i %i %i %i\n", t0, t1, t2, t3);<br>
>  printf ("%i %i %i %i\n", t4, t5, t6, t7);<br>
><br>
>  return 0;<br>
> }<br>
><br>
> --- t1.c ---<br>
><br>
> __thread int t0;<br>
> __thread int t1;<br>
> __thread int t2;<br>
> __thread int t3;<br>
><br>
> -------------<br>
><br>
> If you build with lld you will see:<br>
><br>
> $ ./t-lld<br>
> 1 1 1 1<br>
> 1 2 3 4<br>
><br>
> Because t{4,5,6,7} space is not taking in consideration.  In fact if you<br>
> check the resulting tbss for the test:<br>
><br>
>  [15] .tbss             NOBITS           0000000000401000  00001000<br>
>       0000000000000010  0000000000000000 WAT       0     0     4<br>
><br>
> Its size is just 0x10 (4 int), where it should be 0x20 (8 ints).<br>
><br>
><br>
>> On 02-06-2015 21:14, Shankar Easwaram wrote:<br>
>> Are you saying it generates wrong section size?  Tbss is very special and I checked the behavior on X86_64 to model it. It does not account for virtual address increase as libc allocates it.<br>
>><br>
>><br>
>>> On Jun 2, 2015, at 17:20, Adhemerval Zanella <<a href="mailto:adhemerval.zanella@linaro.org">adhemerval.zanella@linaro.org</a>> wrote:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> I am tracking some TLS issues with lld and found that it is<br>
>>> generating wrong tbss size for case where multiple modules<br>
>>> have non initialized threads variables.  For instance:<br>
>>><br>
>>> -- t0.c --<br>
>>><br>
>>> __thread int x0;<br>
>>> __thread int x1;<br>
>>> __thread int x2;<br>
>>><br>
>>> extern __thread int e0;<br>
>>> extern __thread int e1;<br>
>>> extern __thread int e2;<br>
>>> extern __thread int e3;<br>
>>><br>
>>> int foo0 ()<br>
>>> {<br>
>>> return x0;<br>
>>> }<br>
>>><br>
>>> int main ()<br>
>>> {<br>
>>> return x0;<br>
>>> }<br>
>>><br>
>>> -- t1.c --<br>
>>><br>
>>> __thread int e0;<br>
>>> __thread int e1;<br>
>>> __thread int e2;<br>
>>> __thread int e3;<br>
>>><br>
>>> ---<br>
>>><br>
>>> lld is generating (for aarch64):<br>
>>><br>
>>> [14] .tbss             NOBITS           0000000000401000  00001000<br>
>>>      0000000000000010  0000000000000000 WAT       0     0     4<br>
>>><br>
>>> Where is just taking in consideration the largest tbss segment, not all<br>
>>> from all objects.  ld generates a correct output:<br>
>>><br>
>>> [17] .tbss             NOBITS           0000000000410dec  00000dec<br>
>>>      000000000000001c  0000000000000000 WAT       0     0     4<br>
>>><br>
>>> My initial idea is that 'lib/ReaderWriter/ELF/SegmentChunks.cpp' /<br>
>>> Segment<ELFT>::assignVirtualAddress is setting wrong slice values, however<br>
>>> playing with this I could not find a correct logic to handle the TBSS.<br>
>>><br>
>>> Any ideas where lld is possible messing the TBSS segments sizes?<br>
</div></div></blockquote></div><br></div>