[PATCH v3] i386: Update ___tls_get_addr to preserve vector registers
Sam James
sam@gentoo.org
Sat Jun 14 09:56:41 GMT 2025
Sam James <sam@gentoo.org> writes:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> On Tue, Jun 10, 2025 at 8:01 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>
>>> On Tue, Jun 10, 2025, 7:47 PM H. Peter Anvin <hpa@zytor.com> wrote:
>>>>
>>>> On 2025-06-09 14:25, H.J. Lu wrote:
>>>> > On Mon, Jun 9, 2025 at 1:47 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> >>
>>>> >> Compiler generates the following instruction sequence for dynamic TLS
>>>> >> access:
>>>> >>
>>>> >> leal tls_var@tlsgd(,%ebx,1), %eax
>>>> >> call ___tls_get_addr@PLT
>>>> >>
>>>> >> CALL instruction is transparent to compiler which assumes all registers,
>>>> >> except for EFLAGS, AX, CX, and DX, are unchanged after CALL. But
>>>> >> ___tls_get_addr is a normal function which doesn't preserve any vector
>>>> >> registers.
>>>> >>
>>>> >> 1. Rename the generic __tls_get_addr function to ___tls_get_addr_internal.
>>>> >> 2. Change ___tls_get_addr to a wrapper function with implementations for
>>>> >> FNSAVE, FXSAVE, XSAVE and XSAVEC to save and restore all vector registers.
>>>> >> 3. dl-tlsdesc-dynamic.h:
>>>> >>
>>>>
>>>> Would it not make more sense to build this functon with
>>>> -mgeneral-regs-only? There doesn't seem to be any reason for this
>>>> function to use vector registers, and that's a huge overhead.
>>>
>>>
>>> It won't work since that function calls other functions.
>>> In my test included in my patch, malloc is called, which uses vector registers.
>>
>> Here is the v3 patch. Changes are
>>
>> 1. Define DL_RUNTIME_RESOLVE_REALIGN_STACK in sysdeps/x86/sysdep.h.
>> 2. Add
>>
>> +ifneq (no,$(have-test-mtls-traditional))
>> CFLAGS-tst-tls23-mod.c += -mtls-dialect=$(have-test-mtls-traditional)
>> +endif
>
> The test changes look good to me, but I don't feel confident enough
> reviewing the rest. I think we need Florian and D.J.
Sorry, I mean DJ.
More information about the Libc-alpha
mailing list