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]

ARM BPABI breakage


The other day I noticed that my 2006-04-21 change to
assign_file_positions_except_relocs probably broke ARM BPABI PT_DYNAMIC
segment.  The comment saying "If the section has not yet been assigned a
file position... so it will not be processed above" is no longer true,
because all sections have been processed by the time we hit that code.
This will result in p_filesz not being set.  I also noticed the hack in
assign_file_positions_for_load_sections for PT_NOTE p_filesz, which of
course is working around exactly the same problem:  Non-loaded segments
don't have p_filesz set.  Fixed by setting p_filesz for all these
segments in assign_file_positions_for_non_load_sections.

Bugzilla 594 also mentioned that p_memsz was unexpectedly being set for
the PT_NOTE segment.  That particular bug was likely introduced with
a 2004-09-22 change I made with changelog saying "Don't bother checking
SEC_ALLOC in PT_LOAD segments."  Looks like I missed the fact that some
of the SEC_ALLOC checks I removed were for non-PT_LOAD segments.

Finally, I think we can safely increase p_align from maxpagesize in
demand-paged executables so long as p_vaddr and p_offset are congruent
modulo the alignment.

	* elf.c (elf_fake_sections): Formatting.
	(assign_file_positions_for_load_sections): Only add SEC_ALLOC
	sections to p_memsz.  Remove hack for PT_NOTE sections.  Allow
	section alignment to increase p_align for PT_LOAD.
	(assign_file_positions_for_non_load_sections): Remove ARM BPABI
	hack for PT_DYNAMIC.  Instead, set p_filesz for all segments
	other than PT_LOAD, and PT_NOTE in core.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.337
diff -c -p -r1.337 elf.c
*** bfd/elf.c	17 May 2006 05:09:24 -0000	1.337
--- bfd/elf.c	18 May 2006 23:00:37 -0000
*************** elf_fake_sections (bfd *abfd, asection *
*** 2736,2743 ****
        if ((asect->flags & SEC_GROUP) != 0)
  	this_hdr->sh_type = SHT_GROUP;
        else if ((asect->flags & SEC_ALLOC) != 0
! 	  && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
! 	      || (asect->flags & SEC_NEVER_LOAD) != 0))
  	this_hdr->sh_type = SHT_NOBITS;
        else
  	this_hdr->sh_type = SHT_PROGBITS;
--- 2736,2743 ----
        if ((asect->flags & SEC_GROUP) != 0)
  	this_hdr->sh_type = SHT_GROUP;
        else if ((asect->flags & SEC_ALLOC) != 0
! 	       && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
! 		   || (asect->flags & SEC_NEVER_LOAD) != 0))
  	this_hdr->sh_type = SHT_NOBITS;
        else
  	this_hdr->sh_type = SHT_PROGBITS;
*************** assign_file_positions_for_load_sections 
*** 4379,4384 ****
--- 4379,4389 ----
  	    }
  	}
  
+       /* Set up p_filesz, p_memsz, p_align and p_flags from the section
+ 	 maps.  Set filepos for sections in PT_LOAD segments, and in
+ 	 core files, for sections in PT_NOTE segments.
+ 	 assign_file_positions_for_non_load_sections will set filepos
+ 	 for other sections and update p_filesz for other segments.  */
        for (i = 0, secpp = m->sections; i < m->count; i++, secpp++)
  	{
  	  asection *sec;
*************** assign_file_positions_for_load_sections 
*** 4410,4417 ****
  		}
  	      /* .tbss is special.  It doesn't contribute to p_memsz of
  		 normal segments.  */
! 	      else if ((flags & SEC_THREAD_LOCAL) == 0
! 		       || p->p_type == PT_TLS)
  		{
  		  /* The section VMA must equal the file position
  		     modulo the page size.  */
--- 4415,4423 ----
  		}
  	      /* .tbss is special.  It doesn't contribute to p_memsz of
  		 normal segments.  */
