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: Zero p_paddr confuses BFD


I've been having second thoughts about the patch I committed to fix
PR 6473,  http://sourceware.org/ml/binutils/2008-05/msg00008.html
I think I went a little too far, effectively removing support for
binaries created by some non-GNU linkers.  This patch restores the
previous _bfd_elf_make_section_from_shdr behaviour for such binaries,
at least when there are multiple PT_LOAD headers.

	PR 2995, PR 6473
	* elf.c (_bfd_elf_make_section_from_shdr): Leave lma equal to
	vma when all p_paddr fields are zero and there is more than
	one PT_LOAD header.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.444
diff -u -p -r1.444 elf.c
--- bfd/elf.c	3 May 2008 05:18:02 -0000	1.444
+++ bfd/elf.c	19 May 2008 03:00:06 -0000
@@ -948,7 +948,20 @@ _bfd_elf_make_section_from_shdr (bfd *ab
   if ((flags & SEC_ALLOC) != 0)
     {
       Elf_Internal_Phdr *phdr;
-      unsigned int i;
+      unsigned int i, nload;
+
+      /* Some ELF linkers produce binaries with all the program header
+	 p_paddr fields zero.  If we have such a binary with more than
+	 one PT_LOAD header, then leave the section lma equal to vma
+	 so that we don't create sections with overlapping lma.  */
+      phdr = elf_tdata (abfd)->phdr;
+      for (nload = 0, i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
+	if (phdr->p_paddr != 0)
+	  break;
+	else if (phdr->p_type == PT_LOAD && phdr->p_memsz != 0)
+	  ++nload;
+      if (i >= elf_elfheader (abfd)->e_phnum && nload > 1)
+	return TRUE;
 
       phdr = elf_tdata (abfd)->phdr;
       for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)

-- 
Alan Modra
Australia Development Lab, IBM


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