Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jun 2025 12:22:52 -0700
From:      Mark Millard <marklmi@yahoo.com>
To:        Konstantin Belousov <kib@freebsd.org>, dev-commits-src-main@freebsd.org
Subject:   RE: git: 883596411327 - stable/14 - amd64: switch to amd64_set_tlsbase to set tls base [|| (. . . && osrel >= 1403502) test too?]
Message-ID:  <4C483AC0-4082-4EBB-AAC2-01610E0482B3@yahoo.com>
References:  <4C483AC0-4082-4EBB-AAC2-01610E0482B3.ref@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Konstantin Belousov <kib_at_FreeBSD.org> wrote on
Date: Thu, 12 Jun 2025 18:03:03 UTC :

> The branch stable/14 has been updated by kib:
>=20
> URL: =
https://cgit.FreeBSD.org/src/commit/?id=3D88359641132766cc0a8eed283a7a7045=
95c7c119
>=20
> commit 88359641132766cc0a8eed283a7a704595c7c119
> Author:     Konstantin Belousov <kib@FreeBSD.org>
> AuthorDate: 2025-05-22 04:32:25 +0000
> Commit:     Konstantin Belousov <kib@FreeBSD.org>
> CommitDate: 2025-06-12 18:02:50 +0000
>=20
>     amd64: switch to amd64_set_tlsbase to set tls base
>    =20
>     (cherry picked from commit =
aef025fc9b6c8b06677086a93c866ee09622f6fa)
> ---
>  libexec/rtld-elf/amd64/reloc.c | 6 ++++--
>  sys/x86/include/tls.h          | 2 +-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>=20
> diff --git a/libexec/rtld-elf/amd64/reloc.c =
b/libexec/rtld-elf/amd64/reloc.c
> index 7e7f01a5d186..74693d35ba1d 100644
> --- a/libexec/rtld-elf/amd64/reloc.c
> +++ b/libexec/rtld-elf/amd64/reloc.c
> @@ -530,10 +530,12 @@ allocate_initial_tls(Obj_Entry *objs)
>  	addr =3D allocate_tls(objs, 0, TLS_TCB_SIZE, TLS_TCB_ALIGN);
> =20
>  	/*
> -	 * This does not use _tcb_set() as it calls amd64_set_fsbase()
> +	 * This does not use _tcb_set() as it calls amd64_set_tlsbase()
>  	 * which is an ifunc and rtld must not use ifuncs.
>  	 */
> -	if (__getosreldate() >=3D P_OSREL_WRFSBASE &&
> +	if (__getosreldate() >=3D P_OSREL_TLSBASE)

lib/libc/amd64/sys/amd64_set_tlsbase.c has more in its test,
"|| (P_OSREL_MAJOR(osrel) =3D=3D 14 && osrel >=3D 1403502)" :

+DEFINE_UIFUNC(, int, amd64_set_tlsbase, (void *))
+{
+	int osrel;
+
+	osrel =3D __getosreldate();
+	if (osrel >=3D P_OSREL_TLSBASE ||
+	    (P_OSREL_MAJOR(osrel) =3D=3D 14 && osrel >=3D 1403502))
+		return (amd64_set_tlsbase_syscall);
+	return (amd64_set_fsbase);
+}

Is the difference in libexec/rtld-elf/amd64/reloc.c related
to P_OSREL_TLSBASE like testing deliberate?

> +		sysarch(AMD64_SET_TLSBASE, &addr);
> +	else if (__getosreldate() >=3D P_OSREL_WRFSBASE &&
>  	    (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) !=3D 0)
>  		wrfsbase((uintptr_t)addr);
>  	else
> diff --git a/sys/x86/include/tls.h b/sys/x86/include/tls.h
> index 4b6b58b4a5e3..b431c336122c 100644
> --- a/sys/x86/include/tls.h
> +++ b/sys/x86/include/tls.h
> @@ -59,7 +59,7 @@ static __inline void
>  _tcb_set(struct tcb *tcb)
>  {
>  #ifdef __amd64__
> -	amd64_set_fsbase(tcb);
> +	amd64_set_tlsbase(tcb);
>  #else
>   	i386_set_gsbase(tcb);
>  #endif
=20

=3D=3D=3D
Mark Millard
marklmi at yahoo.com




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C483AC0-4082-4EBB-AAC2-01610E0482B3>