This is the mail archive of the binutils@sourceware.org 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: PATCH: Preserve segment physical address only if needed


On Thu, Nov 23, 2006 at 10:15:57PM -0800, H. J. Lu wrote:
> On Fri, Nov 24, 2006 at 11:27:56AM +1030, Alan Modra wrote:
> > On Thu, Nov 23, 2006 at 03:38:39PM -0800, H. J. Lu wrote:
> > > I meant to say "segment physical address". The test is to check if the
> > > first section isn't removed. If it isn't removed, we will preserve
> > > segment physical address by setting
> > > 
> > > 	map->p_paddr = segment->p_paddr;
> > > 	map->p_paddr_valid = 1;
> > > 
> > > The first section isn't removed only if first_section == NULL or
> > > first_section->output_section != NULL.
> > 
> > Hmm, OK, that makes some sort of sense.  For the first part of your
> > patch, can you explain why you didn't use something like
> > 
> >       for (section = ibfd->sections, section_count = 0;
> > 	   section != NULL;
> > 	   section = section->next)
> > 	if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed)
> > 	  {
> > 	    ++section_count;
> > 	    if (first_section == NULL)
> > 	      first_section = section;
> > 	  }
> 
> INCLUDE_SECTION_IN_SEGMENT has
> 
> 	&& section->output_section != NULL 
> 
> This will set first_section to the first section in the output
> segment, which isn't the first section in the input segment if it
> has been removed. What we need to know is if the first section in the
> input segment has been removed or not. Here is the updated comment.
> 
> 

We don't need to preserve segmentphysical address in the output
segment even if the first section in the corresponding input segment
isn't aligned with the input segment.


H.J.
-----
2006-11-23  H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (rewrite_elf_program_header): Don't preserve segment
	physical address in the output segment if the first section in
	the corresponding input segment is removed.

--- bfd/elf.c.strip	2006-11-23 07:55:03.000000000 -0800
+++ bfd/elf.c	2006-11-24 06:41:53.000000000 -0800
@@ -5427,16 +5427,30 @@ rewrite_elf_program_header (bfd *ibfd, b
       bfd_vma       suggested_lma;
       unsigned int  j;
       bfd_size_type amt;
+      asection *    first_section;
 
       if (segment->p_type == PT_NULL)
 	continue;
 
+      first_section = NULL;
       /* Compute how many sections might be placed into this segment.  */
       for (section = ibfd->sections, section_count = 0;
 	   section != NULL;
 	   section = section->next)
-	if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed))
-	  ++section_count;
+	{
+	  /* Find the first section in the input segment, which may be
+	     removed from the corresponding output segment.  That is
+	     why we don't use INCLUDE_SECTION_IN_SEGMENT directly.  */
+	  if (first_section == NULL)
+	    {
+	      Elf_Internal_Shdr *hdr;
+	      hdr = &(elf_section_data(section)->this_hdr);
+	      if (ELF_IS_SECTION_IN_SEGMENT_FILE (hdr, segment))
+		first_section = section;
+	    }
+	  if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed))
+	    ++section_count;
+	}
 
       /* Allocate a segment map big enough to contain
 	 all of the sections we have selected.  */
@@ -5452,8 +5466,14 @@ rewrite_elf_program_header (bfd *ibfd, b
       map->p_type        = segment->p_type;
       map->p_flags       = segment->p_flags;
       map->p_flags_valid = 1;
-      map->p_paddr       = segment->p_paddr;
-      map->p_paddr_valid = 1;
+      /* If the first section in the input segment is removed, there is
+	 no need to preserve segment physical address in the corresponding
+	 output segment.  */
+      if (first_section->output_section != NULL)
+	{
+	  map->p_paddr = segment->p_paddr;
+	  map->p_paddr_valid = 1;
+	}
 
       /* Determine if this segment contains the ELF file header
 	 and if it contains the program headers themselves.  */


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