[PATCH 2/5] readelf: Use BYTE_GET_SIZE in RELR relocation processing

"H.J. Lu" <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
Replace

      if (relr_entsize == sizeof (Elf32_External_Relr))
	entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
      else
	entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);

with

      BYTE_GET_SIZE (entry, relrs, relr_entsize);

	PR binutils/34356
	* readelf.c (count_relr_relocations): Change relrs_p to void **.
	Use BYTE_GET_SIZE.
	(dump_relr_relocations): Change relrs to void *.  Use
	BYTE_GET_SIZE.
	(display_relocations): Change relrs to void *.
	(process_relocs): Likewise.

Signed-off-by: H.J. Lu <[email protected]>
---
 binutils/readelf.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 16480340b4d..1e3caeec252 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -1856,9 +1856,9 @@ update_all_relocations (size_t nentries)
 static uint64_t
 count_relr_relocations (Filedata *          filedata,
 			Elf_Internal_Shdr * section,
-			uint64_t         ** relrs_p)
+			void **             relrs_p)
 {
-  uint64_t *  relrs;
+  void *      relrs;
   uint64_t    nentries;
   uint64_t    i;
   uint64_t    count;
@@ -1886,14 +1886,12 @@ count_relr_relocations (Filedata *          filedata,
   if (relrs == NULL)
     return 0;
 
+  void *ptr = relrs;
   for (count = i = 0; i < nentries; i++)
     {
       uint64_t entry;
 
-      if (entsize == sizeof (Elf32_External_Relr))
-	entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
-      else
-	entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
+      BYTE_GET_SIZE (entry, ptr, entsize);
 
       if ((entry & 1) == 0)
 	{
@@ -1923,7 +1921,7 @@ dump_relr_relocations (Filedata *          filedata,
 		       uint64_t            relr_size,
 		       int                 relr_entsize,
 		       uint64_t            relr_offset,
-		       uint64_t *          relrs,
+		       void *              relrs,
 		       const Elf_Internal_Sym * symtab_p,
 		       uint64_t            nsyms,
 		       char *              strtab,
@@ -2151,10 +2149,7 @@ dump_relr_relocations (Filedata *          filedata,
     {
       uint64_t entry;
 
-      if (relr_entsize == sizeof (Elf32_External_Relr))
-	entry = BYTE_GET (((Elf32_External_Relr *)relrs)[i].r_data);
-      else
-	entry = BYTE_GET (((Elf64_External_Relr *)relrs)[i].r_data);
+      BYTE_GET_SIZE (entry, relrs, relr_entsize);
 
       if (dump_reloc)
 	{
@@ -9999,7 +9994,7 @@ display_relocations (Elf_Internal_Shdr *  section,
   uint64_t rel_offset = section->sh_offset;
   uint64_t num_rela = rel_size / section->sh_entsize;
   uint64_t num_reloc;
-  uint64_t *relrs = NULL;
+  void *relrs = NULL;
 
   if (rel_type == reltype_relr)
     {
@@ -10187,7 +10182,7 @@ process_relocs (Filedata * filedata)
 		  /* Count DT_RELR relocations when "-D --got-contents"
 		     is passed to readelf.  */
 		  uint64_t num_reloc;
-		  uint64_t *relrs = NULL;
+		  void *relrs = NULL;
 		  Elf_Internal_Shdr section = {};
 		  Elf_Internal_Shdr *orig_section = NULL;
 		  section.sh_offset
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.