00c0d4
commit e4a2fb76efb45210c541ee3f8ef32f317783c3a8
00c0d4
Author: Florian Weimer <fweimer@redhat.com>
00c0d4
Date:   Wed May 11 20:30:49 2022 +0200
00c0d4
00c0d4
    manual: Document the dlinfo function
00c0d4
    
00c0d4
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
00c0d4
    Tested-by: Carlos O'Donell <carlos@rehdat.com>
00c0d4
    (cherry picked from commit 93804a1ee084d4bdc620b2b9f91615c7da0fabe1)
00c0d4
    
00c0d4
    Also includes partial backport of commit 5d28a8962dcb6ec056b81d730e
00c0d4
    (the addition of manual/dynlink.texi).
00c0d4
00c0d4
diff --git a/manual/Makefile b/manual/Makefile
00c0d4
index c2756640a785afe1..4c835e568f3bab67 100644
00c0d4
--- a/manual/Makefile
00c0d4
+++ b/manual/Makefile
00c0d4
@@ -39,7 +39,7 @@ chapters = $(addsuffix .texi, \
00c0d4
 		       pipe socket terminal syslog math arith time	\
00c0d4
 		       resource setjmp signal startup process ipc job	\
00c0d4
 		       nss users sysinfo conf crypt debug threads	\
00c0d4
-		       probes tunables)
00c0d4
+		       dynlink probes tunables)
00c0d4
 appendices = lang.texi header.texi install.texi maint.texi platform.texi \
00c0d4
 	     contrib.texi
00c0d4
 licenses = freemanuals.texi lgpl-2.1.texi fdl-1.3.texi
