[PATCH 3/4] elf: Use TLS_DTV_OFFSET in __tls_get_addr

Florian Weimer fweimer@redhat.com
Tue Dec 31 23:30:17 GMT 2024


* Adhemerval Zanella Netto:

>> diff --git a/elf/dl-tls.c b/elf/dl-tls.c
>> index 4df83b9bb2..5f3c03edf8 100644
>> --- a/elf/dl-tls.c
>> +++ b/elf/dl-tls.c
>> @@ -890,6 +890,14 @@ _dl_update_slotinfo (unsigned long int req_modid, size_t new_gen)
>>    return the_map;
>>  }
>>  
>> +/* Adjust the TLS variable pointer using the TLS descriptor offset and
>> +   the ABI-specific offset.  */
>> +static inline void *
>> +tls_get_addr_adjust (void *from_dtv, tls_index *ti)
>> +{
>> +  return (void *) (uintptr_t) ((uintptr_t) from_dtv + ti->ti_offset
>> +			       + TLS_DTV_OFFSET);
>> +}
>
> On sysdeps/unix/sysv/linux/x86_64/x32/sysdep.h the code explicitly disables the
> warning to zero-extend; but this should not be affect.  Maybe add a comment 
> that the extra cast is required because on ILP32 the ti_offset could be a
> 64-bit value and thus the whole result would result in a 64-bit value that
> needs to be truncated to a address.

I'm going to add:

  /* Perform arithmetic in uintptr_t to avoid pointer wraparound
     issues.  The outer cast to uintptr_t suppresses a warning about
     pointer/integer size mismatch on ILP32 targets with 64-bit
     ti_offset.  */

Thanks,
Florian



More information about the Libc-alpha mailing list