BFD guesswork on section LMAs for ELF

Alan Modra amodra@bigpond.net.au
Sat Aug 8 01:45:00 GMT 2009


Just comparing sh_offset against p_offset isn't sufficient to tell
whether a SH_NOBITS section belongs to a PT_LOAD header.  The weird
testcase in pr10494 shows BFD getting LMAs wrong, and everything going
downhill from there.

	PR 10494
	* elf.c (_bfd_elf_make_section_from_shdr): When setting up section
	LMAs, use ELF_IS_SECTION_IN_SEGMENT to match sections with headers.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.488
diff -u -p -r1.488 elf.c
--- bfd/elf.c	6 Aug 2009 13:08:24 -0000	1.488
+++ bfd/elf.c	7 Aug 2009 09:28:58 -0000
@@ -971,25 +971,8 @@ _bfd_elf_make_section_from_shdr (bfd *ab
       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.
-
-	     Note - we used to check the p_paddr field as well, and
-	     refuse to set the LMA if it was 0.  This is wrong
-	     though, as a perfectly valid initialised segment can
-	     have a p_paddr of zero.  Some architectures, eg ARM,
-	     place special significance on the address 0 and
-	     executables need to be able to have a segment which
-	     covers this address.  */
 	  if (phdr->p_type == PT_LOAD
-	      && (bfd_vma) hdr->sh_offset >= phdr->p_offset
-	      && (hdr->sh_offset + hdr->sh_size
-		  <= phdr->p_offset + phdr->p_memsz)
-	      && ((flags & SEC_LOAD) == 0
-		  || (hdr->sh_offset + hdr->sh_size
-		      <= phdr->p_offset + phdr->p_filesz)))
+	      && ELF_IS_SECTION_IN_SEGMENT (hdr, phdr))
 	    {
 	      if ((flags & SEC_LOAD) == 0)
 		newsect->lma = (phdr->p_paddr

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list