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]

[PATCH] Correctly set lma when reading an elf image



This patch changes the way we calculate the LMA for a section to more
closely conform with the way the linker works.  It's based on the
assumption that while a segment may not contain contiguous VMAs the LMAs
*will* always be contiguous and therefore the LMA of a section within that
segment can be calculated from the LMA of the segment plus the offset into
it.  This is the first of two changes to fix the problem of strip
complaining that sections are not mapped into segments.

<date>  Richard Earnshaw (rearnsha@arm.com)

	* elf.c (_bfd_elf_make_section_from_shdr): Set the LMA based on the
	p_paddr of the segment that contains it.


Index: elf.c
===================================================================
RCS file: /thirdparty/cvs/gnu/utils/bfd/elf.c,v
retrieving revision 1.1.1.1
diff -p -r1.1.1.1 elf.c
*** elf.c	2001/06/28 15:58:45	1.1.1.1
--- elf.c	2001/10/27 15:35:54
*************** _bfd_elf_make_section_from_shdr (abfd, h
*** 450,466 ****
  	  phdr = elf_tdata (abfd)->phdr;
  	  for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
  	    {
  	      if (phdr->p_type == PT_LOAD
! 		  && phdr->p_vaddr != phdr->p_paddr
! 		  && phdr->p_vaddr <= hdr->sh_addr
! 		  && (phdr->p_vaddr + phdr->p_memsz
! 		      >= hdr->sh_addr + hdr->sh_size)
  		  && ((flags & SEC_LOAD) == 0
! 		      || (phdr->p_offset <= (bfd_vma) hdr->sh_offset
! 			  && (phdr->p_offset + phdr->p_filesz
! 			      >= hdr->sh_offset + hdr->sh_size))))
  		{
! 		  newsect->lma += phdr->p_paddr - phdr->p_vaddr;
  		  break;
  		}
  	    }
--- 450,479 ----
  	  phdr = elf_tdata (abfd)->phdr;
  	  for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
  	    {
+ 	      /* This section is part of this segment if its file
+ 		 offset plus size lies within the segment's memory
+ 		 span and, if the section is loaded, the extent of the
+ 		 loaded data lies within the extent of the segment.  
+ 		 If the p_paddr field is not set, we don't alter the 
+ 		 LMA.  */
  	      if (phdr->p_type == PT_LOAD
! 		  && phdr->p_paddr
! 		  && (bfd_vma) hdr->sh_offset >= phdr->p_offset
! 		  && (hdr->sh_offset + hdr->sh_size
! 		      <= phdr->p_offset + phdr->p_memsz)
  		  && ((flags & SEC_LOAD) == 0
! 		      || (phdr->p_offset + phdr->p_filesz
! 			  >= hdr->sh_offset + hdr->sh_size)))
  		{
! 		  /* We used to do a relative adjustment here, but
! 		     that doesn't work if the segment is packed with
! 		     code from multiple VMAs.  Instead we calculate
! 		     the LMA absoultely, based on the LMA of the
! 		     segment (it is assumed that the segment will
! 		     contain sections with contiguous LMAs, even if
! 		     the VMAs are not).  */
! 		  newsect->lma = phdr->p_paddr
! 		    + hdr->sh_offset - phdr->p_offset;
  		  break;
  		}
  	    }

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