[PATCH v2] i386: Update ___tls_get_addr to preserve vector registers

H.J. Lu hjl.tools@gmail.com
Tue Jun 10 12:01:25 GMT 2025


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.


>         -hpa
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250610/c54595ad/attachment.htm>


More information about the Libc-alpha mailing list