The branch main has been updated by kib:

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

commit db9ef9d5f517a14160bb3d0a599b8392e01fb400
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2025-07-21 04:09:53 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2025-07-21 05:29:05 +0000

    rtld: do not relocate tlsinit address twice
    
    The addend for PT_TLS p_vaddr value should be obj' relocbase and not
    mapbase. It does not matter for dso which is linked at the address
    zero, but for executables in direct-exec mode with non-zero link
    address mapbase is already at the link base.  Then, adding mapbase to
    phtls->p_vaddr adds twice as much relocbase offset as needed.
    
    PR:     288334
    Reported by:    Jordan Gordeev <jgopensou...@proton.me>
    Reviewed by:    jrtc27
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D51448
---
 libexec/rtld-elf/map_object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c
index 04d17072af77..c6a98b50a165 100644
--- a/libexec/rtld-elf/map_object.c
+++ b/libexec/rtld-elf/map_object.c
@@ -337,7 +337,7 @@ map_object(int fd, const char *path, const struct stat *sb, 
bool ismain)
                obj->tlsalign = phtls->p_align;
                obj->tlspoffset = phtls->p_offset;
                obj->tlsinitsize = phtls->p_filesz;
-               obj->tlsinit = mapbase + phtls->p_vaddr;
+               obj->tlsinit = obj->relocbase + phtls->p_vaddr;
        }
        obj->stack_flags = stack_flags;
        if (note_start < note_end)

Reply via email to