public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sourceware.org
Subject: [PATCH] Set dynobj to a normal input file if possible
Date: Thu, 21 Apr 2016 03:32:00 -0000	[thread overview]
Message-ID: <20160421033150.GA24027@intel.com> (raw)

When check_relocs is called after gc-sections has run,
_bfd_elf_link_create_dynstrtab may be called with an dynamic object
and hash_table->dynobj may be NULL.  We may not set dynobj, an input
file holding linker created dynamic sections to the dynamic object,
which has its own dynamic sections.  We need to find a normal input
file to hold linker created sections if possible.  Otherwise ld will
crash during LTO input rescan when linker created dynamic section
overrides input dynamic section.

Tested on x86-64.  OK for master?

H.J.

	* elflink.c (_bfd_elf_link_create_dynstrtab): Set dynobj to a
	normal input file if possible.
---
 bfd/elflink.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/bfd/elflink.c b/bfd/elflink.c
index b432384..13233cb 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -204,7 +204,23 @@ _bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info)
 
   hash_table = elf_hash_table (info);
   if (hash_table->dynobj == NULL)
-    hash_table->dynobj = abfd;
+    {
+      /* We may not set dynobj, an input file holding linker created
+	 dynamic sections to abfd, which may be a dynamic object with
+	 its own dynamic sections.  We need to find a normal input file
+	 to hold linker created sections if possible.  */
+      if ((abfd->flags & (DYNAMIC | BFD_PLUGIN)) != 0)
+	{
+	  bfd *ibfd;
+	  for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
+	    if ((ibfd->flags & (DYNAMIC | BFD_PLUGIN)) == 0)
+	      {
+		abfd = ibfd;
+		break;
+	      }
+	}
+      hash_table->dynobj = abfd;
+    }
 
   if (hash_table->dynstr == NULL)
     {
-- 
2.5.5

             reply	other threads:[~2016-04-21  3:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21  3:32 H.J. Lu [this message]
2016-04-22  0:33 ` Alan Modra
2016-04-22  3:41 ` Hans-Peter Nilsson
2016-04-22  4:50   ` H.J. Lu
2016-04-22  8:55     ` Alan Modra
2016-04-22 12:35       ` H.J. Lu

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=20160421033150.GA24027@intel.com \
    --to=hongjiu.lu@intel.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /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).