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


Alan Modra wrote:
The array size calculation was wrong.

Oh, yeah. :-P



* readelf.c (get_32bit_dynamic_section): Correct number of entries translated from external to internal form. (get_64bit_dynamic_section): Likewise.


I thinks this patch did not actually fix it. process_dynamic_section() really expects dynamic_size be the number of entries in the dynamic section, not bytes, after calling get_32bit_dynamic_section () or get_64bit_dynamic_section (). So we need reverse the last two patches partially to make both of them calculate dynamic_size as before.


Here is the reverse patch.


-- Jie
2004-06-22  Jie Zhang  <zhangjie@magima.com.cn>

	* readelf.c (get_32bit_dynamic_section): Partially reverse last two patches.
	(get_64bit_dynamic_section): Likewise.

--- readelf.c.old	2004-06-22 13:52:01.000000000 +0800
+++ readelf.c	2004-06-22 14:02:49.000000000 +0800
@@ -4656,14 +4656,22 @@ dynamic_section_ia64_val (Elf_Internal_D
 static int
 get_32bit_dynamic_section (FILE *file)
 {
-  Elf32_External_Dyn *edyn, *ext;
+  Elf32_External_Dyn *edyn;
   Elf_Internal_Dyn *entry;
+  bfd_size_type i;
 
   edyn = get_data (NULL, file, dynamic_addr, dynamic_size,
 		   _("dynamic section"));
   if (!edyn)
     return 0;
 
+  /* SGI's ELF has more than one section in the DYNAMIC segment.  Determine
+     how large this .dynamic is now.  We can do this even before the byte
+     swapping since the DT_NULL tag is recognizable.  */
+  dynamic_size = 0;
+  while (*(Elf32_Word *) edyn[dynamic_size++].d_tag != DT_NULL)
+    ;
+
   dynamic_section = malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
 
   if (dynamic_section == NULL)
@@ -4673,12 +4681,12 @@ get_32bit_dynamic_section (FILE *file)
       return 0;
     }
 
-  for (ext = edyn, entry = dynamic_section;
-       (char *) ext < (char *) edyn + dynamic_size;
-       ext++, entry++)
+  for (i = 0, entry = dynamic_section;
+       i < dynamic_size;
+       i++, entry++)
     {
-      entry->d_tag      = BYTE_GET (ext->d_tag);
-      entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
+      entry->d_tag      = BYTE_GET (edyn[i].d_tag);
+      entry->d_un.d_val = BYTE_GET (edyn[i].d_un.d_val);
     }
 
   free (edyn);
@@ -4689,14 +4697,22 @@ get_32bit_dynamic_section (FILE *file)
 static int
 get_64bit_dynamic_section (FILE *file)
 {
-  Elf64_External_Dyn *edyn, *ext;
+  Elf64_External_Dyn *edyn;
   Elf_Internal_Dyn *entry;
+  bfd_size_type i;
 
   edyn = get_data (NULL, file, dynamic_addr, dynamic_size,
 		   _("dynamic section"));
   if (!edyn)
     return 0;
 
+  /* SGI's ELF has more than one section in the DYNAMIC segment.  Determine
+     how large this .dynamic is now.  We can do this even before the byte
+     swapping since the DT_NULL tag is recognizable.  */
+  dynamic_size = 0;
+  while (*(bfd_vma *) edyn[dynamic_size++].d_tag != DT_NULL)
+    ;
+
   dynamic_section = malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
 
   if (dynamic_section == NULL)
@@ -4706,12 +4722,12 @@ get_64bit_dynamic_section (FILE *file)
       return 0;
     }
 
-  for (ext = edyn, entry = dynamic_section;
-       (char *) ext < (char *) edyn + dynamic_size;
-       ext++, entry++)
+  for (i = 0, entry = dynamic_section;
+       i < dynamic_size;
+       i++, entry++)
     {
-      entry->d_tag      = BYTE_GET8 (ext->d_tag);
-      entry->d_un.d_val = BYTE_GET8 (ext->d_un.d_val);
+      entry->d_tag      = BYTE_GET8 (edyn[i].d_tag);
+      entry->d_un.d_val = BYTE_GET8 (edyn[i].d_un.d_val);
     }
 
   free (edyn);

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