! 	      else if ((flags & SEC_ALLOC) != 0
! 		       && ((flags & SEC_THREAD_LOCAL) == 0
! 			   || p->p_type == PT_TLS))
  		{
  		  /* The section VMA must equal the file position
  		     modulo the page size.  */
*************** assign_file_positions_for_load_sections 
*** 4475,4490 ****
  		  p->p_filesz += sec->size;
  		  p->p_memsz += sec->size;
  		}
- 	      /* PR ld/594:  Sections in note segments which are not loaded
- 		 contribute to the file size but not the in-memory size.  */
- 	      else if (p->p_type == PT_NOTE
- 		  && (flags & SEC_HAS_CONTENTS) != 0)
- 		p->p_filesz += sec->size;
  
  	      /* .tbss is special.  It doesn't contribute to p_memsz of
  		 normal segments.  */
! 	      else if ((flags & SEC_THREAD_LOCAL) == 0
! 		       || p->p_type == PT_TLS)
  		p->p_memsz += sec->size;
  
  	      if (p->p_type == PT_TLS
--- 4481,4492 ----
  		  p->p_filesz += sec->size;
  		  p->p_memsz += sec->size;
  		}
  
  	      /* .tbss is special.  It doesn't contribute to p_memsz of
  		 normal segments.  */
! 	      else if ((flags & SEC_ALLOC) != 0
! 		       && ((flags & SEC_THREAD_LOCAL) == 0
! 			   || p->p_type == PT_TLS))
  		p->p_memsz += sec->size;
  
  	      if (p->p_type == PT_TLS
*************** assign_file_positions_for_load_sections 
*** 4497,4503 ****
  		}
  
  	      if (align > p->p_align
! 		  && (p->p_type != PT_LOAD || (abfd->flags & D_PAGED) == 0))
  		p->p_align = align;
  	    }
  
--- 4499,4507 ----
  		}
  
  	      if (align > p->p_align
! 		  && (p->p_type != PT_LOAD
! 		      || (abfd->flags & D_PAGED) == 0
! 		      || ((p->p_vaddr - p->p_offset) & (align - 1)) == 0))
  		p->p_align = align;
  	    }
  
*************** assign_file_positions_for_non_load_secti
*** 4624,4650 ****
         m != NULL;
         m = m->next, p++)
      {
!       if (p->p_type != PT_LOAD && m->count > 0)
  	{
! 	  BFD_ASSERT (! m->includes_filehdr && ! m->includes_phdrs);
! 	  /* If the section has not yet been assigned a file position,
! 	     do so now.  The ARM BPABI requires that .dynamic section
! 	     not be marked SEC_ALLOC because it is not part of any
! 	     PT_LOAD segment, so it will not be processed above.  */
! 	  if (p->p_type == PT_DYNAMIC && m->sections[0]->filepos == 0)
! 	    {
! 	      Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd);
! 
! 	      i = 1;
! 	      while (i_shdrpp[i]->bfd_section != m->sections[0])
! 		++i;
! 	      off = (_bfd_elf_assign_file_position_for_section 
! 		     (i_shdrpp[i], off, TRUE));
! 	      p->p_filesz = m->sections[0]->size;
  	    }
- 	  p->p_offset = m->sections[0]->filepos;
  	}
!       if (m->count == 0)
  	{
  	  if (m->includes_filehdr)
  	    {
--- 4628,4651 ----
         m != NULL;
         m = m->next, p++)
      {
!       if (m->count != 0)
  	{
! 	  if (p->p_type != PT_LOAD
! 	      && (p->p_type != PT_NOTE || bfd_get_format (abfd) != bfd_core))
! 	    {
! 	      Elf_Internal_Shdr *hdr;
! 	      BFD_ASSERT (!m->includes_filehdr && !m->includes_phdrs);
! 
! 	      hdr = &elf_section_data (m->sections[m->count - 1])->this_hdr;
! 	      p->p_filesz = (m->sections[m->count - 1]->filepos
! 			     - m->sections[0]->filepos);
! 	      if (hdr->sh_type != SHT_NOBITS)
! 		p->p_filesz += hdr->sh_size;
! 
! 	      p->p_offset = m->sections[0]->filepos;
  	    }
  	}
!       else
  	{
  	  if (m->includes_filehdr)
  	    {

-- 
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]