From a93d9e03a31ec14405cb3a09aa95413b67067380 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 17 Aug 2021 19:35:48 -0700 Subject: Extend struct r_debug to support multiple namespaces [BZ #15971] Glibc does not provide an interface for debugger to access libraries loaded in multiple namespaces via dlmopen. The current rtld-debugger interface is described in the file: elf/rtld-debugger-interface.txt under the "Standard debugger interface" heading. This interface only provides access to the first link-map (LM_ID_BASE). 1. Bump r_version to 2 when multiple namespaces are used. This triggers the GDB bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28236 2. Add struct r_debug_extended to extend struct r_debug into a linked-list, where each element correlates to an unique namespace. 3. Initialize the r_debug_extended structure. Bump r_version to 2 for the new namespace and add the new namespace to the namespace linked list. 4. Add _dl_debug_update to return the address of struct r_debug' of a namespace. 5. Add a hidden symbol, _r_debug_extended, for struct r_debug_extended. 6. Provide the symbol, _r_debug, with size of struct r_debug, as an alias of _r_debug_extended, for programs which reference _r_debug. This fixes BZ #15971. Reviewed-by: Florian Weimer --- sysdeps/generic/ldsodefs.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sysdeps/generic/ldsodefs.h') diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index fd67871f4b..6e50fcd7cd 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -355,7 +355,7 @@ struct rtld_global void (*free) (void *); } _ns_unique_sym_table; /* Keep track of changes to each namespace' list. */ - struct r_debug _ns_debug; + struct r_debug_extended _ns_debug; } _dl_ns[DL_NNS]; /* One higher than index of last used namespace. */ EXTERN size_t _dl_nns; @@ -1099,12 +1099,16 @@ extern void _dl_sort_maps (struct link_map **maps, unsigned int nmaps, extern void _dl_debug_state (void); rtld_hidden_proto (_dl_debug_state) -/* Initialize `struct r_debug' if it has not already been done. The - argument is the run-time load address of the dynamic linker, to be put - in the `r_ldbase' member. Returns the address of the structure. */ +/* Initialize `struct r_debug_extended' for the namespace NS. LDBASE + is the run-time load address of the dynamic linker, to be put in the + `r_ldbase' member. Return the address of the structure. */ extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns) attribute_hidden; +/* Update the `r_map' member and return the address of `struct r_debug' + of the namespace NS. */ +extern struct r_debug *_dl_debug_update (Lmid_t ns) attribute_hidden; + /* Initialize the basic data structure for the search paths. SOURCE is either "LD_LIBRARY_PATH" or "--library-path". GLIBC_HWCAPS_PREPEND adds additional glibc-hwcaps subdirectories to -- cgit v1.2.3