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