[v3,2/3] pldd: use target-specific r_debug_offset function

Message ID 289382368837057e769b963f9ebaacc62e5bcacd.camel@mengyan1223.wang
State Superseded
Headers
Series mips: add target-specific r_debug offset |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Xi Ruoyao Jan. 28, 2022, 10:07 p.m. UTC
  It allows pldd to work on MIPS.
---
 elf/pldd-xx.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
  

Patch

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;