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