public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: readelf: apply all rela relocations in the debug_info section
@ 2003-04-22 18:28 Joern Rennecke
  2003-04-22 18:36 ` Joern Rennecke
  0 siblings, 1 reply; 24+ messages in thread
From: Joern Rennecke @ 2003-04-22 18:28 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: binutils, Alan Modra

>       * readelf.c (display_debug_info): Apply RELA relocations on the
>       entire section.
>       (byte_put_little_endian, byte_put_big_endian): New functions.
>       (byte_put): New variable.
>       (get_file_header): Initialize it.

This breaks the readelf -wi test for sh-elf.

-- 
--------------------------
SuperH (UK) Ltd.
2410 Aztec West / Almondsbury / BRISTOL / BS32 4QX
T:+44 1454 465658

^ permalink raw reply	[flat|nested] 24+ messages in thread
* readelf: apply all rela relocations in the debug_info section
@ 2003-04-08  9:02 Alexandre Oliva
  2003-04-08 10:53 ` Alan Modra
  0 siblings, 1 reply; 24+ messages in thread
From: Alexandre Oliva @ 2003-04-08  9:02 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

readelf -wi is not quite nice on mips64-linux-gnu to check debugging
information in object files as it is on executables and shared
libraries.  The problem, as usual, is in RELA relocations, mostly to
the .debug_str section: since the addends aren't in-place on n32 or
n64, we display the compiler ident whenever a string that is located
in the .debug_str should be displayed.  This patch corrects this
problem.  Ok to install?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: readelf-apply-all-rela.patch --]
[-- Type: text/x-patch, Size: 5159 bytes --]

Index: binutils/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* readelf.c (display_debug_info): Apply RELA relocations on the
	entire section.
	(byte_put_little_endian, byte_put_big_endian): New functions.
	(byte_put): New variable.
	(get_file_header): Initialize it.

Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.199
diff -u -p -r1.199 readelf.c
--- binutils/readelf.c 1 Apr 2003 15:53:47 -0000 1.199
+++ binutils/readelf.c 8 Apr 2003 08:53:26 -0000
@@ -173,6 +173,12 @@ static bfd_vma byte_get_little_endian
   PARAMS ((unsigned char *, int));
 static bfd_vma byte_get_big_endian
   PARAMS ((unsigned char *, int));
+static void (*byte_put)
+  PARAMS ((unsigned char *, bfd_vma, int));
+static void byte_put_little_endian
+  PARAMS ((unsigned char *, bfd_vma, int));
+static void byte_put_big_endian
+  PARAMS ((unsigned char *, bfd_vma, int));
 static const char *get_mips_dynamic_type
   PARAMS ((unsigned long));
 static const char *get_sparc64_dynamic_type
@@ -550,6 +556,37 @@ byte_get_little_endian (field, size)
     }
 }
 
+static void
+byte_put_little_endian (field, value, size)
+     unsigned char * field;
+     bfd_vma	     value;
+     int             size;
+{
+  switch (size)
+    {
+    case 8:
+      field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
+      field[6] = ((value >> 24) >> 24) & 0xff;
+      field[5] = ((value >> 24) >> 16) & 0xff;
+      field[4] = ((value >> 24) >> 8) & 0xff;
+      /* Fall through.  */
+    case 4:
+      field[3] = (value >> 24) & 0xff;
+      field[2] = (value >> 16) & 0xff;
+      /* Fall through.  */
+    case 2:
+      field[1] = (value >> 8) & 0xff;
+      /* Fall through.  */
+    case 1:
+      field[0] = value & 0xff;
+      break;
+
+    default:
+      error (_("Unhandled data length: %d\n"), size);
+      abort ();
+    }
+}
+
 /* Print a VMA value.  */
 static void
 print_vma (vma, mode)
@@ -708,6 +745,41 @@ byte_get_big_endian (field, size)
     }
 }
 
+static void
+byte_put_big_endian (field, value, size)
+     unsigned char * field;
+     bfd_vma	     value;
+     int             size;
+{
+  switch (size)
+    {
+    case 8:
+      field[7] = value & 0xff;
+      field[6] = (value >> 8) & 0xff;
+      field[5] = (value >> 16) & 0xff;
+      field[4] = (value >> 24) & 0xff;
+      value >>= 16;
+      value >>= 16;
+      /* Fall through.  */
+    case 4:
+      field[3] = value & 0xff;
+      field[2] = (value >> 8) & 0xff;
+      value >>= 16;
+      /* Fall through.  */
+    case 2:
+      field[1] = value & 0xff;
+      value >>= 8;
+      /* Fall through.  */
+    case 1:
+      field[0] = value & 0xff;
+      break;
+
+    default:
+      error (_("Unhandled data length: %d\n"), size);
+      abort ();
+    }
+}
+
 /* Guess the relocation size commonly used by the specific machines.  */
 
 static int
