displays dynamic segment even if no .dynamic section

Alan Modra amodra@bigpond.net.au
Wed Oct 24 03:55:00 GMT 2007


On Mon, Jun 25, 2007 at 02:42:32PM +0200, Tristan Gingold wrote:
> 	* readelf.c (process_program_headers): use DYNAMIC segment unless
> 	.dynamic section is found.

I'm about to apply this variation of your patch.

Index: binutils/readelf.c
===================================================================
RCS file: /cvs/src/src/binutils/readelf.c,v
retrieving revision 1.381
diff -u -p -r1.381 readelf.c
--- binutils/readelf.c	9 Oct 2007 13:32:50 -0000	1.381
+++ binutils/readelf.c	17 Oct 2007 05:06:45 -0000
@@ -3530,6 +3530,11 @@ process_program_headers (FILE *file)
 	  if (dynamic_addr)
 	    error (_("more than one dynamic segment\n"));
 
+	  /* By default, assume that the .dynamic section is the first
+	     section in the DYNAMIC segment.  */
+	  dynamic_addr = segment->p_offset;
+	  dynamic_size = segment->p_filesz;
+
 	  /* Try to locate the .dynamic section. If there is
 	     a section header table, we can easily locate it.  */
 	  if (section_headers != NULL)
@@ -3544,23 +3549,21 @@ process_program_headers (FILE *file)
 		}
 
 	      if (sec->sh_type == SHT_NOBITS)
-		break;
+		{
+		  dynamic_size = 0;
+		  break;
+		}
 
 	      dynamic_addr = sec->sh_offset;
 	      dynamic_size = sec->sh_size;
 
 	      if (dynamic_addr < segment->p_offset
 		  || dynamic_addr > segment->p_offset + segment->p_filesz)
-		warn (_("the .dynamic section is not contained within the dynamic segment\n"));
+		warn (_("the .dynamic section is not contained"
+			" within the dynamic segment\n"));
 	      else if (dynamic_addr > segment->p_offset)
-		warn (_("the .dynamic section is not the first section in the dynamic segment.\n"));
-	    }
-	  else
-	    {
-	      /* Otherwise, we can only assume that the .dynamic
-		 section is the first section in the DYNAMIC segment.  */
-	      dynamic_addr = segment->p_offset;
-	      dynamic_size = segment->p_filesz;
+		warn (_("the .dynamic section is not the first section"
+			" in the dynamic segment.\n"));
 	    }
 	  break;
 

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list