[PATCH v3 2/3] pldd: use target-specific r_debug_offset function
Xi Ruoyao
xry111@mengyan1223.wang
Fri Jan 28 22:07:09 GMT 2022
It allows pldd to work on MIPS.
---
elf/pldd-xx.c | 34 ++++++++++++++++++++--------------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/elf/pldd-xx.c b/elf/pldd-xx.c
index 1cdfb49c53..5560afe049 100644
--- a/elf/pldd-xx.c
+++ b/elf/pldd-xx.c
@@ -22,6 +22,8 @@
#define EW_(e, w, t) EW__(e, w, _##t)
#define EW__(e, w, t) e##w##t
+#include <elfxx-r_debug.h>
+
struct E(link_map)
{
EW(Addr) l_addr;
@@ -126,21 +128,25 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv,
!= p[i].p_filesz)
error (EXIT_FAILURE, 0, gettext ("cannot read dynamic section"));
- /* Search for the DT_DEBUG entry. */
+ /* Search for the r_debug struct. */
for (unsigned int j = 0; j < p[i].p_filesz / sizeof (EW(Dyn)); ++j)
- if (dyn[j].d_tag == DT_DEBUG && dyn[j].d_un.d_ptr != 0)
- {
- struct E(r_debug) r;
- if (pread (memfd, &r, sizeof (r), dyn[j].d_un.d_ptr)
- != sizeof (r))
- error (EXIT_FAILURE, 0, gettext ("cannot read r_debug"));
-
- if (r.r_map != 0)
- {
- list = r.r_map;
- break;
- }
- }
+ {
+ EW(Addr) d_addr = offset + p[i].p_vaddr + sizeof (EW(Dyn)) * j;
+ EW(Addr) off = E(r_debug_offset)(&dyn[j], memfd, d_addr);
+ if (off != 0)
+ {
+ struct E(r_debug) r;
+ if (pread (memfd, &r, sizeof (r), off)
+ != sizeof (r))
+ error (EXIT_FAILURE, 0, gettext ("cannot read r_debug"));
+
+ if (r.r_map != 0)
+ {
+ list = r.r_map;
+ break;
+ }
+ }
+ }
free (dyn);
break;
--
2.35.0
More information about the Libc-alpha
mailing list