[Bug 254774] [rtld] dl_iterate_phdr: dlpi_tls_data should be the iterated module's TLS image instead of TLS initialization image

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Mon Apr 5 03:13:21 UTC 2021


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=254774

--- Comment #3 from Konstantin Belousov <kib at FreeBSD.org> ---
(In reply to Brandon Bergren from comment #2)
The drv reallocation should not affect dl_iterate_phdr() result.

That said, for dl_iterate_phdr() for dynamic binary, the fix is indeed simple:
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 733c3c80b70f..0ded117b1019 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -3909,13 +3909,16 @@ dlinfo(void *handle, int request, void *p)
 static void
 rtld_fill_dl_phdr_info(const Obj_Entry *obj, struct dl_phdr_info *phdr_info)
 {
+       tls_index ti;

        phdr_info->dlpi_addr = (Elf_Addr)obj->relocbase;
        phdr_info->dlpi_name = obj->path;
        phdr_info->dlpi_phdr = obj->phdr;
        phdr_info->dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]);
        phdr_info->dlpi_tls_modid = obj->tlsindex;
-       phdr_info->dlpi_tls_data = obj->tlsinit;
+       ti.ti_module = obj->tlsindex;
+       ti.ti_offset = 0;
+       phdr_info->dlpi_tls_data = __tls_get_addr(&ti);
        phdr_info->dlpi_adds = obj_loads;
        phdr_info->dlpi_subs = obj_loads - obj_count;
 }

But for static binary where libc TLS implementation is used, we do not provide
working __tls_get_addr().  Do you need this for static binaries, or it would
be only the consistency that is hurt if libc implementation is provided later?

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list