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