git: f1830ad9e727 - stable/14 - rtld amd64: extend osrel check to enable tlsbase op on stable/14

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 12 Jun 2025 19:31:13 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=f1830ad9e727f990d0124e89d9a9f7cd759d42a6

commit f1830ad9e727f990d0124e89d9a9f7cd759d42a6
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-06-12 19:29:19 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-06-12 19:29:19 +0000

    rtld amd64: extend osrel check to enable tlsbase op on stable/14
    
    This is a direct commit to stable/14.
    
    Reported by:    Mark Millard <marklmi@yahoo.com>
    Sponsored by:   The FreeBSD Foundation
---
 libexec/rtld-elf/amd64/reloc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libexec/rtld-elf/amd64/reloc.c b/libexec/rtld-elf/amd64/reloc.c
index 74693d35ba1d..e46f6bc2e9b5 100644
--- a/libexec/rtld-elf/amd64/reloc.c
+++ b/libexec/rtld-elf/amd64/reloc.c
@@ -519,6 +519,8 @@ void
 allocate_initial_tls(Obj_Entry *objs)
 {
 	void *addr;
+	int osrel;
+
 
 	/*
 	 * Fix the size of the static TLS block by using the maximum
@@ -533,7 +535,9 @@ allocate_initial_tls(Obj_Entry *objs)
 	 * This does not use _tcb_set() as it calls amd64_set_tlsbase()
 	 * which is an ifunc and rtld must not use ifuncs.
 	 */
-	if (__getosreldate() >= P_OSREL_TLSBASE)
+	osrel = __getosreldate();
+	if (osrel >= P_OSREL_TLSBASE ||
+	    (P_OSREL_MAJOR(osrel) == 14 && osrel >= 1403502))
 		sysarch(AMD64_SET_TLSBASE, &addr);
 	else if (__getosreldate() >= P_OSREL_WRFSBASE &&
 	    (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0)