[RFC PATCH 3/3] add r_debug multiple namespaces support
Daniel Walker
danielwa@cisco.com
Fri Jun 26 19:32:28 GMT 2020
From: Conan C Huang <conhuang@cisco.com>
GLIBC Bugzilla: 15971
GDB Bugzilla: 11839
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).
This solution converts r_debug into a linked-list, where each element correlates
to an unique namespace. Debugger (GDB) can traverse r_debug linked-list to
retrieve information for all loaded namespaces.
---
elf/dl-debug.c | 13 ++++++++++---
elf/link.h | 4 ++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/elf/dl-debug.c b/elf/dl-debug.c
index 4b3d3ad6ba..7eba477fd3 100644
--- a/elf/dl-debug.c
+++ b/elf/dl-debug.c
@@ -44,20 +44,27 @@ struct r_debug _r_debug;
struct r_debug *
_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
{
- struct r_debug *r;
+ struct r_debug *r, *rp;
if (ns == LM_ID_BASE)
r = &_r_debug;
else
- r = &GL(dl_ns)[ns]._ns_debug;
+ {
+ r = &GL(dl_ns)[ns]._ns_debug;
+ rp = &GL(dl_ns)[ns - 1]._ns_debug;
+ rp->next = r;
+ if (ns - 1 == LM_ID_BASE)
+ _r_debug.next = r;
+ }
if (r->r_map == NULL || ldbase != 0)
{
/* Tell the debugger where to find the map of loaded objects. */
- r->r_version = 1 /* R_DEBUG_VERSION XXX */;
+ r->r_version = 3 /* R_DEBUG_VERSION XXX */;
r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
r->r_brk = (ElfW(Addr)) &_dl_debug_state;
+ r->next = NULL;
}
return r;
diff --git a/elf/link.h b/elf/link.h
index 0048ad5d4d..5a42511636 100644
--- a/elf/link.h
+++ b/elf/link.h
@@ -61,6 +61,10 @@ struct r_debug
} r_state;
ElfW(Addr) r_ldbase; /* Base address the linker is loaded at. */
+
+ /* Link to next r_debug struct. Each r_debug struct represents a
+ different namespace. The first r_debug struct is the default. */
+ struct r_debug *next;
};
/* This is the instance of that structure used by the dynamic linker. */
--
2.17.1
More information about the Libc-alpha
mailing list