Status of threading and TLS

Marcel Moolenaar xcllnt at mac.com
Fri Sep 1 19:11:40 UTC 2006


On Sep 1, 2006, at 11:44 AM, Marcel Moolenaar wrote:
> On Sep 1, 2006, at 11:40 AM, Peter Grehan wrote:
>
>>> If anyone has any suggestions why for libpthread we end up
>>> with r2 off by 8 bytes, I'm happy to hear it...
>>
>>  I don't have access to a PPC machine at the moment, but would it  
>> have anything to do with:
>>
>> struct ppc32_tp {
>>         void            *tp_dtv;        /* dynamic thread vector */
>>         uint32_t        _reserved_;
>>         double          tp_tls[0];      /* static TLS */
>> };
>>
>>  I think the last element was put in for alignment, but would that  
>> possibly have an effect somewhere else, in that it's forcing an 8- 
>> byte pad somewhere ?
>
> I've been thinking about that too. I played with the following  
> definition
> to see if it made a difference:
>
> union ppc32_tp {
> 	void *tp_ptr[2];
> 	double _align_;
> };
>
> It didn't make a difference :-/

I found it!

The ucontext on powerpc is 16-bytes aligned. This means that struct tcb
is a multiple of 16-bytes. It so happened that there were 8 bytes of
padding after struct ppc32_tp. So, we need to force 16-byte alignment
for struct ppc32_tp or add internal padding before struct tcb so as to
eliminate padding after it. I opted for the latter...

All is well!

-- 
Marcel Moolenaar
xcllnt at mac.com




More information about the freebsd-ppc mailing list