From c8ad15b6ff8803d886f31289ea4df826b472918b Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Fri, 22 May 2020 17:52:09 +0000 Subject: [PATCH] Implement Solaris-like link_map l_refname member. The implementation is based on the public documentation, in particular dlinfo(3) from Solaris. Sponsored by: The FreeBSD Foundation MFC after: 1 week --- lib/libc/gen/dlinfo.3 | 8 +++++++- libexec/rtld-elf/rtld.c | 7 +++++++ sys/sys/link_elf.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/libc/gen/dlinfo.3 b/lib/libc/gen/dlinfo.3 index a801b0bd005d..e5da2bc9ffda 100644 --- a/lib/libc/gen/dlinfo.3 +++ b/lib/libc/gen/dlinfo.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 19, 2020 +.Dd May 21, 2020 .Dt DLINFO 3 .Os .Sh NAME @@ -111,6 +111,7 @@ const void *l_ld; /* Pointer to .dynamic in memory */ struct link_map *l_next, /* linked list of mapped libs */ *l_prev; caddr_t l_addr; /* Load Offset of library */ +const char *l_refname; /* Object this one filters for */ .Ed .Bl -tag -width ".Va l_addr" .It Va l_base @@ -133,6 +134,11 @@ structure on the link-map list. The load offset of the object, that is, the difference between the actual load address and the base virtual address the object was linked at. +.It Va l_refname +A name of the object this object filters for, if any. +If there are more then one filtee, a name from the first +.Dv DT_FILTER +dynamic entry is supplied. .El .It Dv RTLD_DI_SERINFO Retrieve the library search paths associated with the given diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index 225d1c19350b..dc50b99ab5e7 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -1207,6 +1207,9 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath, *needed_filtees_tail = nep; needed_filtees_tail = &nep->next; + + if (obj->linkmap.l_refname == NULL) + obj->linkmap.l_refname = (char *)dynp->d_un.d_val; } break; @@ -1402,6 +1405,10 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath, } obj->dynsymcount += obj->symndx_gnu; } + + if (obj->linkmap.l_refname != NULL) + obj->linkmap.l_refname = obj->strtab + (unsigned long)obj-> + linkmap.l_refname; } static bool diff --git a/sys/sys/link_elf.h b/sys/sys/link_elf.h index 7ea1b4e69ebc..6114765baa4a 100644 --- a/sys/sys/link_elf.h +++ b/sys/sys/link_elf.h @@ -65,6 +65,7 @@ typedef struct link_map { const void *l_ld; /* Pointer to .dynamic in memory */ struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ caddr_t l_addr; /* Load Offset of library */ + const char *l_refname; /* object we are filtering for */ } Link_map; struct r_debug {