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]

PATCH: PR ld/4701: binutils generates invalid klibc-based binary on Linux x86_64


I don't think we can skip segment alignment on disk when its offset
< alignment. This patch fixes it. I will try to find a small testcase.


H.J.
---
2007-06-27  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/4701
	* elf.c (assign_file_positions_for_load_sections): Skip segment
	alignment on disk only if its offset >= alignment.

--- bfd/elf.c.bss	2007-06-26 10:15:25.000000000 -0700
+++ bfd/elf.c	2007-06-27 10:59:45.000000000 -0700
@@ -4518,21 +4518,24 @@ assign_file_positions_for_load_sections 
 	  adjust = vma_page_aligned_bias (m->sections[0]->vma, off, align);
 	  if (adjust != 0)
 	    {
-	      /* If the first section isn't loadable, the same holds
-		 for any other sections.  We don't need to align the
-		 segment on disk since the segment doesn't need file
-		 space.  */
-	      i = 0;
-	      while (elf_section_type (m->sections[i]) == SHT_NOBITS)
+	      if ((ufile_ptr) off >= align)
 		{
-		  /* If a segment starts with .tbss, we need to look
-		     at the next section to decide whether the segment
-		     has any loadable sections.  */
-		  if ((elf_section_flags (m->sections[i]) & SHF_TLS) == 0
-		      || ++i >= m->count)
+		  /* If the first section isn't loadable, the same holds
+		     for any other sections.  We don't need to align the
+		     segment on disk since the segment doesn't need file
+		     space.  */
+		  i = 0;
+		  while (elf_section_type (m->sections[i]) == SHT_NOBITS)
 		    {
-		      adjust = 0;
-		      break;
+		      /* If a segment starts with .tbss, we need to look
+			 at the next section to decide whether the segment
+			 has any loadable sections.  */
+		      if (!(elf_section_flags (m->sections[i]) & SHF_TLS)
+			  || ++i >= m->count)
+			{
+			  adjust = 0;
+			  break;
+			}
 		    }
 		}
 	      off += adjust;


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