2 .\" Copyright (C) 2015 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .TH dlinfo 3 (date) "Linux man-pages (unreleased)"
8 dlinfo \- obtain information about a dynamically loaded object
10 Dynamic linking library
11 .RI ( libdl ", " \-ldl )
14 .B #define _GNU_SOURCE
18 .BR "int dlinfo(void *restrict " handle ", int " request \
19 ", void *restrict " info );
24 function obtains information about the dynamically loaded object
27 (typically obtained by an earlier call to
33 argument specifies which information is to be returned.
36 argument is a pointer to a buffer used to store information
37 returned by the call; the type of this argument depends on
40 The following values are supported for
42 (with the corresponding type for
44 shown in parentheses):
46 .BR RTLD_DI_LMID " (\fILmid_t *\fP)"
47 Obtain the ID of the link-map list (namespace) in which
51 .BR RTLD_DI_LINKMAP " (\fIstruct link_map **\fP)"
52 Obtain a pointer to the
54 structure corresponding to
58 argument points to a pointer to a
67 ElfW(Addr) l_addr; /* Difference between the
68 address in the ELF file and
69 the address in memory */
70 char *l_name; /* Absolute pathname where
72 ElfW(Dyn) *l_ld; /* Dynamic section of the
74 struct link_map *l_next, *l_prev;
75 /* Chain of loaded objects */
77 /* Plus additional fields private to the
83 .BR RTLD_DI_ORIGIN " (\fIchar *\fP)"
84 Copy the pathname of the origin of the shared object corresponding to
86 to the location pointed to by
89 .BR RTLD_DI_SERINFO " (\fIDl_serinfo *\fP)"
90 Obtain the library search paths for the shared object referred to by
94 argument is a pointer to a
96 that contains the search paths.
97 Because the number of search paths may vary,
98 the size of the structure pointed to by
102 .B RTLD_DI_SERINFOSIZE
103 request described below allows applications to size the buffer suitably.
104 The caller must perform the following steps:
108 .B RTLD_DI_SERINFOSIZE
109 request to populate a
111 structure with the size
113 of the structure needed for the subsequent
119 buffer of the correct size
123 .B RTLD_DI_SERINFOSIZE
124 request to populate the
128 fields of the buffer allocated in the previous step.
132 to obtain the library search paths.
137 structure is defined as follows:
142 size_t dls_size; /* Size in bytes of
144 unsigned int dls_cnt; /* Number of elements
145 in \[aq]dls_serpath\[aq] */
146 Dl_serpath dls_serpath[1]; /* Actually longer,
147 \[aq]dls_cnt\[aq] elements */
154 elements in the above structure is a structure of the following form:
159 char *dls_name; /* Name of library search
161 unsigned int dls_flags; /* Indicates where this
162 directory came from */
169 field is currently unused, and always contains zero.
171 .BR RTLD_DI_SERINFOSIZE " (\fIDl_serinfo *\fP)"
178 structure pointed to by
180 with values suitable for allocating a buffer for use in a subsequent
184 .BR RTLD_DI_TLS_MODID " (\fIsize_t *\fP, since glibc 2.4)"
185 Obtain the module ID of this shared object's TLS (thread-local storage)
186 segment, as used in TLS relocations.
187 If this object does not define a TLS segment, zero is placed in
190 .BR RTLD_DI_TLS_DATA " (\fIvoid **\fP, since glibc 2.4)"
191 Obtain a pointer to the calling
192 thread's TLS block corresponding to this shared object's TLS segment.
193 If this object does not define a PT_TLS segment,
194 or if the calling thread has not allocated a block for it,
201 On failure, it returns \-1; the cause of the error can be diagnosed using
205 first appeared in glibc 2.3.3.
207 For an explanation of the terms used in this section, see
215 Interface Attribute Value
218 T} Thread safety MT-Safe
224 This function is a nonstandard GNU extension.
226 This function derives from the Solaris function of the same name
227 and also appears on some other systems.
228 The sets of requests supported by the various implementations
229 overlaps only partially.
231 The program below opens a shared objects using
234 .B RTLD_DI_SERINFOSIZE
237 requests to obtain the library search path list for the library.
238 Here is an example of what we might see when running the program:
242 $ \fB./a.out /lib64/libm.so.6\fP
243 dls_serpath[0].dls_name = /lib64
244 dls_serpath[1].dls_name = /usr/lib64
249 .\" SRC BEGIN (dlinfo.c)
258 main(int argc, char *argv[])
265 fprintf(stderr, "Usage: %s <libpath>\en", argv[0]);
269 /* Obtain a handle for shared object specified on command line. */
271 handle = dlopen(argv[1], RTLD_NOW);
272 if (handle == NULL) {
273 fprintf(stderr, "dlopen() failed: %s\en", dlerror());
277 /* Discover the size of the buffer that we must pass to
280 if (dlinfo(handle, RTLD_DI_SERINFOSIZE, &serinfo) == \-1) {
281 fprintf(stderr, "RTLD_DI_SERINFOSIZE failed: %s\en", dlerror());
285 /* Allocate the buffer for use with RTLD_DI_SERINFO. */
287 sip = malloc(serinfo.dls_size);
293 /* Initialize the \[aq]dls_size\[aq] and \[aq]dls_cnt\[aq] fields in the newly
296 if (dlinfo(handle, RTLD_DI_SERINFOSIZE, sip) == \-1) {
297 fprintf(stderr, "RTLD_DI_SERINFOSIZE failed: %s\en", dlerror());
301 /* Fetch and print library search list. */
303 if (dlinfo(handle, RTLD_DI_SERINFO, sip) == \-1) {
304 fprintf(stderr, "RTLD_DI_SERINFO failed: %s\en", dlerror());
308 for (size_t j = 0; j < serinfo.dls_cnt; j++)
309 printf("dls_serpath[%zu].dls_name = %s\en",
310 j, sip\->dls_serpath[j].dls_name);
317 .BR dl_iterate_phdr (3),