public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Blunck <jblunck@suse.de>
To: binutils@sourceware.org
Subject: [PATCH] Fix assign_file_positions_for_load_sections() for 	STRIP_NONDEBUG
Date: Tue, 07 Oct 2008 16:39:00 -0000	[thread overview]
Message-ID: <20081007163844.GB19803@T61> (raw)

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;
 		}
 	    }

             reply	other threads:[~2008-10-07 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-07 16:39 Jan Blunck [this message]
2008-10-08  8:32 ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081007163844.GB19803@T61 \
    --to=jblunck@suse.de \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).