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 <jgopensource@proton.me>
Reviewed by:	jrtc27
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D51448
This commit is contained in:
Konstantin Belousov
2025-07-21 07:09:53 +03:00
parent 5df4eb5fd7
commit db9ef9d5f5
+1 -1
View File
@@ -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)