Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 May 2025 22:15:36 GMT
From:      Jessica Clarke <jrtc27@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: d71c97026366 - main - rtld-elf: Push TLS_DTV_OFFSET into tls_get_addr_common's arguments
Message-ID:  <202505062215.546MFaNW063121@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jrtc27:

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

commit d71c97026366eff5d8a701077fd9e1499a28c7b1
Author:     Jessica Clarke <jrtc27@FreeBSD.org>
AuthorDate: 2025-05-06 22:14:52 +0000
Commit:     Jessica Clarke <jrtc27@FreeBSD.org>
CommitDate: 2025-05-06 22:14:52 +0000

    rtld-elf: Push TLS_DTV_OFFSET into tls_get_addr_common's arguments
    
    Rather than calling tls_get_addr_common with a biased ti_offset and
    un-biasing the return value, we can instead un-bias the offset given in
    the first place and not need to adjust the return value. This is in fact
    how the MIPS implementation worked, and makes this call tail-recursive.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D50187
---
 libexec/rtld-elf/powerpc/reloc.c   | 6 ++----
 libexec/rtld-elf/powerpc64/reloc.c | 6 ++----
 libexec/rtld-elf/riscv/reloc.c     | 6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/libexec/rtld-elf/powerpc/reloc.c b/libexec/rtld-elf/powerpc/reloc.c
index 82a9669e3e73..4d5b1be6a429 100644
--- a/libexec/rtld-elf/powerpc/reloc.c
+++ b/libexec/rtld-elf/powerpc/reloc.c
@@ -838,10 +838,8 @@ void*
 __tls_get_addr(tls_index* ti)
 {
 	uintptr_t **dtvp;
-	char *p;
 
 	dtvp = &_tcb_get()->tcb_dtv;
-	p = tls_get_addr_common(dtvp, ti->ti_module, ti->ti_offset);
-
-	return (p + TLS_DTV_OFFSET);
+	return (tls_get_addr_common(dtvp, ti->ti_module, ti->ti_offset +
+	    TLS_DTV_OFFSET));
 }
diff --git a/libexec/rtld-elf/powerpc64/reloc.c b/libexec/rtld-elf/powerpc64/reloc.c
index 70acd0ac390d..b0b5ca6419f7 100644
--- a/libexec/rtld-elf/powerpc64/reloc.c
+++ b/libexec/rtld-elf/powerpc64/reloc.c
@@ -735,10 +735,8 @@ void*
 __tls_get_addr(tls_index* ti)
 {
 	uintptr_t **dtvp;
-	char *p;
 
 	dtvp = &_tcb_get()->tcb_dtv;
-	p = tls_get_addr_common(dtvp, ti->ti_module, ti->ti_offset);
-
-	return (p + TLS_DTV_OFFSET);
+	return (tls_get_addr_common(dtvp, ti->ti_module, ti->ti_offset +
+	    TLS_DTV_OFFSET));
 }
diff --git a/libexec/rtld-elf/riscv/reloc.c b/libexec/rtld-elf/riscv/reloc.c
index aa2cc97ae769..80a0acd3510f 100644
--- a/libexec/rtld-elf/riscv/reloc.c
+++ b/libexec/rtld-elf/riscv/reloc.c
@@ -496,10 +496,8 @@ void *
 __tls_get_addr(tls_index* ti)
 {
 	uintptr_t **dtvp;
-	void *p;
 
 	dtvp = &_tcb_get()->tcb_dtv;
-	p = tls_get_addr_common(dtvp, ti->ti_module, ti->ti_offset);
-
-	return ((char*)p + TLS_DTV_OFFSET);
+	return (tls_get_addr_common(dtvp, ti->ti_module, ti->ti_offset +
+	    TLS_DTV_OFFSET));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505062215.546MFaNW063121>