This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: "make check" failures on Linux/x86


I suppose we should put back the support for SGI ELF dynamic segments
too, except that I'm not going to use the old hack that depends on size
of integer types.  That fails badly for readelf compiled with a 32-bit
bfd_vma on a big-endian host trying to read a big-endian ELF64 binary.

	* readelf.c (Elf32_Word): Delete.
	(get_32bit_dynamic_section): Handle SGI ELF dynamic segment.
	(get_64bit_dynamic_section): Likewise.

Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.243
diff -u -p -r1.243 readelf.c
--- binutils/readelf.c	22 Jun 2004 07:58:53 -0000	1.243
+++ binutils/readelf.c	22 Jun 2004 09:22:43 -0000
@@ -206,8 +206,6 @@ print_mode;
 static bfd_vma (*byte_get) (unsigned char *, int);
 static void (*byte_put) (unsigned char *, bfd_vma, int);
 
-typedef int Elf32_Word;
-
 #define UNKNOWN -1
 
 #define SECTION_NAME(X)	((X) == NULL ? "<none>" : \
@@ -4665,9 +4663,19 @@ get_32bit_dynamic_section (FILE *file)
   if (!edyn)
     return 0;
 
-  dynamic_nent = dynamic_size / sizeof (*ext);
-  dynamic_section = malloc (dynamic_nent * sizeof (*entry));
+/* SGI's ELF has more than one section in the DYNAMIC segment, and we
+   might not have the luxury of section headers.  Look for the DT_NULL
+   terminator to determine the number of entries.  */
+  for (ext = edyn, dynamic_nent = 0;
+       (char *) ext < (char *) edyn + dynamic_size;
+       ext++)
+    {
+      dynamic_nent++;
+      if (BYTE_GET (ext->d_tag) == DT_NULL)
+	break;
+    }
 
+  dynamic_section = malloc (dynamic_nent * sizeof (*entry));
   if (dynamic_section == NULL)
     {
       error (_("Out of memory\n"));
@@ -4676,7 +4684,7 @@ get_32bit_dynamic_section (FILE *file)
     }
 
   for (ext = edyn, entry = dynamic_section;
-       (char *) ext < (char *) edyn + dynamic_size;
+       entry < dynamic_section + dynamic_nent;
        ext++, entry++)
     {
       entry->d_tag      = BYTE_GET (ext->d_tag);
@@ -4699,9 +4707,19 @@ get_64bit_dynamic_section (FILE *file)
   if (!edyn)
     return 0;
 
-  dynamic_nent = dynamic_size / sizeof (*ext);
-  dynamic_section = malloc (dynamic_nent * sizeof (*entry));
+/* SGI's ELF has more than one section in the DYNAMIC segment, and we
+   might not have the luxury of section headers.  Look for the DT_NULL
+   terminator to determine the number of entries.  */
+  for (ext = edyn, dynamic_nent = 0;
+       (char *) ext < (char *) edyn + dynamic_size;
+       ext++)
+    {
+      dynamic_nent++;
+      if (BYTE_GET8 (ext->d_tag) == DT_NULL)
+	break;
+    }
 
+  dynamic_section = malloc (dynamic_nent * sizeof (*entry));
   if (dynamic_section == NULL)
     {
       error (_("Out of memory\n"));
@@ -4710,7 +4728,7 @@ get_64bit_dynamic_section (FILE *file)
     }
 
   for (ext = edyn, entry = dynamic_section;
-       (char *) ext < (char *) edyn + dynamic_size;
+       entry < dynamic_section + dynamic_nent;
        ext++, entry++)
     {
       entry->d_tag      = BYTE_GET8 (ext->d_tag);

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]