18647a1edSAlexey Zelkin.\" 28647a1edSAlexey Zelkin.\" Copyright (c) 2003 Alexey Zelkin <phantom@FreeBSD.org> 38647a1edSAlexey Zelkin.\" All rights reserved. 48647a1edSAlexey Zelkin.\" 58647a1edSAlexey Zelkin.\" Redistribution and use in source and binary forms, with or without 68647a1edSAlexey Zelkin.\" modification, are permitted provided that the following conditions 78647a1edSAlexey Zelkin.\" are met: 88647a1edSAlexey Zelkin.\" 1. Redistributions of source code must retain the above copyright 98647a1edSAlexey Zelkin.\" notice, this list of conditions and the following disclaimer. 108647a1edSAlexey Zelkin.\" 2. Redistributions in binary form must reproduce the above copyright 118647a1edSAlexey Zelkin.\" notice, this list of conditions and the following disclaimer in the 128647a1edSAlexey Zelkin.\" documentation and/or other materials provided with the distribution. 138647a1edSAlexey Zelkin.\" 148647a1edSAlexey Zelkin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 158647a1edSAlexey Zelkin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 168647a1edSAlexey Zelkin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 178647a1edSAlexey Zelkin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 188647a1edSAlexey Zelkin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 198647a1edSAlexey Zelkin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 208647a1edSAlexey Zelkin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 218647a1edSAlexey Zelkin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 228647a1edSAlexey Zelkin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 238647a1edSAlexey Zelkin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 248647a1edSAlexey Zelkin.\" SUCH DAMAGE. 258647a1edSAlexey Zelkin.\" 26*c8ad15b6SKonstantin Belousov.Dd May 21, 2020 278647a1edSAlexey Zelkin.Dt DLINFO 3 28aa12cea2SUlrich Spörlein.Os 298647a1edSAlexey Zelkin.Sh NAME 308647a1edSAlexey Zelkin.Nm dlinfo 318647a1edSAlexey Zelkin.Nd information about dynamically loaded object 328647a1edSAlexey Zelkin.Sh LIBRARY 338647a1edSAlexey Zelkin.Lb libc 348647a1edSAlexey Zelkin.Sh SYNOPSIS 358647a1edSAlexey Zelkin.In link.h 368647a1edSAlexey Zelkin.In dlfcn.h 378647a1edSAlexey Zelkin.Ft int 380e35e492SRuslan Ermilov.Fn dlinfo "void * restrict handle" "int request" "void * restrict p" 398647a1edSAlexey Zelkin.Sh DESCRIPTION 408647a1edSAlexey ZelkinThe 418647a1edSAlexey Zelkin.Fn dlinfo 428647a1edSAlexey Zelkinfunction provides information about dynamically loaded object. 438647a1edSAlexey ZelkinThe action taken by 448647a1edSAlexey Zelkin.Fn dlinfo 458647a1edSAlexey Zelkinand exact meaning and type of 468647a1edSAlexey Zelkin.Fa p 478647a1edSAlexey Zelkinargument depend on value of the 488647a1edSAlexey Zelkin.Fa request 498647a1edSAlexey Zelkinargument provided by caller. 508647a1edSAlexey Zelkin.Pp 510e35e492SRuslan ErmilovThe 528647a1edSAlexey Zelkin.Fa handle 530e35e492SRuslan Ermilovargument is either the value returned from the 540e35e492SRuslan Ermilov.Xr dlopen 3 558647a1edSAlexey Zelkinfunction call or special handle 568647a1edSAlexey Zelkin.Dv RTLD_SELF . 570e35e492SRuslan ErmilovIf 580e35e492SRuslan Ermilov.Fa handle 590e35e492SRuslan Ermilovis the value returned from 600e35e492SRuslan Ermilov.Xr dlopen 3 , 610e35e492SRuslan Ermilovthe information returned by the 628647a1edSAlexey Zelkin.Fn dlinfo 630e35e492SRuslan Ermilovfunction pertains to the specified object. 648647a1edSAlexey ZelkinIf handle is the special handle 658647a1edSAlexey Zelkin.Dv RTLD_SELF , 668647a1edSAlexey Zelkinthe information returned pertains to the caller itself. 678647a1edSAlexey Zelkin.Pp 680e35e492SRuslan ErmilovPossible values for the 698647a1edSAlexey Zelkin.Fa request 700e35e492SRuslan Ermilovargument are: 710e35e492SRuslan Ermilov.Bl -tag -width indent 720e35e492SRuslan Ermilov.It Dv RTLD_DI_LINKMAP 730e35e492SRuslan ErmilovRetrieve the 740e35e492SRuslan Ermilov.Vt Link_map 750e35e492SRuslan Ermilov.Pq Vt "struct link_map" 760e35e492SRuslan Ermilovstructure pointer for the specified 770e35e492SRuslan Ermilov.Fa handle . 780e35e492SRuslan ErmilovOn successful return, the 798647a1edSAlexey Zelkin.Fa p 800e35e492SRuslan Ermilovargument is filled with the pointer to the 810e35e492SRuslan Ermilov.Vt Link_map 820e35e492SRuslan Ermilovstructure 830e35e492SRuslan Ermilov.Pq Fa "Link_map **p" 840e35e492SRuslan Ermilovdescribing a shared object specified by the 858647a1edSAlexey Zelkin.Fa handle 868647a1edSAlexey Zelkinargument. 870e35e492SRuslan ErmilovThe 880e35e492SRuslan Ermilov.Vt Link_map 8981181557SMike Pritchardstructures are maintained as a doubly linked list by 900e35e492SRuslan Ermilov.Xr ld.so 1 , 910e35e492SRuslan Ermilovin the same order as 920e35e492SRuslan Ermilov.Xr dlopen 3 938647a1edSAlexey Zelkinand 940e35e492SRuslan Ermilov.Xr dlclose 3 958647a1edSAlexey Zelkinare called. 968647a1edSAlexey ZelkinSee 970e35e492SRuslan Ermilov.Sx EXAMPLES , 980e35e492SRuslan Ermilovexample 1. 996bc55edbSAlexey Zelkin.Pp 1006bc55edbSAlexey ZelkinThe 1010e35e492SRuslan Ermilov.Vt Link_map 1020e35e492SRuslan Ermilovstructure is defined in 103fe08efe6SRuslan Ermilov.In link.h 1040e35e492SRuslan Ermilovand has the following members: 1050e35e492SRuslan Ermilov.Bd -literal -offset indent 106d0ca9a7fSKonstantin Belousovcaddr_t l_base; /* Base Address of library */ 1076bc55edbSAlexey Zelkinconst char *l_name; /* Absolute Path to Library */ 1086bc55edbSAlexey Zelkinconst void *l_ld; /* Pointer to .dynamic in memory */ 1090e35e492SRuslan Ermilovstruct link_map *l_next, /* linked list of mapped libs */ 1106bc55edbSAlexey Zelkin *l_prev; 111d0ca9a7fSKonstantin Belousovcaddr_t l_addr; /* Load Offset of library */ 112*c8ad15b6SKonstantin Belousovconst char *l_refname; /* Object this one filters for */ 1136bc55edbSAlexey Zelkin.Ed 1140e35e492SRuslan Ermilov.Bl -tag -width ".Va l_addr" 115d0ca9a7fSKonstantin Belousov.It Va l_base 116d0ca9a7fSKonstantin BelousovThe base address of the object loaded into memory. 1170e35e492SRuslan Ermilov.It Va l_name 1180e35e492SRuslan ErmilovThe full name of the loaded shared object. 1190e35e492SRuslan Ermilov.It Va l_ld 1200e35e492SRuslan ErmilovThe address of the dynamic linking information segment 1210e35e492SRuslan Ermilov.Pq Dv PT_DYNAMIC 1226bc55edbSAlexey Zelkinloaded into memory. 1230e35e492SRuslan Ermilov.It Va l_next 1240e35e492SRuslan ErmilovThe next 1250e35e492SRuslan Ermilov.Vt Link_map 1260e35e492SRuslan Ermilovstructure on the link-map list. 1270e35e492SRuslan Ermilov.It Va l_prev 1280e35e492SRuslan ErmilovThe previous 1290e35e492SRuslan Ermilov.Vt Link_map 1300e35e492SRuslan Ermilovstructure on the link-map list. 131d0ca9a7fSKonstantin Belousov.It Va l_addr 132d0ca9a7fSKonstantin BelousovThe load offset of the object, that is, the difference between 133d0ca9a7fSKonstantin Belousovthe actual load address and the base virtual address the object 134d0ca9a7fSKonstantin Belousovwas linked at. 135*c8ad15b6SKonstantin Belousov.It Va l_refname 136*c8ad15b6SKonstantin BelousovA name of the object this object filters for, if any. 137*c8ad15b6SKonstantin BelousovIf there are more then one filtee, a name from the first 138*c8ad15b6SKonstantin Belousov.Dv DT_FILTER 139*c8ad15b6SKonstantin Belousovdynamic entry is supplied. 1406bc55edbSAlexey Zelkin.El 1410e35e492SRuslan Ermilov.It Dv RTLD_DI_SERINFO 1420e35e492SRuslan ErmilovRetrieve the library search paths associated with the given 1438647a1edSAlexey Zelkin.Fa handle 1448647a1edSAlexey Zelkinargument. 1458647a1edSAlexey ZelkinThe 1468647a1edSAlexey Zelkin.Fa p 1478647a1edSAlexey Zelkinargument should point to 1480e35e492SRuslan Ermilov.Vt Dl_serinfo 1498647a1edSAlexey Zelkinstructure buffer 1500e35e492SRuslan Ermilov.Pq Fa "Dl_serinfo *p" . 1510e35e492SRuslan ErmilovThe 1520e35e492SRuslan Ermilov.Vt Dl_serinfo 1530e35e492SRuslan Ermilovstructure must be initialized first with the 1548647a1edSAlexey Zelkin.Dv RTLD_DI_SERINFOSIZE 1558647a1edSAlexey Zelkinrequest. 1568647a1edSAlexey Zelkin.Pp 1578647a1edSAlexey ZelkinThe returned 1580e35e492SRuslan Ermilov.Vt Dl_serinfo 1598647a1edSAlexey Zelkinstructure contains 1600e35e492SRuslan Ermilov.Va dls_cnt 1610e35e492SRuslan Ermilov.Vt Dl_serpath 1628647a1edSAlexey Zelkinentries. 1638647a1edSAlexey ZelkinEach entry's 1640e35e492SRuslan Ermilov.Va dlp_name 1658647a1edSAlexey Zelkinfield points to the search path. 1668647a1edSAlexey ZelkinThe corresponding 1670e35e492SRuslan Ermilov.Va dlp_info 1688647a1edSAlexey Zelkinfield contains one of more flags indicating the origin of the path (see the 1698647a1edSAlexey Zelkin.Dv LA_SER_* 1700e35e492SRuslan Ermilovflags defined in the 171fe08efe6SRuslan Ermilov.In link.h 1720e35e492SRuslan Ermilovheader file). 1738647a1edSAlexey ZelkinSee 1740e35e492SRuslan Ermilov.Sx EXAMPLES , 1750e35e492SRuslan Ermilovexample 2, for a usage example. 1760e35e492SRuslan Ermilov.It Dv RTLD_DI_SERINFOSIZE 1778647a1edSAlexey ZelkinInitialize a 1780e35e492SRuslan Ermilov.Vt Dl_serinfo 1798647a1edSAlexey Zelkinstructure for use in a 1808647a1edSAlexey Zelkin.Dv RTLD_DI_SERINFO 1818647a1edSAlexey Zelkinrequest. 1828647a1edSAlexey ZelkinBoth the 1830e35e492SRuslan Ermilov.Va dls_cnt 1848647a1edSAlexey Zelkinand 1850e35e492SRuslan Ermilov.Va dls_size 1868647a1edSAlexey Zelkinfields are returned to indicate the number of search paths applicable 1878647a1edSAlexey Zelkinto the handle, and the total size of a 1880e35e492SRuslan Ermilov.Vt Dl_serinfo 1898647a1edSAlexey Zelkinbuffer required to hold 1900e35e492SRuslan Ermilov.Va dls_cnt 1910e35e492SRuslan Ermilov.Vt Dl_serpath 1928647a1edSAlexey Zelkinentries and the associated search path strings. 1938647a1edSAlexey ZelkinSee 1940e35e492SRuslan Ermilov.Sx EXAMPLES , 1950e35e492SRuslan Ermilovexample 2, for a usage example. 1960e35e492SRuslan Ermilov.It Va RTLD_DI_ORIGIN 1978647a1edSAlexey ZelkinRetrieve the origin of the dynamic object associated with the handle. 1980e35e492SRuslan ErmilovOn successful return, 1998647a1edSAlexey Zelkin.Fa p 2000e35e492SRuslan Ermilovargument is filled with the 2010e35e492SRuslan Ermilov.Vt char 2028647a1edSAlexey Zelkinpointer 2030e35e492SRuslan Ermilov.Pq Fa "char *p" . 2048647a1edSAlexey Zelkin.El 20524a0682cSRuslan Ermilov.Sh RETURN VALUES 20624a0682cSRuslan ErmilovThe 20724a0682cSRuslan Ermilov.Fn dlinfo 20824a0682cSRuslan Ermilovfunction returns 0 on success, or \-1 if an error occurred. 20924a0682cSRuslan ErmilovWhenever an error has been detected, a message detailing it can 21024a0682cSRuslan Ermilovbe retrieved via a call to 21124a0682cSRuslan Ermilov.Xr dlerror 3 . 2128647a1edSAlexey Zelkin.Sh EXAMPLES 213f7344926SAlexey ZelkinExample 1: Using 214f7344926SAlexey Zelkin.Fn dlinfo 2150e35e492SRuslan Ermilovto retrieve 2160e35e492SRuslan Ermilov.Vt Link_map 2170e35e492SRuslan Ermilovstructure. 218f7344926SAlexey Zelkin.Pp 219f7344926SAlexey ZelkinThe following example shows how dynamic library can detect the list 220f7344926SAlexey Zelkinof shared libraries loaded after caller's one. 221f7344926SAlexey ZelkinFor simplicity, error checking has been omitted. 2220e35e492SRuslan Ermilov.Bd -literal -offset indent 223f7344926SAlexey ZelkinLink_map *map; 224f7344926SAlexey Zelkin 225f7344926SAlexey Zelkindlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &map); 226f7344926SAlexey Zelkin 227f7344926SAlexey Zelkinwhile (map != NULL) { 228aba60fa6SRuslan Ermilov printf("%p: %s\\n", map->l_addr, map->l_name); 229f7344926SAlexey Zelkin map = map->l_next; 230f7344926SAlexey Zelkin} 231f7344926SAlexey Zelkin.Ed 232f7344926SAlexey Zelkin.Pp 233f7344926SAlexey ZelkinExample 2: Using 234f7344926SAlexey Zelkin.Fn dlinfo 235f7344926SAlexey Zelkinto retrieve the library search paths. 236f7344926SAlexey Zelkin.Pp 237f7344926SAlexey ZelkinThe following example shows how a dynamic object can inspect the library 238f7344926SAlexey Zelkinsearch paths that would be used to locate a simple filename with 2390e35e492SRuslan Ermilov.Xr dlopen 3 . 240f7344926SAlexey ZelkinFor simplicity, error checking has been omitted. 2410e35e492SRuslan Ermilov.Bd -literal -offset indent 242f7344926SAlexey ZelkinDl_serinfo _info, *info = &_info; 243f7344926SAlexey ZelkinDl_serpath *path; 244f7344926SAlexey Zelkinunsigned int cnt; 245f7344926SAlexey Zelkin 246f7344926SAlexey Zelkin/* determine search path count and required buffer size */ 247f7344926SAlexey Zelkindlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info); 248f7344926SAlexey Zelkin 249f7344926SAlexey Zelkin/* allocate new buffer and initialize */ 250f7344926SAlexey Zelkininfo = malloc(_info.dls_size); 251f7344926SAlexey Zelkininfo->dls_size = _info.dls_size; 252f7344926SAlexey Zelkininfo->dls_cnt = _info.dls_cnt; 253f7344926SAlexey Zelkin 254f7344926SAlexey Zelkin/* obtain sarch path information */ 255f7344926SAlexey Zelkindlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info); 256f7344926SAlexey Zelkin 257f7344926SAlexey Zelkinpath = &info->dls_serpath[0]; 258f7344926SAlexey Zelkin 259f7344926SAlexey Zelkinfor (cnt = 1; cnt <= info->dls_cnt; cnt++, path++) { 260aba60fa6SRuslan Ermilov (void) printf("%2d: %s\\n", cnt, path->dls_name); 261f7344926SAlexey Zelkin} 262f7344926SAlexey Zelkin.Ed 2638647a1edSAlexey Zelkin.Sh SEE ALSO 2648647a1edSAlexey Zelkin.Xr rtld 1 , 2658647a1edSAlexey Zelkin.Xr dladdr 3 , 2668647a1edSAlexey Zelkin.Xr dlopen 3 , 2678647a1edSAlexey Zelkin.Xr dlsym 3 2688647a1edSAlexey Zelkin.Sh HISTORY 2698647a1edSAlexey ZelkinThe 2708647a1edSAlexey Zelkin.Fn dlinfo 2718647a1edSAlexey Zelkinfunction first appeared in the Solaris operating system. 2728647a1edSAlexey ZelkinIn 2730e35e492SRuslan Ermilov.Fx , 2748647a1edSAlexey Zelkinit first appeared in 2758647a1edSAlexey Zelkin.Fx 4.8 . 2768647a1edSAlexey Zelkin.Sh AUTHORS 2770e35e492SRuslan Ermilov.An -nosplit 2788647a1edSAlexey ZelkinThe 2796bc55edbSAlexey Zelkin.Fx 2800e35e492SRuslan Ermilovimplementation of the 2818647a1edSAlexey Zelkin.Fn dlinfo 2828647a1edSAlexey Zelkinfunction was originally written by 2838fbf3d50SBaptiste Daroussin.An Alexey Zelkin Aq Mt phantom@FreeBSD.org 2848647a1edSAlexey Zelkinand later extended and improved by 2858fbf3d50SBaptiste Daroussin.An Alexander Kabaev Aq Mt kan@FreeBSD.org . 2868647a1edSAlexey Zelkin.Pp 2878647a1edSAlexey ZelkinThe manual page for this function was written by 2888fbf3d50SBaptiste Daroussin.An Alexey Zelkin Aq Mt phantom@FreeBSD.org . 289