This is the mail archive of the binutils-cvs@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]

[binutils-gdb] Set dynobj to a normal input file if possible


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6cd255ca1f03550291bd05ac4548e383bca88c5f

commit 6cd255ca1f03550291bd05ac4548e383bca88c5f
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Apr 21 19:14:10 2016 -0700

    Set dynobj to a normal input file if possible
    
    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.
    
    	* elflink.c (_bfd_elf_link_create_dynstrtab): Set dynobj to a
    	normal input file if possible.

Diff:
---
 bfd/ChangeLog |  5 +++++
 bfd/elflink.c | 18 +++++++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 9793225..d668652 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2016-04-21  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* elflink.c (_bfd_elf_link_create_dynstrtab): Set dynobj to a
+	normal input file if possible.
+
 2016-04-21  Nick Clifton  <nickc@redhat.com>
 
 	* aout-adobe.c: Use _bfd_generic_link_check_relocs.
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)
     {


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