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