@@ -8290,15 +8362,7 @@ display_debug_info (section, start, file
       compunit.cu_version = byte_get (hdrptr, 2);
       hdrptr += 2;
 
-      cu_abbrev_offset_ptr = hdrptr;
-      compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
-      hdrptr += offset_size;
-
-      compunit.cu_pointer_size = byte_get (hdrptr, 1);
-      hdrptr += 1;
-
-      /* Check for RELA relocations in the
-	 abbrev_offset address, and apply them.  */
+      /* Apply addends of RELA relocations.  */
       for (relsec = section_headers;
 	   relsec < section_headers + elf_header.e_shnum;
 	   ++relsec)
@@ -8323,8 +8387,13 @@ display_debug_info (section, start, file
 
 	  for (rp = rela; rp < rela + nrelas; ++rp)
 	    {
-	      if (rp->r_offset
-		  != (bfd_vma) (cu_abbrev_offset_ptr - section_begin))
+	      unsigned char *loc;
+
+	      if (rp->r_offset >= (bfd_vma) (hdrptr - section_begin)
+		  && section->sh_size > (bfd_vma) offset_size
+		  && rp->r_offset <= section->sh_size - offset_size)
+		loc = section_begin + rp->r_offset;
+	      else
 		continue;
 
 	      if (is_32bit_elf)
@@ -8352,14 +8421,20 @@ display_debug_info (section, start, file
 		    }
 		}
 
-	      compunit.cu_abbrev_offset = rp->r_addend;
-	      break;
+	      byte_put (loc, rp->r_addend, offset_size);
 	    }
 
 	  free (rela);
 	  break;
 	}
 
+      cu_abbrev_offset_ptr = hdrptr;
+      compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
+      hdrptr += offset_size;
+
+      compunit.cu_pointer_size = byte_get (hdrptr, 1);
+      hdrptr += 1;
+
       tags = hdrptr;
       cu_offset = start - section_begin;
       start += compunit.cu_length + initial_length_size;
@@ -10294,8 +10369,14 @@ get_file_header (file)
     {
     default: /* fall through */
     case ELFDATANONE: /* fall through */
-    case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
-    case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
+    case ELFDATA2LSB:
+      byte_get = byte_get_little_endian;
+      byte_put = byte_put_little_endian;
+      break;
+    case ELFDATA2MSB:
+      byte_get = byte_get_big_endian;
+      byte_put = byte_put_big_endian;
+      break;
     }
 
   /* For now we only support 32 bit and 64 bit ELF files.  */

[-- Attachment #3: Type: text/plain, Size: 289 bytes --]


-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2003-04-28 13:02 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-22 18:28 readelf: apply all rela relocations in the debug_info section Joern Rennecke
2003-04-22 18:36 ` Joern Rennecke
2003-04-22 20:13   ` RFA: Fix readelf -wi test (Was: Re: readelf: apply all rela relocations in the debug_info section) Joern Rennecke
2003-04-23 17:36     ` Nick Clifton
2003-04-23 17:39       ` Daniel Jacobowitz
2003-04-23 17:59         ` Nick Clifton
2003-04-23 18:09       ` H. J. Lu
2003-04-23 18:17         ` Nick Clifton
2003-04-23 18:22           ` H. J. Lu
2003-04-23 18:47       ` Joern Rennecke
2003-04-24 17:21       ` Joern Rennecke
2003-04-25  9:34         ` Nick Clifton
2003-04-25 13:38           ` Daniel Jacobowitz
2003-04-25 15:36             ` H. J. Lu
2003-04-25 16:05             ` Nick Clifton
2003-04-25 16:10               ` H. J. Lu
2003-04-25 16:43               ` Joern Rennecke
2003-04-25 17:18                 ` Daniel Jacobowitz
2003-04-26  7:57                   ` Nick Clifton
2003-04-26 13:56                     ` Daniel Jacobowitz
2003-04-27  9:12                       ` Nick Clifton
2003-04-28 13:02                     ` Joern Rennecke
  -- strict thread matches above, loose matches on Subject: below --
2003-04-08  9:02 readelf: apply all rela relocations in the debug_info section Alexandre Oliva
2003-04-08 10:53 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).