00c0d4
diff --git a/manual/dynlink.texi b/manual/dynlink.texi
00c0d4
new file mode 100644
00c0d4
index 0000000000000000..dbf3de11769d8e57
00c0d4
--- /dev/null
00c0d4
+++ b/manual/dynlink.texi
00c0d4
@@ -0,0 +1,100 @@
00c0d4
+@node Dynamic Linker
00c0d4
+@c @node Dynamic Linker, Internal Probes, Threads, Top
00c0d4
+@c %MENU% Loading programs and shared objects.
00c0d4
+@chapter Dynamic Linker
00c0d4
+@cindex dynamic linker
00c0d4
+@cindex dynamic loader
00c0d4
+
00c0d4
+The @dfn{dynamic linker} is responsible for loading dynamically linked
00c0d4
+programs and their dependencies (in the form of shared objects).  The
00c0d4
+dynamic linker in @theglibc{} also supports loading shared objects (such
00c0d4
+as plugins) later at run time.
00c0d4
+
00c0d4
+Dynamic linkers are sometimes called @dfn{dynamic loaders}.
00c0d4
+
00c0d4
+@menu
00c0d4
+* Dynamic Linker Introspection::    Interfaces for querying mapping information.
00c0d4
+@end menu
00c0d4
+
00c0d4
+@node Dynamic Linker Introspection
00c0d4
+@section Dynamic Linker Introspection
00c0d4
+
00c0d4
+@Theglibc{} provides various functions for querying information from the
00c0d4
+dynamic linker.
00c0d4
+
00c0d4
+@deftypefun {int} dlinfo (void *@var{handle}, int @var{request}, void *@var{arg})
00c0d4
+@safety{@mtsafe{}@asunsafe{@asucorrupt{}}@acunsafe{@acucorrupt{}}}
00c0d4
+@standards{GNU, dlfcn.h}
00c0d4
+This function returns information about @var{handle} in the memory
00c0d4
+location @var{arg}, based on @var{request}.  The @var{handle} argument
00c0d4
+must be a pointer returned by @code{dlopen} or @code{dlmopen}; it must
00c0d4
+not have been closed by @code{dlclose}.
00c0d4
+
00c0d4
+On success, @code{dlinfo} returns 0.  If there is an error, the function
00c0d4
+returns @math{-1}, and @code{dlerror} can be used to obtain a
00c0d4
+corresponding error message.
00c0d4
+
00c0d4
+The following operations are defined for use with @var{request}:
00c0d4
+
00c0d4
+@vtable @code
00c0d4
+@item RTLD_DI_LINKMAP
00c0d4
+The corresponding @code{struct link_map} pointer for @var{handle} is
00c0d4
+written to @code{*@var{arg}}.  The @var{arg} argument must be the
00c0d4
+address of an object of type @code{struct link_map *}.
00c0d4
+
00c0d4
+@item RTLD_DI_LMID
00c0d4
+The namespace identifier of @var{handle} is written to
00c0d4
+@code{*@var{arg}}.  The @var{arg} argument must be the address of an
00c0d4
+object of type @code{Lmid_t}.
00c0d4
+
00c0d4
+@item RTLD_DI_ORIGIN
00c0d4
+The value of the @code{$ORIGIN} dynamic string token for @var{handle} is
00c0d4
+written to the character array starting at @var{arg} as a
00c0d4
+null-terminated string.
00c0d4
+
00c0d4
+This request type should not be used because it is prone to buffer
00c0d4
+overflows.
00c0d4
+
00c0d4
+@item RTLD_DI_SERINFO
00c0d4
+@itemx RTLD_DI_SERINFOSIZE
00c0d4
+These requests can be used to obtain search path information for
00c0d4
+@var{handle}.  For both requests, @var{arg} must point to a
00c0d4
+@code{Dl_serinfo} object.  The @code{RTLD_DI_SERINFOSIZE} request must
00c0d4
+be made first; it updates the @code{dls_size} and @code{dls_cnt} members
00c0d4
+of the @code{Dl_serinfo} object.  The caller should then allocate memory
00c0d4
+to store at least @code{dls_size} bytes and pass that buffer to a
00c0d4
+@code{RTLD_DI_SERINFO} request.  This second request fills the
00c0d4
+@code{dls_serpath} array.  The number of array elements was returned in
00c0d4
+the @code{dls_cnt} member in the initial @code{RTLD_DI_SERINFOSIZE}
00c0d4
+request.  The caller is responsible for freeing the allocated buffer.
00c0d4
+
00c0d4
+This interface is prone to buffer overflows in multi-threaded processes
00c0d4
+because the required size can change between the
00c0d4
+@code{RTLD_DI_SERINFOSIZE} and @code{RTLD_DI_SERINFO} requests.
00c0d4
+
00c0d4
+@item RTLD_DI_TLS_DATA
00c0d4
+This request writes the address of the TLS block (in the current thread)
00c0d4
+for the shared object identified by @var{handle} to @code{*@var{arg}}.
00c0d4
+The argument @var{arg} must be the address of an object of type
00c0d4
+@code{void *}.  A null pointer is written if the object does not have
00c0d4
+any associated TLS block.
00c0d4
+
00c0d4
+@item RTLD_DI_TLS_MODID
00c0d4
+This request writes the TLS module ID for the shared object @var{handle}
00c0d4
+to @code{*@var{arg}}.  The argument @var{arg} must be the address of an
00c0d4
+object of type @code{size_t}.  The module ID is zero if the object
00c0d4
+does not have an associated TLS block.
00c0d4
+@end vtable
00c0d4
+
00c0d4
+The @code{dlinfo} function is a GNU extension.
00c0d4
+@end deftypefun
00c0d4
+
00c0d4
+@c FIXME these are undocumented:
00c0d4
+@c dladdr
00c0d4
+@c dladdr1
00c0d4
+@c dlclose
00c0d4
+@c dlerror
00c0d4
+@c dlmopen
00c0d4
+@c dlopen
00c0d4
+@c dlsym
00c0d4
+@c dlvsym
00c0d4
diff --git a/manual/libdl.texi b/manual/libdl.texi
00c0d4
deleted file mode 100644
00c0d4
index e3fe0452d9f41d47..0000000000000000
00c0d4
--- a/manual/libdl.texi
00c0d4
+++ /dev/null
00c0d4
@@ -1,10 +0,0 @@
00c0d4
-@c FIXME these are undocumented:
00c0d4
-@c dladdr
00c0d4
-@c dladdr1
00c0d4
-@c dlclose
00c0d4
-@c dlerror
00c0d4
-@c dlinfo
00c0d4
-@c dlmopen
00c0d4
-@c dlopen
00c0d4
-@c dlsym
00c0d4
-@c dlvsym
00c0d4
diff --git a/manual/probes.texi b/manual/probes.texi
00c0d4
index 0ea560ed78bcfd7e..892d2451938eb379 100644
00c0d4
--- a/manual/probes.texi
00c0d4
+++ b/manual/probes.texi
00c0d4
@@ -1,5 +1,5 @@
00c0d4
 @node Internal Probes
00c0d4
-@c @node Internal Probes, Tunables, Threads, Top
00c0d4
+@c @node Internal Probes, Tunables, Dynamic Linker, Top
00c0d4
 @c %MENU% Probes to monitor libc internal behavior
00c0d4
 @chapter Internal probes
00c0d4
 
00c0d4
diff --git a/manual/threads.texi b/manual/threads.texi
00c0d4
index 87fda7d8e716e08c..1c26c57540746e3b 100644
00c0d4
--- a/manual/threads.texi
00c0d4
+++ b/manual/threads.texi
00c0d4
@@ -1,5 +1,5 @@
00c0d4
 @node Threads
00c0d4
-@c @node Threads, Internal Probes, Debugging Support, Top
00c0d4
+@c @node Threads, Dynamic Linker, Debugging Support, Top
00c0d4
 @c %MENU% Functions, constants, and data types for working with threads
00c0d4
 @chapter Threads
00c0d4
 @cindex threads