aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-04-05 03:05:44 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-04-23 11:14:06 +0000
commitc3f97dd75a1c294c4f60f42b604ee8bcda17be09 (patch)
treea4132cba0755de908ac43e94e42921c758bac377
parenta574fbf34ba94be106c8c8dea11cdb13ab2fbe54 (diff)
downloadsrc-c3f97dd75a1c294c4f60f42b604ee8bcda17be09.tar.gz
src-c3f97dd75a1c294c4f60f42b604ee8bcda17be09.zip
rtld dl_iterate_phdr(): dlpi_tls_data is wrong
(cherry picked from commit d36d6816151705907393889d661cbfd25c630ca8)
-rw-r--r--lib/libc/gen/dl_iterate_phdr.37
-rw-r--r--libexec/rtld-elf/Symbol.map1
-rw-r--r--libexec/rtld-elf/rtld.17
-rw-r--r--libexec/rtld-elf/rtld.c8
-rw-r--r--sys/sys/param.h2
5 files changed, 21 insertions, 4 deletions
diff --git a/lib/libc/gen/dl_iterate_phdr.3 b/lib/libc/gen/dl_iterate_phdr.3
index 6e952dc13b57..fe4face9eeb7 100644
--- a/lib/libc/gen/dl_iterate_phdr.3
+++ b/lib/libc/gen/dl_iterate_phdr.3
@@ -15,7 +15,7 @@
.\"
.\" $OpenBSD: dl_iterate_phdr.3,v 1.3 2007/05/31 19:19:48 jmc Exp $
.\" $FreeBSD$
-.Dd October 9, 2014
+.Dd April 5, 2021
.Dt DL_ITERATE_PHDR 3
.Os
.Sh NAME
@@ -80,7 +80,10 @@ The counter of the object unloads performed by the dynamic linker.
.It Fa dlpi_tls_modid
The TLS index of the object.
.It Fa dlpi_tls_data
-A pointer to the initialization data for the object TLS segment.
+A pointer to the calling thread' TLS data segment for this module,
+if it was allocated,
+.Dv NULL
+otherwise.
.El
.Pp
Future versions of
diff --git a/libexec/rtld-elf/Symbol.map b/libexec/rtld-elf/Symbol.map
index 13068c5626dc..0a9eac82cf05 100644
--- a/libexec/rtld-elf/Symbol.map
+++ b/libexec/rtld-elf/Symbol.map
@@ -34,4 +34,5 @@ FBSDprivate_1.0 {
_r_debug_postinit;
_rtld_version__FreeBSD_version;
_rtld_version_laddr_offset;
+ _rtld_version_dlpi_tls_data;
};
diff --git a/libexec/rtld-elf/rtld.1 b/libexec/rtld-elf/rtld.1
index 10dd7986903a..47bdc028b22d 100644
--- a/libexec/rtld-elf/rtld.1
+++ b/libexec/rtld-elf/rtld.1
@@ -416,6 +416,13 @@ See
Also it indicates the presence of
.Va l_refname
member of the structure.
+.It Dv _rtld_version_dlpi_tls_data
+The
+.Va dlpi_tls_data
+member of the structure
+.Vt dl_phdr_info
+contains the address of the module TLS segment for the calling thread,
+and not the address of the initialization segment.
.El
.Sh FILES
.Bl -tag -width ".Pa /var/run/ld-elf32.so.hints" -compact
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index b186bebbfefc..4749e3a50d72 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -3889,13 +3889,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;
}
@@ -5894,3 +5897,6 @@ int _rtld_version__FreeBSD_version = __FreeBSD_version;
extern char _rtld_version_laddr_offset __exported;
char _rtld_version_laddr_offset;
+
+extern char _rtld_version_dlpi_tls_data __exported;
+char _rtld_version_dlpi_tls_data;
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 28a1cf981a58..1930af51f7da 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -60,7 +60,7 @@
* in the range 5 to 9.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 1300500 /* Master, propagated to newvers */
+#define __FreeBSD_version 1300501 /* Master, propagated to newvers */
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,