public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix assign_file_positions_for_load_sections() for  STRIP_NONDEBUG
@ 2008-10-07 16:39 Jan Blunck
  2008-10-08  8:32 ` Alan Modra
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Blunck @ 2008-10-07 16:39 UTC (permalink / raw)
  To: binutils

When objcopy is called with the option --only-keep-debug it might happen that
the first section in a load segment isn't marked for loading since it is
stripped. This doesn't mean that all section in a segment are not marked for
loading.

This failed on certain binaries when some section couldn't be allocated in a
segment because of the sh_offset was larger than the end of the segment in the
binary. Typically these binaries also had some padding at the beginning of the
file (e.g. introduced through either "-Wl,-zcommon-page-size=4194304
-Wl,-zmax-page-size=4194304" or "-Wl,--section-start,.interp=0x7bf00400")
which I couldn't find a reason for.

Signed-off-by: Jan Blunck <jblunck@suse.de>
---
 bfd/elf.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Index: b/bfd/elf.c
===================================================================
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4258,18 +4258,23 @@ assign_file_positions_for_load_sections
 	      elf_section_type (m->sections[i]) = SHT_NOBITS;
 
 	  /* Find out whether this segment contains any loadable
-	     sections.  If the first section isn't loadable, the same
-	     holds for any other sections.  */
-	  i = 0;
-	  while (elf_section_type (m->sections[i]) == SHT_NOBITS)
+	     sections.
+	     We have to look at all the sections until we find a loadable one,
+	     since with STRIP_NONDEBUG the first sections might just be set to
+	     SHT_NOBITS */
+	  no_contents = TRUE;
+	  for (i = 0; i < m->count; i++)
 	    {
 	      /* 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 ((elf_section_flags (m->sections[i]) & SHF_TLS) != 0
+		  && (i + 1 < m->count))
+		continue;
+
+	      if (elf_section_type (m->sections[i]) != SHT_NOBITS)
 		{
-		  no_contents = TRUE;
+		  no_contents = FALSE;
 		  break;
 		}
 	    }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-10-08  8:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-07 16:39 [PATCH] Fix assign_file_positions_for_load_sections() for STRIP_NONDEBUG Jan Blunck
2008-10-08  8:32 ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).